From bonefish at mail.berlios.de Mon Oct 1 02:39:39 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Mon, 1 Oct 2007 02:39:39 +0200 Subject: [Haiku-commits] r22390 - haiku/trunk/src/tests/system/kernel Message-ID: <200710010039.l910ddUg013235@sheep.berlios.de> Author: bonefish Date: 2007-10-01 02:39:38 +0200 (Mon, 01 Oct 2007) New Revision: 22390 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22390&view=rev Added: haiku/trunk/src/tests/system/kernel/select_check.cpp haiku/trunk/src/tests/system/kernel/select_close_test.cpp Modified: haiku/trunk/src/tests/system/kernel/Jamfile Log: Added two small select() test programs. select_check select()s stdin/out/err according the what was specified via arguments. select_close_test select()s a file descriptor that is closed a little later by another thread. Modified: haiku/trunk/src/tests/system/kernel/Jamfile =================================================================== --- haiku/trunk/src/tests/system/kernel/Jamfile 2007-09-30 17:24:57 UTC (rev 22389) +++ haiku/trunk/src/tests/system/kernel/Jamfile 2007-10-01 00:39:38 UTC (rev 22390) @@ -29,17 +29,20 @@ SimpleTest port_wakeup_test_8 : port_wakeup_test_8.cpp ; SimpleTest port_wakeup_test_9 : port_wakeup_test_9.cpp ; +SimpleTest select_check : select_check.cpp ; +SimpleTest select_close_test : select_close_test.cpp ; + SimpleTest syscall_time : syscall_time.cpp ; SimpleTest transfer_area_test : transfer_area_test.cpp ; -SimpleTest yield_test : yield_test.cpp ; - SimpleTest wait_test_1 : wait_test_1.c ; SimpleTest wait_test_2 : wait_test_2.cpp ; SimpleTest wait_test_3 : wait_test_3.cpp ; SimpleTest wait_test_4 : wait_test_4.cpp ; +SimpleTest yield_test : yield_test.cpp ; + SetSupportedPlatformsForTarget sigint_bug113_test : $(HAIKU_BEOS_COMPATIBLE_PLATFORMS) ; SimpleTest sigint_bug113_test : sigint_bug113_test.cpp ; Added: haiku/trunk/src/tests/system/kernel/select_check.cpp =================================================================== --- haiku/trunk/src/tests/system/kernel/select_check.cpp 2007-09-30 17:24:57 UTC (rev 22389) +++ haiku/trunk/src/tests/system/kernel/select_check.cpp 2007-10-01 00:39:38 UTC (rev 22390) @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include +#include + + +int +main(int argc, const char* const* argv) +{ + const char* config[] = { + argc >= 2 ? argv[1] : "rwe", + argc >= 3 ? argv[2] : "rwe", + argc >= 4 ? argv[3] : "rwe" + }; + + fd_set readSet; + fd_set writeSet; + fd_set errorSet; + + FD_ZERO(&readSet); + FD_ZERO(&writeSet); + FD_ZERO(&errorSet); + + for (int fd = 0; fd < 3; fd++) { + if (strchr(config[fd], 'r')) + FD_SET(fd, &readSet); + if (strchr(config[fd], 'w')) + FD_SET(fd, &writeSet); + if (strchr(config[fd], 'e')) + FD_SET(fd, &errorSet); + } + + int result = select(3, &readSet, &writeSet, &errorSet, NULL); + fprintf(stderr, "select(): %d\n", result); + + for (int fd = 0; fd < 3; fd++) { + fprintf(stderr, "fd %d: %s%s%s\n", fd, + FD_ISSET(fd, &readSet) ? "r" : " ", + FD_ISSET(fd, &writeSet) ? "w" : " ", + FD_ISSET(fd, &errorSet) ? "e" : " "); + } + + return 0; +} Added: haiku/trunk/src/tests/system/kernel/select_close_test.cpp =================================================================== --- haiku/trunk/src/tests/system/kernel/select_close_test.cpp 2007-09-30 17:24:57 UTC (rev 22389) +++ haiku/trunk/src/tests/system/kernel/select_close_test.cpp 2007-10-01 00:39:38 UTC (rev 22390) @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include +#include + +#include + + +static status_t +close_fd(void* data) +{ + int fd = int(data); + snooze(1000000); + close(fd); + fprintf(stderr, "fd %d closed\n", fd); + return B_OK; +} + + +int +main() +{ + int fd = dup(0); + + thread_id thread = spawn_thread(close_fd, "close fd", B_NORMAL_PRIORITY, + (void*)fd); + resume_thread(thread); + + fd_set readSet; + FD_ZERO(&readSet); + FD_SET(0, &readSet); + FD_SET(fd, &readSet); + + fprintf(stderr, "select({0, %d}, NULL, NULL, NULL) ...\n", fd); + int result = select(fd + 1, &readSet, NULL, NULL, NULL); + fprintf(stderr, "select(): %d\n", result); + + fprintf(stderr, "fd %d: %s\n", 0, FD_ISSET(0, &readSet) ? "r" : " "); + fprintf(stderr, "fd %d: %s\n", fd, FD_ISSET(fd, &readSet) ? "r" : " "); + + return 0; +} From bonefish at mail.berlios.de Mon Oct 1 03:37:30 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Mon, 1 Oct 2007 03:37:30 +0200 Subject: [Haiku-commits] r22391 - in haiku/trunk: headers/private/kernel headers/private/kernel/fs src/system/kernel/fs Message-ID: <200710010137.l911bUIY015123@sheep.berlios.de> Author: bonefish Date: 2007-10-01 03:37:28 +0200 (Mon, 01 Oct 2007) New Revision: 22391 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22391&view=rev Added: haiku/trunk/src/system/kernel/fs/fd.cpp Removed: haiku/trunk/src/system/kernel/fs/fd.c Modified: haiku/trunk/headers/private/kernel/fs/fd.h haiku/trunk/headers/private/kernel/vfs.h haiku/trunk/src/system/kernel/fs/Jamfile haiku/trunk/src/system/kernel/fs/vfs.cpp haiku/trunk/src/system/kernel/fs/vfs_select.cpp haiku/trunk/src/system/kernel/fs/vfs_select.h Log: * fd.c -> fd.cpp * Reworked the select support: - The io_context additionally stores a table of lists of select_infos, which enables it to deselect events of a pending select() when closing a FD. This prevents a race condition potentially causing a write to stale memory. - The opaque selectsync* passed to FSs is now actually a select_info*. This was necessary, since the FDs deselect() hook (unlike the select() hook) doesn't take a "ref" argument and deselecting a single info (e.g. caused by a premature close()) was not possible. The select() hook's "ref" argument has become superfluous. - It should now be relatively easy to implement a poll_on_steroids() that can also wait for objects other than FDs (e.g. semaphores, ports, threads etc.). * Set/reset the signal mask in common_select(). This makes pselect() work as required. * Reorganized vfs_resize_fd_table(). Modified: haiku/trunk/headers/private/kernel/fs/fd.h =================================================================== --- haiku/trunk/headers/private/kernel/fs/fd.h 2007-10-01 00:39:38 UTC (rev 22390) +++ haiku/trunk/headers/private/kernel/fs/fd.h 2007-10-01 01:37:28 UTC (rev 22391) @@ -16,6 +16,7 @@ #endif struct file_descriptor; +struct selectsync; struct select_sync; struct fd_ops { @@ -23,8 +24,10 @@ status_t (*fd_write)(struct file_descriptor *, off_t pos, const void *buffer, size_t *length); off_t (*fd_seek)(struct file_descriptor *, off_t pos, int seekType); status_t (*fd_ioctl)(struct file_descriptor *, ulong op, void *buffer, size_t length); - status_t (*fd_select)(struct file_descriptor *, uint8 event, uint32 ref, struct select_sync *sync); - status_t (*fd_deselect)(struct file_descriptor *, uint8 event, struct select_sync *sync); + status_t (*fd_select)(struct file_descriptor *, uint8 event, uint32 ref, + struct selectsync *sync); + status_t (*fd_deselect)(struct file_descriptor *, uint8 event, + struct selectsync *sync); status_t (*fd_read_dir)(struct file_descriptor *, struct dirent *buffer, size_t bufferSize, uint32 *_count); status_t (*fd_rewind_dir)(struct file_descriptor *); status_t (*fd_read_stat)(struct file_descriptor *, struct stat *); @@ -74,10 +77,10 @@ extern void put_fd(struct file_descriptor *descriptor); extern void disconnect_fd(struct file_descriptor *descriptor); extern void inc_fd_ref_count(struct file_descriptor *descriptor); -extern status_t select_fd(int fd, uint8 event, uint32 ref, - struct select_sync *sync, bool kernel); -extern status_t deselect_fd(int fd, uint8 event, struct select_sync *sync, +extern status_t select_fd(int fd, struct select_sync *sync, uint32 ref, bool kernel); +extern status_t deselect_fd(int fd, struct select_sync *sync, uint32 ref, + bool kernel); extern bool fd_is_valid(int fd, bool kernel); extern struct vnode *fd_vnode(struct file_descriptor *descriptor); Modified: haiku/trunk/headers/private/kernel/vfs.h =================================================================== --- haiku/trunk/headers/private/kernel/vfs.h 2007-10-01 00:39:38 UTC (rev 22390) +++ haiku/trunk/headers/private/kernel/vfs.h 2007-10-01 01:37:28 UTC (rev 22391) @@ -30,6 +30,7 @@ struct vm_cache; struct file_descriptor; struct selectsync; +struct select_info; struct pollfd; struct vnode; @@ -41,6 +42,7 @@ uint32 table_size; uint32 num_used_fds; struct file_descriptor **fds; + struct select_info **select_infos; uint8 *fds_close_on_exec; struct list node_monitors; uint32 num_monitors; Modified: haiku/trunk/src/system/kernel/fs/Jamfile =================================================================== --- haiku/trunk/src/system/kernel/fs/Jamfile 2007-10-01 00:39:38 UTC (rev 22390) +++ haiku/trunk/src/system/kernel/fs/Jamfile 2007-10-01 01:37:28 UTC (rev 22391) @@ -9,7 +9,7 @@ devfs.cpp rootfs.c pipefs.cpp - fd.c + fd.cpp vfs.cpp vfs_boot.cpp vfs_net_boot.cpp @@ -19,4 +19,4 @@ KPath.cpp : $(TARGET_KERNEL_PIC_CCFLAGS) -Wno-unused - ; +; Deleted: haiku/trunk/src/system/kernel/fs/fd.c Copied: haiku/trunk/src/system/kernel/fs/fd.cpp (from rev 22363, haiku/trunk/src/system/kernel/fs/fd.c) =================================================================== --- haiku/trunk/src/system/kernel/fs/fd.c 2007-09-29 00:34:09 UTC (rev 22363) +++ haiku/trunk/src/system/kernel/fs/fd.cpp 2007-10-01 01:37:28 UTC (rev 22391) @@ -0,0 +1,1188 @@ +/* Operations on file descriptors + * + * Copyright 2002-2007, Axel D?rfler, axeld at pinc-software.de. + * Distributed under the terms of the MIT License. + */ + + +#include + +#include +#include + +#include + +#include +#include +#include + +#include "vfs_select.h" + + +//#define TRACE_FD +#ifdef TRACE_FD +# define TRACE(x) dprintf x +#else +# define TRACE(x) +#endif + + +static void deselect_select_infos(file_descriptor* descriptor, + select_info* infos); + + +/*** General fd routines ***/ + + +#ifdef DEBUG +void dump_fd(int fd, struct file_descriptor *descriptor); + +void +dump_fd(int fd,struct file_descriptor *descriptor) +{ + dprintf("fd[%d] = %p: type = %ld, ref_count = %ld, ops = %p, u.vnode = %p, u.mount = %p, cookie = %p, open_mode = %lx, pos = %Ld\n", + fd, descriptor, descriptor->type, descriptor->ref_count, descriptor->ops, + descriptor->u.vnode, descriptor->u.mount, descriptor->cookie, descriptor->open_mode, descriptor->pos); +} +#endif + + +/** Allocates and initializes a new file_descriptor */ + +struct file_descriptor * +alloc_fd(void) +{ + file_descriptor *descriptor + = (file_descriptor*)malloc(sizeof(struct file_descriptor)); + if (descriptor == NULL) + return NULL; + + descriptor->u.vnode = NULL; + descriptor->cookie = NULL; + descriptor->ref_count = 1; + descriptor->open_count = 0; + descriptor->open_mode = 0; + descriptor->pos = 0; + + return descriptor; +} + + +bool +fd_close_on_exec(struct io_context *context, int fd) +{ + return CHECK_BIT(context->fds_close_on_exec[fd / 8], fd & 7) ? true : false; +} + + +void +fd_set_close_on_exec(struct io_context *context, int fd, bool closeFD) +{ + if (closeFD) + context->fds_close_on_exec[fd / 8] |= (1 << (fd & 7)); + else + context->fds_close_on_exec[fd / 8] &= ~(1 << (fd & 7)); +} + + +/** Searches a free slot in the FD table of the provided I/O context, and inserts + * the specified descriptor into it. + */ + +int +new_fd_etc(struct io_context *context, struct file_descriptor *descriptor, int firstIndex) +{ + int fd = -1; + uint32 i; + + mutex_lock(&context->io_mutex); + + for (i = firstIndex; i < context->table_size; i++) { + if (!context->fds[i]) { + fd = i; + break; + } + } + if (fd < 0) { + fd = B_NO_MORE_FDS; + goto err; + } + + context->fds[fd] = descriptor; + context->num_used_fds++; + atomic_add(&descriptor->open_count, 1); + +err: + mutex_unlock(&context->io_mutex); + + return fd; +} + + +int +new_fd(struct io_context *context, struct file_descriptor *descriptor) +{ + return new_fd_etc(context, descriptor, 0); +} + + +/** Reduces the descriptor's reference counter, and frees all resources + * when it's no longer used. + */ + +void +put_fd(struct file_descriptor *descriptor) +{ + int32 previous = atomic_add(&descriptor->ref_count, -1); + + TRACE(("put_fd(descriptor = %p [ref = %ld, cookie = %p])\n", + descriptor, descriptor->ref_count, descriptor->cookie)); + + // free the descriptor if we don't need it anymore + if (previous == 1) { + // free the underlying object + if (descriptor->ops != NULL && descriptor->ops->fd_free != NULL) + descriptor->ops->fd_free(descriptor); + + free(descriptor); + } else if ((descriptor->open_mode & O_DISCONNECTED) != 0 + && previous - 1 == descriptor->open_count + && descriptor->ops != NULL) { + // the descriptor has been disconnected - it cannot + // be accessed anymore, let's close it (no one is + // currently accessing this descriptor) + + if (descriptor->ops->fd_close) + descriptor->ops->fd_close(descriptor); + if (descriptor->ops->fd_free) + descriptor->ops->fd_free(descriptor); + + // prevent this descriptor from being closed/freed again + descriptor->open_count = -1; + descriptor->ref_count = -1; + descriptor->ops = NULL; + descriptor->u.vnode = NULL; + + // the file descriptor is kept intact, so that it's not + // reused until someone explicetly closes it + } +} + + +/** Decrements the open counter of the file descriptor and invokes + * its close hook when appropriate. + */ + +void +close_fd(struct file_descriptor *descriptor) +{ + if (atomic_add(&descriptor->open_count, -1) == 1) { + vfs_unlock_vnode_if_locked(descriptor); + + if (descriptor->ops != NULL && descriptor->ops->fd_close != NULL) + descriptor->ops->fd_close(descriptor); + } +} + + +/** This descriptor's underlying object will be closed and freed + * as soon as possible (in one of the next calls to put_fd() - + * get_fd() will no longer succeed on this descriptor). + * This is useful if the underlying object is gone, for instance + * when a (mounted) volume got removed unexpectedly. + */ + +void +disconnect_fd(struct file_descriptor *descriptor) +{ + descriptor->open_mode |= O_DISCONNECTED; +} + + +void +inc_fd_ref_count(struct file_descriptor *descriptor) +{ + atomic_add(&descriptor->ref_count, 1); +} + + +static struct file_descriptor * +get_fd_locked(struct io_context *context, int fd) +{ + if (fd < 0 || (uint32)fd >= context->table_size) + return NULL; + + struct file_descriptor *descriptor = context->fds[fd]; + + if (descriptor != NULL) { + // Disconnected descriptors cannot be accessed anymore + if (descriptor->open_mode & O_DISCONNECTED) + descriptor = NULL; + else + inc_fd_ref_count(descriptor); + } + + return descriptor; +} + + +struct file_descriptor * +get_fd(struct io_context *context, int fd) +{ + MutexLocker(context->io_mutex); + + return get_fd_locked(context, fd); +} + + +/** Removes the file descriptor from the specified slot. + */ + +static struct file_descriptor * +remove_fd(struct io_context *context, int fd) +{ + struct file_descriptor *descriptor = NULL; + + if (fd < 0) + return NULL; + + mutex_lock(&context->io_mutex); + + if ((uint32)fd < context->table_size) + descriptor = context->fds[fd]; + + select_info* selectInfos = NULL; + bool disconnected = false; + + if (descriptor) { + // fd is valid + context->fds[fd] = NULL; + fd_set_close_on_exec(context, fd, false); + context->num_used_fds--; + + selectInfos = context->select_infos[fd]; + context->select_infos[fd] = NULL; + + disconnected = (descriptor->open_mode & O_DISCONNECTED); + } + + mutex_unlock(&context->io_mutex); + + if (selectInfos != NULL) + deselect_select_infos(descriptor, selectInfos); + + return disconnected ? NULL : descriptor; +} + + +static int +dup_fd(int fd, bool kernel) +{ + struct io_context *context = get_current_io_context(kernel); + struct file_descriptor *descriptor; + int status; + + TRACE(("dup_fd: fd = %d\n", fd)); + + // Try to get the fd structure + descriptor = get_fd(context, fd); + if (descriptor == NULL) + return B_FILE_ERROR; + + // now put the fd in place + status = new_fd(context, descriptor); + if (status < 0) + put_fd(descriptor); + else { + mutex_lock(&context->io_mutex); + fd_set_close_on_exec(context, status, false); + mutex_unlock(&context->io_mutex); + } + + return status; +} + + +/** POSIX says this should be the same as: + * close(newfd); + * fcntl(oldfd, F_DUPFD, newfd); + * + * We do dup2() directly to be thread-safe. + */ +static int +dup2_fd(int oldfd, int newfd, bool kernel) +{ + struct file_descriptor *evicted = NULL; + struct io_context *context; + + TRACE(("dup2_fd: ofd = %d, nfd = %d\n", oldfd, newfd)); + + // quick check + if (oldfd < 0 || newfd < 0) + return B_FILE_ERROR; + + // Get current I/O context and lock it + context = get_current_io_context(kernel); + mutex_lock(&context->io_mutex); + + // Check if the fds are valid (mutex must be locked because + // the table size could be changed) + if ((uint32)oldfd >= context->table_size + || (uint32)newfd >= context->table_size + || context->fds[oldfd] == NULL) { + mutex_unlock(&context->io_mutex); + return B_FILE_ERROR; + } + + // Check for identity, note that it cannot be made above + // because we always want to return an error on invalid + // handles + select_info* selectInfos = NULL; + if (oldfd != newfd) { + // Now do the work + evicted = context->fds[newfd]; + selectInfos = context->select_infos[newfd]; + context->select_infos[newfd] = NULL; + atomic_add(&context->fds[oldfd]->ref_count, 1); + atomic_add(&context->fds[oldfd]->open_count, 1); + context->fds[newfd] = context->fds[oldfd]; + + if (evicted == NULL) + context->num_used_fds++; + } + + fd_set_close_on_exec(context, newfd, false); + + mutex_unlock(&context->io_mutex); + + // Say bye bye to the evicted fd + if (evicted) { + deselect_select_infos(evicted, selectInfos); + close_fd(evicted); + put_fd(evicted); + } + + return newfd; +} + + +static status_t +fd_ioctl(bool kernelFD, int fd, ulong op, void *buffer, size_t length) +{ + struct file_descriptor *descriptor; + int status; + + descriptor = get_fd(get_current_io_context(kernelFD), fd); + if (descriptor == NULL) + return B_FILE_ERROR; + + if (descriptor->ops->fd_ioctl) + status = descriptor->ops->fd_ioctl(descriptor, op, buffer, length); + else + status = EOPNOTSUPP; + + put_fd(descriptor); + return status; +} + + +static void +deselect_select_infos(file_descriptor* descriptor, select_info* infos) +{ + TRACE(("deselect_select_infos(%p, %p)\n", descriptor, infos)); + + select_info* info = infos; + while (info != NULL) { + select_sync* sync = info->sync; + + // deselect the selected events + if (descriptor->ops->fd_deselect && info->selected_events) { + for (uint16 event = 1; event < 16; event++) { + if (info->selected_events & SELECT_FLAG(event)) { + descriptor->ops->fd_deselect(descriptor, event, + (selectsync*)info); + } + } + } + + info = info->next; + put_select_sync(sync); + } +} + + +status_t +select_fd(int fd, struct select_sync* sync, uint32 ref, bool kernel) +{ + TRACE(("select_fd(fd = %d, selectsync = %p, ref = %lu, 0x%x)\n", fd, sync, ref, sync->set[ref].selected_events)); + + select_info* info = &sync->set[ref]; + if (info->selected_events == 0) + return B_OK; + + io_context* context = get_current_io_context(kernel); + MutexLocker locker(context->io_mutex); + + struct file_descriptor* descriptor = get_fd_locked(context, fd); + if (descriptor == NULL) + return B_FILE_ERROR; + + if (!descriptor->ops->fd_select) { + // if the I/O subsystem doesn't support select(), we will + // immediately notify the select call + locker.Unlock(); + put_fd(descriptor); + return notify_select_events(info, info->selected_events); + } + + // add the info to the IO context + info->next = context->select_infos[fd]; + context->select_infos[fd] = info; + + // as long as the info is in the list, we keep a reference to the sync + // object + atomic_add(&sync->ref_count, 1); + + locker.Unlock(); + + // select any events asked for + uint32 selectedEvents = 0; + + for (uint16 event = 1; event < 16; event++) { + if (info->selected_events & SELECT_FLAG(event) + && descriptor->ops->fd_select(descriptor, event, ref, + (selectsync*)info) == B_OK) { + selectedEvents |= SELECT_FLAG(event); + } + } + info->selected_events = selectedEvents; + + // if nothing has been selected, we deselect immediately + if (selectedEvents == 0) + deselect_fd(fd, sync, ref, kernel); + + put_fd(descriptor); + return B_OK; +} + + +status_t +deselect_fd(int fd, struct select_sync* sync, uint32 ref, bool kernel) +{ + TRACE(("deselect_fd(fd = %d, selectsync = %p, ref = %lu)\n", fd, sync, ref)); + + select_info* info = &sync->set[ref]; + if (info->selected_events == 0) + return B_OK; + + io_context* context = get_current_io_context(kernel); + MutexLocker locker(context->io_mutex); + + struct file_descriptor* descriptor = get_fd_locked(context, fd); + if (descriptor == NULL) + return B_FILE_ERROR; + + // remove the info from the IO context + + select_info** infoLocation = &context->select_infos[fd]; + while (*infoLocation != NULL && *infoLocation != info) + infoLocation = &(*infoLocation)->next; + + // If not found, someone else beat us to it. + if (*infoLocation != info) { + locker.Unlock(); + put_fd(descriptor); + return B_OK; + } + + *infoLocation = info->next; + + locker.Unlock(); + + // deselect the selected events + if (descriptor->ops->fd_deselect && info->selected_events) { + for (uint16 event = 1; event < 16; event++) { + if (info->selected_events & SELECT_FLAG(event)) { + descriptor->ops->fd_deselect(descriptor, event, + (selectsync*)info); + } + } + } + + put_select_sync(sync); + + put_fd(descriptor); + return B_OK; +} + + +/** This function checks if the specified fd is valid in the current + * context. It can be used for a quick check; the fd is not locked + * so it could become invalid immediately after this check. + */ + +bool +fd_is_valid(int fd, bool kernel) +{ + struct file_descriptor *descriptor = get_fd(get_current_io_context(kernel), fd); + if (descriptor == NULL) + return false; + + put_fd(descriptor); + return true; +} + + +struct vnode * +fd_vnode(struct file_descriptor *descriptor) +{ + switch (descriptor->type) { + case FDTYPE_FILE: + case FDTYPE_DIR: + case FDTYPE_ATTR_DIR: + case FDTYPE_ATTR: + return descriptor->u.vnode; + } + + return NULL; +} + + +static status_t +common_close(int fd, bool kernel) +{ + struct io_context *io = get_current_io_context(kernel); + struct file_descriptor *descriptor = remove_fd(io, fd); + + if (descriptor == NULL) + return B_FILE_ERROR; + +#ifdef TRACE_FD + if (!kernel) + TRACE(("_user_close(descriptor = %p)\n", descriptor)); +#endif + + close_fd(descriptor); + put_fd(descriptor); + // the reference associated with the slot + + return B_OK; +} + + +// #pragma mark - +// User syscalls + + +ssize_t +_user_read(int fd, off_t pos, void *buffer, size_t length) +{ + struct file_descriptor *descriptor; + ssize_t bytesRead; + + /* This is a user_function, so abort if we have a kernel address */ + if (!IS_USER_ADDRESS(buffer)) + return B_BAD_ADDRESS; + + if (pos < -1) + return B_BAD_VALUE; + + descriptor = get_fd(get_current_io_context(false), fd); + if (!descriptor) + return B_FILE_ERROR; + if ((descriptor->open_mode & O_RWMASK) == O_WRONLY) { + put_fd(descriptor); + return B_FILE_ERROR; + } + + if (pos == -1) + pos = descriptor->pos; + + if (descriptor->ops->fd_read) { + bytesRead = descriptor->ops->fd_read(descriptor, pos, buffer, &length); + if (bytesRead >= B_OK) { + if (length > SSIZE_MAX) + bytesRead = SSIZE_MAX; + else + bytesRead = (ssize_t)length; + + descriptor->pos = pos + length; + } + } else + bytesRead = B_BAD_VALUE; + + put_fd(descriptor); + return bytesRead; +} + + +ssize_t +_user_readv(int fd, off_t pos, const iovec *userVecs, size_t count) +{ + struct file_descriptor *descriptor; + ssize_t bytesRead = 0; + status_t status; + iovec *vecs; + uint32 i; + + /* This is a user_function, so abort if we have a kernel address */ + if (!IS_USER_ADDRESS(userVecs)) + return B_BAD_ADDRESS; + + if (pos < -1) + return B_BAD_VALUE; + + /* prevent integer overflow exploit in malloc() */ + if (count > IOV_MAX) + return B_BAD_VALUE; + + descriptor = get_fd(get_current_io_context(false), fd); + if (!descriptor) + return B_FILE_ERROR; + if ((descriptor->open_mode & O_RWMASK) == O_WRONLY) { + status = B_FILE_ERROR; + goto err1; + } + + vecs = (iovec*)malloc(sizeof(iovec) * count); + if (vecs == NULL) { + status = B_NO_MEMORY; + goto err1; + } + + if (user_memcpy(vecs, userVecs, sizeof(iovec) * count) < B_OK) { + status = B_BAD_ADDRESS; + goto err2; + } + + if (pos == -1) + pos = descriptor->pos; + + if (descriptor->ops->fd_read) { + for (i = 0; i < count; i++) { + size_t length = vecs[i].iov_len; + status = descriptor->ops->fd_read(descriptor, pos, vecs[i].iov_base, &length); + if (status < B_OK) { + bytesRead = status; + break; + } + + if ((uint64)bytesRead + length > SSIZE_MAX) + bytesRead = SSIZE_MAX; + else + bytesRead += (ssize_t)length; + + pos += vecs[i].iov_len; + } + } else + bytesRead = B_BAD_VALUE; + + status = bytesRead; + descriptor->pos = pos; + +err2: + free(vecs); +err1: + put_fd(descriptor); + return status; +} + + +ssize_t +_user_write(int fd, off_t pos, const void *buffer, size_t length) +{ + struct file_descriptor *descriptor; + ssize_t bytesWritten = 0; + + if (IS_KERNEL_ADDRESS(buffer)) + return B_BAD_ADDRESS; + + if (pos < -1) + return B_BAD_VALUE; + + descriptor = get_fd(get_current_io_context(false), fd); + if (!descriptor) + return B_FILE_ERROR; + if ((descriptor->open_mode & O_RWMASK) == O_RDONLY) { + put_fd(descriptor); + return B_FILE_ERROR; + } + + if (pos == -1) + pos = descriptor->pos; + + if (descriptor->ops->fd_write) { + bytesWritten = descriptor->ops->fd_write(descriptor, pos, buffer, &length); + if (bytesWritten >= B_OK) { + if (length > SSIZE_MAX) + bytesWritten = SSIZE_MAX; + else + bytesWritten = (ssize_t)length; + + descriptor->pos = pos + length; + } + } else + bytesWritten = B_BAD_VALUE; + + put_fd(descriptor); + return bytesWritten; +} + + +ssize_t +_user_writev(int fd, off_t pos, const iovec *userVecs, size_t count) +{ + struct file_descriptor *descriptor; + ssize_t bytesWritten = 0; + status_t status; + iovec *vecs; + uint32 i; + + /* This is a user_function, so abort if we have a kernel address */ + if (!IS_USER_ADDRESS(userVecs)) + return B_BAD_ADDRESS; + + if (pos < -1) + return B_BAD_VALUE; + + /* prevent integer overflow exploit in malloc() */ + if (count > IOV_MAX) + return B_BAD_VALUE; + + descriptor = get_fd(get_current_io_context(false), fd); + if (!descriptor) + return B_FILE_ERROR; + if ((descriptor->open_mode & O_RWMASK) == O_RDONLY) { + status = B_FILE_ERROR; + goto err1; + } + + vecs = (iovec*)malloc(sizeof(iovec) * count); + if (vecs == NULL) { + status = B_NO_MEMORY; + goto err1; + } + + if (user_memcpy(vecs, userVecs, sizeof(iovec) * count) < B_OK) { + status = B_BAD_ADDRESS; + goto err2; + } + + if (pos == -1) + pos = descriptor->pos; + + if (descriptor->ops->fd_write) { + for (i = 0; i < count; i++) { + size_t length = vecs[i].iov_len; + status = descriptor->ops->fd_write(descriptor, pos, vecs[i].iov_base, &length); + if (status < B_OK) { + bytesWritten = status; + break; + } + + if ((uint64)bytesWritten + length > SSIZE_MAX) + bytesWritten = SSIZE_MAX; + else + bytesWritten += (ssize_t)length; + + pos += vecs[i].iov_len; + } + } else + bytesWritten = B_BAD_VALUE; + + status = bytesWritten; + descriptor->pos = pos; + +err2: + free(vecs); +err1: + put_fd(descriptor); + return status; +} + + +off_t +_user_seek(int fd, off_t pos, int seekType) +{ + struct file_descriptor *descriptor; + + descriptor = get_fd(get_current_io_context(false), fd); + if (!descriptor) + return B_FILE_ERROR; + + TRACE(("user_seek(descriptor = %p)\n", descriptor)); + + if (descriptor->ops->fd_seek) + pos = descriptor->ops->fd_seek(descriptor, pos, seekType); + else + pos = ESPIPE; + + put_fd(descriptor); + return pos; +} + + +status_t +_user_ioctl(int fd, ulong op, void *buffer, size_t length) +{ + struct file_descriptor *descriptor; + int status; + + if (IS_KERNEL_ADDRESS(buffer)) + return B_BAD_ADDRESS; + + TRACE(("user_ioctl: fd %d\n", fd)); + + return fd_ioctl(false, fd, op, buffer, length); +} + + +ssize_t +_user_read_dir(int fd, struct dirent *buffer, size_t bufferSize, uint32 maxCount) +{ + struct file_descriptor *descriptor; + ssize_t retval; + + if (IS_KERNEL_ADDRESS(buffer)) + return B_BAD_ADDRESS; + + TRACE(("user_read_dir(fd = %d, buffer = %p, bufferSize = %ld, count = %lu)\n", fd, buffer, bufferSize, maxCount)); + + descriptor = get_fd(get_current_io_context(false), fd); + if (descriptor == NULL) + return B_FILE_ERROR; + + if (descriptor->ops->fd_read_dir) { + uint32 count = maxCount; + retval = descriptor->ops->fd_read_dir(descriptor, buffer, bufferSize, &count); + if (retval >= 0) + retval = count; + } else + retval = EOPNOTSUPP; + + put_fd(descriptor); + return retval; +} + + +status_t +_user_rewind_dir(int fd) +{ + struct file_descriptor *descriptor; + status_t status; + + TRACE(("user_rewind_dir(fd = %d)\n", fd)); + + descriptor = get_fd(get_current_io_context(false), fd); + if (descriptor == NULL) + return B_FILE_ERROR; + + if (descriptor->ops->fd_rewind_dir) + status = descriptor->ops->fd_rewind_dir(descriptor); + else + status = EOPNOTSUPP; + + put_fd(descriptor); + return status; +} + + +status_t +_user_close(int fd) +{ + return common_close(fd, false); +} + + +int +_user_dup(int fd) +{ + return dup_fd(fd, false); +} + + +int +_user_dup2(int ofd, int nfd) +{ + return dup2_fd(ofd, nfd, false); +} + + +// #pragma mark - +// Kernel calls [... truncated: 955 lines follow ...] From bonefish at mail.berlios.de Mon Oct 1 03:41:46 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Mon, 1 Oct 2007 03:41:46 +0200 Subject: [Haiku-commits] r22392 - haiku/trunk/src/add-ons/kernel/drivers/tty Message-ID: <200710010141.l911fkfw015337@sheep.berlios.de> Author: bonefish Date: 2007-10-01 03:41:46 +0200 (Mon, 01 Oct 2007) New Revision: 22392 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22392&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/tty/tty.cpp haiku/trunk/src/add-ons/kernel/drivers/tty/tty_private.h Log: Moved the select_sync_pool from tty_cookie to tty. No need to have one per cookie. Modified: haiku/trunk/src/add-ons/kernel/drivers/tty/tty.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/tty/tty.cpp 2007-10-01 01:37:28 UTC (rev 22391) +++ haiku/trunk/src/add-ons/kernel/drivers/tty/tty.cpp 2007-10-01 01:41:46 UTC (rev 22392) @@ -783,6 +783,7 @@ tty->index = index; tty->lock = NULL; tty->settings = &gTTYSettings[index]; + tty->select_pool = NULL; tty->is_master = isMaster; tty->pending_eof = 0; } @@ -916,7 +917,6 @@ cookie->tty = tty; cookie->other_tty = otherTTY; cookie->open_mode = openMode; - cookie->select_pool = NULL; cookie->thread_count = 0; cookie->closed = false; @@ -1051,16 +1051,6 @@ tty_close(cookie->tty); } - // notify all pending selects and clean up the pool - if (cookie->select_pool) { - notify_select_event_pool(cookie->select_pool, B_SELECT_READ); - notify_select_event_pool(cookie->select_pool, B_SELECT_WRITE); - notify_select_event_pool(cookie->select_pool, B_SELECT_ERROR); - - delete_select_sync_pool(cookie->select_pool); - cookie->select_pool = NULL; - } - // notify a select write event on the other tty, if we've closed this tty if (cookie->tty->open_count == 0 && cookie->other_tty->open_count > 0) tty_notify_select_event(cookie->other_tty, B_SELECT_WRITE); @@ -1072,13 +1062,8 @@ { TRACE(("tty_notify_select_event(%p, %u)\n", tty, event)); - for (TTYCookieList::Iterator it = tty->cookies.GetIterator(); - it.HasNext();) { - tty_cookie *cookie = it.Next(); - - if (cookie->select_pool) - notify_select_event_pool(cookie->select_pool, event); - } + if (tty->select_pool) + notify_select_event_pool(tty->select_pool, event); } @@ -1705,7 +1690,7 @@ otherTTY = NULL; // add the event to the TTY's pool - status_t error = add_select_sync_pool_entry(&cookie->select_pool, sync, ref, + status_t error = add_select_sync_pool_entry(&tty->select_pool, sync, ref, event); if (error != B_OK) { TRACE(("tty_select() done: add_select_sync_pool_entry() failed: %lx\n", @@ -1784,6 +1769,6 @@ // lock the TTY (guards the select sync pool, among other things) MutexLocker ttyLocker(tty->lock); - return remove_select_sync_pool_entry(&cookie->select_pool, sync, event); + return remove_select_sync_pool_entry(&tty->select_pool, sync, event); } Modified: haiku/trunk/src/add-ons/kernel/drivers/tty/tty_private.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/tty/tty_private.h 2007-10-01 01:37:28 UTC (rev 22391) +++ haiku/trunk/src/add-ons/kernel/drivers/tty/tty_private.h 2007-10-01 01:41:46 UTC (rev 22392) @@ -110,7 +110,6 @@ struct tty *tty; struct tty *other_tty; uint32 open_mode; - select_sync_pool *select_pool; int32 thread_count; sem_id blocking_semaphore; bool closed; @@ -130,6 +129,7 @@ int32 index; struct mutex* lock; tty_settings* settings; + select_sync_pool* select_pool; RequestQueue reader_queue; RequestQueue writer_queue; TTYCookieList cookies; From axeld at mail.berlios.de Mon Oct 1 12:21:13 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 1 Oct 2007 12:21:13 +0200 Subject: [Haiku-commits] r22393 - haiku/trunk/src/apps/sudoku Message-ID: <200710011021.l91ALDrI032508@sheep.berlios.de> Author: axeld Date: 2007-10-01 12:21:12 +0200 (Mon, 01 Oct 2007) New Revision: 22393 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22393&view=rev Modified: haiku/trunk/src/apps/sudoku/ProgressWindow.cpp haiku/trunk/src/apps/sudoku/ProgressWindow.h haiku/trunk/src/apps/sudoku/SudokuWindow.cpp Log: * The ProgressWindow now starts centered over the reference window on every open. Modified: haiku/trunk/src/apps/sudoku/ProgressWindow.cpp =================================================================== --- haiku/trunk/src/apps/sudoku/ProgressWindow.cpp 2007-10-01 01:41:46 UTC (rev 22392) +++ haiku/trunk/src/apps/sudoku/ProgressWindow.cpp 2007-10-01 10:21:12 UTC (rev 22393) @@ -51,15 +51,7 @@ } ResizeTo(Bounds().Width(), height + 8); - BRect frame; - if (referenceWindow != NULL) - frame = referenceWindow->Frame(); - else - frame = BScreen().Frame(); - - MoveTo(frame.left + (frame.Width() - Bounds().Width()) / 2, - frame.top + (frame.Height() - Bounds().Height()) / 2); - + _Center(referenceWindow); Run(); } @@ -71,9 +63,23 @@ void -ProgressWindow::Start() +ProgressWindow::_Center(BWindow* referenceWindow) { + BRect frame; + if (referenceWindow != NULL) + frame = referenceWindow->Frame(); + else + frame = BScreen().Frame(); + + MoveTo(frame.left + (frame.Width() - Bounds().Width()) / 2, + frame.top + (frame.Height() - Bounds().Height()) / 2); +} + +void +ProgressWindow::Start(BWindow* referenceWindow) +{ BAutolock _(this); + _Center(referenceWindow); fRetrievedUpdate = false; fRetrievedShow = false; Modified: haiku/trunk/src/apps/sudoku/ProgressWindow.h =================================================================== --- haiku/trunk/src/apps/sudoku/ProgressWindow.h 2007-10-01 01:41:46 UTC (rev 22392) +++ haiku/trunk/src/apps/sudoku/ProgressWindow.h 2007-10-01 10:21:12 UTC (rev 22393) @@ -19,10 +19,12 @@ virtual void MessageReceived(BMessage *message); - void Start(); + void Start(BWindow* referenceWindow); void Stop(); private: + void _Center(BWindow* referenceWindow); + BStatusBar* fStatusBar; BMessageRunner* fRunner; bool fRetrievedUpdate; Modified: haiku/trunk/src/apps/sudoku/SudokuWindow.cpp =================================================================== --- haiku/trunk/src/apps/sudoku/SudokuWindow.cpp 2007-10-01 01:41:46 UTC (rev 22392) +++ haiku/trunk/src/apps/sudoku/SudokuWindow.cpp 2007-10-01 10:21:12 UTC (rev 22393) @@ -343,7 +343,7 @@ delete fGenerator; fSudokuView->SetEditable(false); - fProgressWindow->Start(); + fProgressWindow->Start(this); fGenerator = new GenerateSudoku(*fSudokuView->Field(), level, fProgressWindow, this); } From marcusoverhagen at mail.berlios.de Mon Oct 1 12:28:24 2007 From: marcusoverhagen at mail.berlios.de (marcusoverhagen at BerliOS) Date: Mon, 1 Oct 2007 12:28:24 +0200 Subject: [Haiku-commits] r22394 - haiku/trunk/src/add-ons/kernel/busses/scsi/ahci Message-ID: <200710011028.l91ASOVj000409@sheep.berlios.de> Author: marcusoverhagen Date: 2007-10-01 12:28:24 +0200 (Mon, 01 Oct 2007) New Revision: 22394 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22394&view=rev Modified: haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp Log: disable some debug output Modified: haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp 2007-10-01 10:21:12 UTC (rev 22393) +++ haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp 2007-10-01 10:28:24 UTC (rev 22394) @@ -17,6 +17,8 @@ #define TRACE(a...) dprintf("\33[34mahci:\33[0m " a) // #define FLOW(a...) dprintf("ahci: " a) #define FLOW(a...) +//#define RWTRACE(a...) dprintf("\33[34mahci:\33[0m " a) +#define RWTRACE(a...) AHCIPort::AHCIPort(AHCIController *controller, int index) @@ -273,7 +275,7 @@ uint32 ci = fRegs->ci; fRegs->is = is; // clear interrupts - FLOW("AHCIPort::Interrupt port %d, fCommandsActive 0x%08lx, is 0x%08lx, ci 0x%08lx\n", fIndex, fCommandsActive, is, ci); + RWTRACE("AHCIPort::Interrupt port %d, fCommandsActive 0x%08lx, is 0x%08lx, ci 0x%08lx\n", fIndex, fCommandsActive, is, ci); if (is & PORT_INT_ERROR) TRACE("AHCIPort::Interrupt port %d, fCommandsActive 0x%08lx, is 0x%08lx, ci 0x%08lx\n", fIndex, fCommandsActive, is, ci); @@ -574,7 +576,7 @@ { uint32 bytecount = length * 512; - TRACE("ScsiReadWrite: position %llu, size %lu, isWrite %d\n", position * 512, bytecount, isWrite); + RWTRACE("ScsiReadWrite: position %llu, size %lu, isWrite %d\n", position * 512, bytecount, isWrite); #if 0 if (isWrite) { From axeld at mail.berlios.de Mon Oct 1 17:43:46 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 1 Oct 2007 17:43:46 +0200 Subject: [Haiku-commits] r22395 - haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/dev/fxp Message-ID: <200710011543.l91FhkTZ012638@sheep.berlios.de> Author: axeld Date: 2007-10-01 17:43:45 +0200 (Mon, 01 Oct 2007) New Revision: 22395 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22395&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/dev/fxp/glue.c Log: Minor build fix - it still doesn't link, though. Modified: haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/dev/fxp/glue.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/dev/fxp/glue.c 2007-10-01 10:28:24 UTC (rev 22394) +++ haiku/trunk/src/add-ons/kernel/drivers/network/ipro100/dev/fxp/glue.c 2007-10-01 15:43:45 UTC (rev 22395) @@ -1,3 +1,3 @@ #include -HAIKU_FBSD_DRIVER_GLUE(fxp, pci) +HAIKU_FBSD_DRIVER_GLUE(ipro100, fxp, pci) From axeld at mail.berlios.de Mon Oct 1 17:52:29 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 1 Oct 2007 17:52:29 +0200 Subject: [Haiku-commits] r22396 - haiku/trunk/build/jam Message-ID: <200710011552.l91FqT41013153@sheep.berlios.de> Author: axeld Date: 2007-10-01 17:52:28 +0200 (Mon, 01 Oct 2007) New Revision: 22396 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22396&view=rev Modified: haiku/trunk/build/jam/NetBootArchive Log: Build fix; I renamed the "dos" file system to "fat". Modified: haiku/trunk/build/jam/NetBootArchive =================================================================== --- haiku/trunk/build/jam/NetBootArchive 2007-10-01 15:43:45 UTC (rev 22395) +++ haiku/trunk/build/jam/NetBootArchive 2007-10-01 15:52:28 UTC (rev 22396) @@ -26,7 +26,7 @@ BEOS_ADD_ONS_BUS_MANAGERS = pci $(X86_ONLY)isa ide scsi config_manager $(X86_ONLY)agp ; -BEOS_ADD_ONS_FILE_SYSTEMS = bfs cdda dos googlefs iso9660 nfs ; +BEOS_ADD_ONS_FILE_SYSTEMS = bfs cdda fat googlefs iso9660 nfs ; # modules From bonefish at mail.berlios.de Mon Oct 1 19:27:15 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Mon, 1 Oct 2007 19:27:15 +0200 Subject: [Haiku-commits] r22397 - in haiku/trunk/build: jam scripts Message-ID: <200710011727.l91HRF7H004142@sheep.berlios.de> Author: bonefish Date: 2007-10-01 19:27:13 +0200 (Mon, 01 Oct 2007) New Revision: 22397 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22397&view=rev Modified: haiku/trunk/build/jam/HaikuImage haiku/trunk/build/jam/UserBuildConfig.sample haiku/trunk/build/scripts/build_haiku_image Log: Added build variable HAIKU_DONT_CLEAR_IMAGE. When set and the image does already exist, it won't be zeroed out. The image will still be initialized with BFS, though. Handy for installing Haiku on a partition. Modified: haiku/trunk/build/jam/HaikuImage =================================================================== --- haiku/trunk/build/jam/HaikuImage 2007-10-01 15:52:28 UTC (rev 22396) +++ haiku/trunk/build/jam/HaikuImage 2007-10-01 17:27:13 UTC (rev 22397) @@ -467,6 +467,7 @@ AddVariableToScript $(script) : imageSize : $(HAIKU_IMAGE_SIZE) ; AddVariableToScript $(script) : addBuildCompatibilityLibDir : $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) ; +AddVariableToScript $(script) : dontClearImage : $(HAIKU_DONT_CLEAR_IMAGE) ; AddVariableToScript $(script) : updateOnly : [ IsUpdateHaikuImageOnly ] ; AddTargetVariableToScript $(script) : bfs_shell : bfsShell ; AddTargetVariableToScript $(script) : fs_shell_command : fsShellCommand ; Modified: haiku/trunk/build/jam/UserBuildConfig.sample =================================================================== --- haiku/trunk/build/jam/UserBuildConfig.sample 2007-10-01 15:52:28 UTC (rev 22396) +++ haiku/trunk/build/jam/UserBuildConfig.sample 2007-10-01 17:27:13 UTC (rev 22397) @@ -35,6 +35,11 @@ # Install Haiku in directory /Haiku. HAIKU_INSTALL_DIR = /Haiku ; +# If the image does already exist it won't be zeroed out. It will nevertheless +# freshly be initialized with BFS. Useful when installing Haiku on a partition. +HAIKU_DONT_CLEAR_IMAGE = 1 ; + + # Affects the haiku-image, haiku-vmware-image, and install-haiku targets. Only # targets on which the HAIKU_INCLUDE_IN_IMAGE variable has been set will be # updated in the image file/installation directory. Modified: haiku/trunk/build/scripts/build_haiku_image =================================================================== --- haiku/trunk/build/scripts/build_haiku_image 2007-10-01 15:52:28 UTC (rev 22396) +++ haiku/trunk/build/scripts/build_haiku_image 2007-10-01 17:27:13 UTC (rev 22397) @@ -11,6 +11,7 @@ # addBuildCompatibilityLibDir # sourceDirsToCopy # updateOnly +# dontClearImage # # bfsShell # copyattr @@ -83,7 +84,9 @@ echo if [ ! $updateOnly ]; then echo "Creating image ..." - dd if=/dev/zero of=$imagePath bs=1048576 count=$imageSize + if [ ! -f $imagePath -o ! "$dontClearImage" ]; then + dd if=/dev/zero of=$imagePath bs=1048576 count=$imageSize + fi $bfsShell --initialize $imagePath Haiku $makebootable $imagePath fi From bonefish at mail.berlios.de Mon Oct 1 19:36:52 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Mon, 1 Oct 2007 19:36:52 +0200 Subject: [Haiku-commits] r22398 - haiku/trunk/build/scripts Message-ID: <200710011736.l91HaqLw005035@sheep.berlios.de> Author: bonefish Date: 2007-10-01 19:36:52 +0200 (Mon, 01 Oct 2007) New Revision: 22398 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22398&view=rev Modified: haiku/trunk/build/scripts/build_haiku_image Log: Partitions are no regular files. The check for mere existence shall suffice. Modified: haiku/trunk/build/scripts/build_haiku_image =================================================================== --- haiku/trunk/build/scripts/build_haiku_image 2007-10-01 17:27:13 UTC (rev 22397) +++ haiku/trunk/build/scripts/build_haiku_image 2007-10-01 17:36:52 UTC (rev 22398) @@ -84,7 +84,7 @@ echo if [ ! $updateOnly ]; then echo "Creating image ..." - if [ ! -f $imagePath -o ! "$dontClearImage" ]; then + if [ ! -e $imagePath -o ! "$dontClearImage" ]; then dd if=/dev/zero of=$imagePath bs=1048576 count=$imageSize fi $bfsShell --initialize $imagePath Haiku From bonefish at mail.berlios.de Mon Oct 1 20:39:02 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Mon, 1 Oct 2007 20:39:02 +0200 Subject: [Haiku-commits] r22399 - haiku/trunk/headers/private/shared Message-ID: <200710011839.l91Id2hp009114@sheep.berlios.de> Author: bonefish Date: 2007-10-01 20:39:02 +0200 (Mon, 01 Oct 2007) New Revision: 22399 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22399&view=rev Modified: haiku/trunk/headers/private/shared/AutoLocker.h Log: Allow derived classes to access the member variables. Modified: haiku/trunk/headers/private/shared/AutoLocker.h =================================================================== --- haiku/trunk/headers/private/shared/AutoLocker.h 2007-10-01 17:36:52 UTC (rev 22398) +++ haiku/trunk/headers/private/shared/AutoLocker.h 2007-10-01 18:39:02 UTC (rev 22399) @@ -148,7 +148,7 @@ inline operator bool() const { return fLocked; } -private: +protected: Lockable *fLockable; bool fLocked; Locking fLocking; From bonefish at mail.berlios.de Mon Oct 1 20:48:53 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Mon, 1 Oct 2007 20:48:53 +0200 Subject: [Haiku-commits] r22400 - haiku/trunk/src/system/kernel/fs Message-ID: <200710011848.l91Imr1n009652@sheep.berlios.de> Author: bonefish Date: 2007-10-01 20:48:52 +0200 (Mon, 01 Oct 2007) New Revision: 22400 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22400&view=rev Modified: haiku/trunk/src/system/kernel/fs/fd.cpp haiku/trunk/src/system/kernel/fs/vfs_select.cpp Log: * Added a handy FDGetter AutoLocker-style class. * In select_fd(): First get the file descriptor, then check whether any events have to be selected at all. This has the advantage that the caller can interpret an error return code as invalid FD. Consequently common_poll() no longer checks FD validity separately -- this was a race condition. * common_poll() always selects POLLERR and POLLHUP now, which it has to do according to the specs. Modified: haiku/trunk/src/system/kernel/fs/fd.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/fd.cpp 2007-10-01 18:39:02 UTC (rev 22399) +++ haiku/trunk/src/system/kernel/fs/fd.cpp 2007-10-01 18:48:52 UTC (rev 22400) @@ -27,10 +27,53 @@ #endif +static struct file_descriptor* get_fd_locked(struct io_context* context, + int fd); static void deselect_select_infos(file_descriptor* descriptor, select_info* infos); +struct FDGetterLocking { + inline bool Lock(file_descriptor* /*lockable*/) + { + return false; + } + + inline void Unlock(file_descriptor* lockable) + { + put_fd(lockable); + } +}; + +class FDGetter : public AutoLocker { +public: + inline FDGetter() + : AutoLocker() + { + } + + inline FDGetter(io_context* context, int fd, bool contextLocked = false) + : AutoLocker( + contextLocked ? get_fd_locked(context, fd) : get_fd(context, fd)) + { + } + + inline file_descriptor* SetTo(io_context* context, int fd, + bool contextLocked = false) + { + file_descriptor* descriptor + = contextLocked ? get_fd_locked(context, fd) : get_fd(context, fd); + AutoLocker::SetTo(descriptor, true); + return descriptor; + } + + inline file_descriptor* FD() const + { + return fLockable; + } +}; + + /*** General fd routines ***/ @@ -416,22 +459,23 @@ { TRACE(("select_fd(fd = %d, selectsync = %p, ref = %lu, 0x%x)\n", fd, sync, ref, sync->set[ref].selected_events)); - select_info* info = &sync->set[ref]; - if (info->selected_events == 0) - return B_OK; + FDGetter fdGetter; + // define before the context locker, so it will be destroyed after it io_context* context = get_current_io_context(kernel); MutexLocker locker(context->io_mutex); - struct file_descriptor* descriptor = get_fd_locked(context, fd); + struct file_descriptor* descriptor = fdGetter.SetTo(context, fd, true); if (descriptor == NULL) return B_FILE_ERROR; + select_info* info = &sync->set[ref]; + if (info->selected_events == 0) + return B_OK; + if (!descriptor->ops->fd_select) { // if the I/O subsystem doesn't support select(), we will // immediately notify the select call - locker.Unlock(); - put_fd(descriptor); return notify_select_events(info, info->selected_events); } @@ -461,7 +505,6 @@ if (selectedEvents == 0) deselect_fd(fd, sync, ref, kernel); - put_fd(descriptor); return B_OK; } @@ -475,10 +518,13 @@ if (info->selected_events == 0) return B_OK; + FDGetter fdGetter; + // define before the context locker, so it will be destroyed after it + io_context* context = get_current_io_context(kernel); MutexLocker locker(context->io_mutex); - struct file_descriptor* descriptor = get_fd_locked(context, fd); + struct file_descriptor* descriptor = fdGetter.SetTo(context, fd, true); if (descriptor == NULL) return B_FILE_ERROR; @@ -489,11 +535,8 @@ infoLocation = &(*infoLocation)->next; // If not found, someone else beat us to it. - if (*infoLocation != info) { - locker.Unlock(); - put_fd(descriptor); + if (*infoLocation != info) return B_OK; - } *infoLocation = info->next; @@ -511,7 +554,6 @@ put_select_sync(sync); - put_fd(descriptor); return B_OK; } Modified: haiku/trunk/src/system/kernel/fs/vfs_select.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/vfs_select.cpp 2007-10-01 18:39:02 UTC (rev 22399) +++ haiku/trunk/src/system/kernel/fs/vfs_select.cpp 2007-10-01 18:48:52 UTC (rev 22400) @@ -149,8 +149,10 @@ if (errorSet && FD_ISSET(fd, errorSet)) sync->set[fd].selected_events |= SELECT_FLAG(B_SELECT_ERROR); - select_fd(fd, sync, fd, kernel); - // array position is the same as the fd for select() + if (sync->set[fd].selected_events != 0) { + select_fd(fd, sync, fd, kernel); + // array position is the same as the fd for select() + } } locker.Unlock(); @@ -246,21 +248,17 @@ for (i = 0; i < numFDs; i++) { int fd = fds[i].fd; - // check if fds are valid - if (!fd_is_valid(fd, kernel)) { - fds[i].revents = POLLNVAL; - continue; - } - // initialize events masks - fds[i].events &= ~POLLNVAL; - fds[i].revents = 0; - sync->set[i].selected_events = fds[i].events; + sync->set[i].selected_events = fds[i].events & ~POLLNVAL + | POLLERR | POLLHUP; sync->set[i].events = 0; - select_fd(fd, sync, i, kernel); - if (sync->set[i].selected_events != 0) - count++; + if (select_fd(fd, sync, i, kernel) == B_OK) { + fds[i].revents = 0; + if (sync->set[i].selected_events != 0) + count++; + } else + fds[i].revents = POLLNVAL; } if (count < 1) { @@ -289,7 +287,8 @@ continue; // POLLxxx flags and B_SELECT_xxx flags are compatible - fds[i].revents = sync->set[i].events; + fds[i].revents = sync->set[i].events + & sync->set[i].selected_events; if (fds[i].revents != 0) count++; } From bonefish at mail.berlios.de Tue Oct 2 00:24:42 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Tue, 2 Oct 2007 00:24:42 +0200 Subject: [Haiku-commits] r22401 - in haiku/trunk: headers/private/kernel src/system/kernel Message-ID: <200710012224.l91MOgSv021330@sheep.berlios.de> Author: bonefish Date: 2007-10-02 00:24:42 +0200 (Tue, 02 Oct 2007) New Revision: 22401 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22401&view=rev Modified: haiku/trunk/headers/private/kernel/condition_variable.h haiku/trunk/src/system/kernel/condition_variable.cpp haiku/trunk/src/system/kernel/signal.cpp Log: Addressed a deadlock race condition: Acquiration of condition variable and thread spinlock was reverse in Wait() and Notify(). The thread lock is now the outer lock -- this way it is still possible to call Notify() with the thread lock being held. Modified: haiku/trunk/headers/private/kernel/condition_variable.h =================================================================== --- haiku/trunk/headers/private/kernel/condition_variable.h 2007-10-01 18:48:52 UTC (rev 22400) +++ haiku/trunk/headers/private/kernel/condition_variable.h 2007-10-01 22:24:42 UTC (rev 22401) @@ -82,8 +82,7 @@ void Notify(bool all, bool threadsLocked); private: - void _Notify(bool all, bool threadsLocked, - status_t result); + void _Notify(bool all, status_t result); protected: const void* fObject; Modified: haiku/trunk/src/system/kernel/condition_variable.cpp =================================================================== --- haiku/trunk/src/system/kernel/condition_variable.cpp 2007-10-01 18:48:52 UTC (rev 22400) +++ haiku/trunk/src/system/kernel/condition_variable.cpp 2007-10-01 22:24:42 UTC (rev 22401) @@ -134,6 +134,7 @@ } InterruptsLocker _; + SpinLocker threadLocker(thread_spinlock); SpinLocker locker(sConditionVariablesLock); // get first entry for this thread @@ -159,10 +160,9 @@ thread->condition_variable_entry = firstEntry; thread->sem.blocking = -1; - GRAB_THREAD_LOCK(); locker.Unlock(); scheduler_reschedule(); - RELEASE_THREAD_LOCK(); + threadLocker.Unlock(); return firstEntry->fResult; } @@ -289,6 +289,7 @@ ASSERT(fObject != NULL); InterruptsLocker _; + SpinLocker threadLocker(threadsLocked ? NULL : &thread_spinlock); SpinLocker locker(sConditionVariablesLock); #if KDEBUG @@ -304,7 +305,7 @@ fObjectType = NULL; if (fEntries) - _Notify(true, threadsLocked, B_ENTRY_NOT_FOUND); + _Notify(true, B_ENTRY_NOT_FOUND); } @@ -314,6 +315,7 @@ ASSERT(fObject != NULL); InterruptsLocker _; + SpinLocker threadLocker(threadsLocked ? NULL : &thread_spinlock); SpinLocker locker(sConditionVariablesLock); #if KDEBUG @@ -325,18 +327,17 @@ #endif if (fEntries) - _Notify(all, threadsLocked, B_OK); + _Notify(all, B_OK); } -//! Called with interrupts disabled and the condition variable spinlock held. +/*! Called with interrupts disabled and the condition variable spinlock and + thread lock held. +*/ void -PrivateConditionVariable::_Notify(bool all, bool threadsLocked, status_t result) +PrivateConditionVariable::_Notify(bool all, status_t result) { // dequeue and wake up the blocked threads - if (!threadsLocked) - GRAB_THREAD_LOCK(); - while (PrivateConditionVariableEntry* entry = fEntries) { fEntries = entry->fVariableNext; entry->fVariableNext = NULL; @@ -370,37 +371,19 @@ if (!all) break; } - - if (!threadsLocked) - RELEASE_THREAD_LOCK(); } // #pragma mark - -/*! Interrupts must be disabled, thread lock must be held. Note, that the thread - lock may temporarily be released. +/*! Interrupts must be disabled, thread lock must be held. */ status_t condition_variable_interrupt_thread(struct thread* thread) { - if (thread == NULL || thread->state != B_THREAD_WAITING - || thread->condition_variable_entry == NULL) { - return B_BAD_VALUE; - } - - thread_id threadID = thread->id; - - // We also need the condition variable spin lock, so, in order to respect - // the locking order, we must temporarily release the thread lock. - RELEASE_THREAD_LOCK(); SpinLocker locker(sConditionVariablesLock); - GRAB_THREAD_LOCK(); - // re-get the thread and do the checks again - thread = thread_get_thread_struct_locked(threadID); - if (thread == NULL || thread->state != B_THREAD_WAITING || thread->condition_variable_entry == NULL) { return B_BAD_VALUE; Modified: haiku/trunk/src/system/kernel/signal.cpp =================================================================== --- haiku/trunk/src/system/kernel/signal.cpp 2007-10-01 18:48:52 UTC (rev 22400) +++ haiku/trunk/src/system/kernel/signal.cpp 2007-10-01 22:24:42 UTC (rev 22401) @@ -274,8 +274,7 @@ /*! Tries to interrupt a thread waiting for a semaphore or a condition variable. - Interrupts must be disabled, the thread lock be held. Note, that the thread - lock may temporarily be released. + Interrupts must be disabled, the thread lock be held. */ static status_t signal_interrupt_thread(struct thread* thread) From bonefish at mail.berlios.de Tue Oct 2 00:28:54 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Tue, 2 Oct 2007 00:28:54 +0200 Subject: [Haiku-commits] r22402 - haiku/trunk/src/system/kernel Message-ID: <200710012228.l91MSsBd022671@sheep.berlios.de> Author: bonefish Date: 2007-10-02 00:28:54 +0200 (Tue, 02 Oct 2007) New Revision: 22402 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22402&view=rev Modified: haiku/trunk/src/system/kernel/condition_variable.cpp Log: * Increased condition variable hash size. * Renamed condition variable debugger commands to cvar and cvars. Modified: haiku/trunk/src/system/kernel/condition_variable.cpp =================================================================== --- haiku/trunk/src/system/kernel/condition_variable.cpp 2007-10-01 22:24:42 UTC (rev 22401) +++ haiku/trunk/src/system/kernel/condition_variable.cpp 2007-10-01 22:28:54 UTC (rev 22402) @@ -17,7 +17,7 @@ #include -static const int kConditionVariableHashSize = 64; +static const int kConditionVariableHashSize = 512; struct ConditionVariableHashDefinition { @@ -429,9 +429,9 @@ strerror(error)); } - add_debugger_command("condition_variable", &dump_condition_variable, + add_debugger_command("cvar", &dump_condition_variable, "Dump condition_variable"); - add_debugger_command("condition_variables", &list_condition_variables, + add_debugger_command("cvars", &list_condition_variables, "List condition variables"); } From bonefish at mail.berlios.de Tue Oct 2 00:46:57 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Tue, 2 Oct 2007 00:46:57 +0200 Subject: [Haiku-commits] r22403 - haiku/trunk/src/system/kernel Message-ID: <200710012246.l91MkvgS031744@sheep.berlios.de> Author: bonefish Date: 2007-10-02 00:46:56 +0200 (Tue, 02 Oct 2007) New Revision: 22403 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22403&view=rev Modified: haiku/trunk/src/system/kernel/thread.cpp Log: Fixed a race condition on thread exit: There was a gap between releasing the death stack and reacquiring the thread lock in which another thread could snatch our stack that we were still going to use for the scheduler. Now we've got a second spinlock that we can hold while releasing a semaphore. Modified: haiku/trunk/src/system/kernel/thread.cpp =================================================================== --- haiku/trunk/src/system/kernel/thread.cpp 2007-10-01 22:28:54 UTC (rev 22402) +++ haiku/trunk/src/system/kernel/thread.cpp 2007-10-01 22:46:56 UTC (rev 22403) @@ -87,6 +87,7 @@ static unsigned int sNumDeathStacks; static unsigned int volatile sDeathStackBitmap; static sem_id sDeathStackSem; +static spinlock sDeathStackLock = 0; static struct thread *last_thread_dumped = NULL; @@ -524,14 +525,19 @@ acquire_sem(sDeathStackSem); + // grab the death stack and thread locks, find a free spot and release + state = disable_interrupts(); - // grap the thread lock, find a free spot and release + acquire_spinlock(&sDeathStackLock); GRAB_THREAD_LOCK(); + bit = sDeathStackBitmap; bit = (~bit) & ~((~bit) - 1); sDeathStackBitmap |= bit; + RELEASE_THREAD_LOCK(); + release_spinlock(&sDeathStackLock); restore_interrupts(state); @@ -553,12 +559,12 @@ } -/*! Returns the thread's death stack to the pool. */ +/*! Returns the thread's death stack to the pool. + Interrupts must be disabled and the sDeathStackLock be held. +*/ static void put_death_stack(uint32 index) { - cpu_status state; - TRACE(("put_death_stack...: passed %lu\n", index)); if (index >= sNumDeathStacks) @@ -567,16 +573,12 @@ if (!(sDeathStackBitmap & (1 << index))) panic("put_death_stack: passed invalid stack index %ld\n", index); - state = disable_interrupts(); - GRAB_THREAD_LOCK(); sDeathStackBitmap &= ~(1 << index); RELEASE_THREAD_LOCK(); - restore_interrupts(state); - release_sem_etc(sDeathStackSem, 1, B_DO_NOT_RESCHEDULE); - // we must not have acquired the thread lock when releasing a semaphore + // we must not hold the thread lock when releasing a semaphore } @@ -634,9 +636,14 @@ // return the death stack and reschedule one last time + // Note that we need to hold sDeathStackLock until we've got the thread + // lock. Otherwise someone else might grab our stack in the meantime. + acquire_spinlock(&sDeathStackLock); put_death_stack(args.death_stack); GRAB_THREAD_LOCK(); + release_spinlock(&sDeathStackLock); + scheduler_reschedule(); // requires thread lock to be held @@ -1273,6 +1280,7 @@ args.death_sem = cachedDeathSem; args.original_team_id = teamID; + disable_interrupts(); // set the new kernel stack officially to the death stack, it won't be From axeld at mail.berlios.de Tue Oct 2 02:01:18 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 2 Oct 2007 02:01:18 +0200 Subject: [Haiku-commits] r22404 - haiku/trunk/src/system/kernel/vm Message-ID: <200710020001.l9201IYG024175@sheep.berlios.de> Author: axeld Date: 2007-10-02 02:01:18 +0200 (Tue, 02 Oct 2007) New Revision: 22404 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22404&view=rev Modified: haiku/trunk/src/system/kernel/vm/vm_store_anonymous_noswap.cpp Log: The no-swap store shouldn't fool the page writer into believing that its pages could be written back. This should stop the page thief from stealing active pages that cannot be recreated easily :-) Modified: haiku/trunk/src/system/kernel/vm/vm_store_anonymous_noswap.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_store_anonymous_noswap.cpp 2007-10-01 22:46:56 UTC (rev 22403) +++ haiku/trunk/src/system/kernel/vm/vm_store_anonymous_noswap.cpp 2007-10-02 00:01:18 UTC (rev 22404) @@ -102,7 +102,7 @@ size_t count, size_t *_numBytes, bool fsReenter) { // no place to write, this will cause the page daemon to skip this store - return 0; + return B_ERROR; } From axeld at mail.berlios.de Tue Oct 2 03:01:04 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 2 Oct 2007 03:01:04 +0200 Subject: [Haiku-commits] r22405 - haiku/trunk/src/add-ons/kernel/drivers/network/stack Message-ID: <200710020101.l92114fp028246@sheep.berlios.de> Author: axeld Date: 2007-10-02 03:01:01 +0200 (Tue, 02 Oct 2007) New Revision: 22405 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22405&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/network/stack/kernel_stack.cpp Log: If opening the net_stack driver failed because there was no stack, opening it a second time would magically work, as it skipped its initialization then... Modified: haiku/trunk/src/add-ons/kernel/drivers/network/stack/kernel_stack.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/stack/kernel_stack.cpp 2007-10-02 00:01:18 UTC (rev 22404) +++ haiku/trunk/src/add-ons/kernel/drivers/network/stack/kernel_stack.cpp 2007-10-02 01:01:01 UTC (rev 22405) @@ -221,6 +221,7 @@ status_t status = get_module(NET_STARTER_MODULE_NAME, &module); if (status < B_OK) { ERROR("Can't load network stack module: %ld\n", status); + atomic_add(&sOpenCount, -1); return status; } @@ -228,6 +229,7 @@ if (status < B_OK) { ERROR("Can't load " NET_SOCKET_MODULE_NAME " module: %ld\n", status); put_module(NET_STARTER_MODULE_NAME); + atomic_add(&sOpenCount, -1); return status; } } From jackburton at mail.berlios.de Tue Oct 2 11:37:42 2007 From: jackburton at mail.berlios.de (jackburton at BerliOS) Date: Tue, 2 Oct 2007 11:37:42 +0200 Subject: [Haiku-commits] r22406 - haiku/trunk/src/preferences/time Message-ID: <200710020937.l929bgLa007655@sheep.berlios.de> Author: jackburton Date: 2007-10-02 11:37:41 +0200 (Tue, 02 Oct 2007) New Revision: 22406 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22406&view=rev Modified: haiku/trunk/src/preferences/time/TZDisplay.cpp Log: Patch by Rene Gollent which fixes displaying of current time. I've used snprintf instead of sprintf and reduced the size of the char array, though. Hope you don't mind, Rene. Modified: haiku/trunk/src/preferences/time/TZDisplay.cpp =================================================================== --- haiku/trunk/src/preferences/time/TZDisplay.cpp 2007-10-02 01:01:01 UTC (rev 22405) +++ haiku/trunk/src/preferences/time/TZDisplay.cpp 2007-10-02 09:37:41 UTC (rev 22406) @@ -9,6 +9,8 @@ * */ +#include + #include "TZDisplay.h" @@ -125,9 +127,11 @@ if (hour > 11) ap = "PM"; - fTime.SetTo(""); - fTime << ahour << ":" << minute << ":" << ap; + char buffer[32]; + snprintf(buffer, sizeof(buffer), "%ld:%02ld %s", ahour, minute, ap); + fTime.SetTo(buffer); + Invalidate(); } From axeld at mail.berlios.de Tue Oct 2 12:54:33 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 2 Oct 2007 12:54:33 +0200 Subject: [Haiku-commits] r22407 - haiku/trunk/src/add-ons/kernel/drivers/network/stack Message-ID: <200710021054.l92AsXpJ020552@sheep.berlios.de> Author: axeld Date: 2007-10-02 12:54:32 +0200 (Tue, 02 Oct 2007) New Revision: 22407 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22407&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/network/stack/kernel_stack.cpp Log: Fixed initialization threading issues I introduced yesterday. Modified: haiku/trunk/src/add-ons/kernel/drivers/network/stack/kernel_stack.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/stack/kernel_stack.cpp 2007-10-02 09:37:41 UTC (rev 22406) +++ haiku/trunk/src/add-ons/kernel/drivers/network/stack/kernel_stack.cpp 2007-10-02 10:54:32 UTC (rev 22407) @@ -8,9 +8,12 @@ act as an interface to the networking stack. */ -#include #include +#include +#include +#include + #include #include #include @@ -18,9 +21,7 @@ #include // IS_KERNEL_ADDRESS #include // user_fd_kernel_ioctl -#include -#include -#include +#include #define NET_STARTER_MODULE_NAME "network/stack/starter/v1" @@ -46,6 +47,8 @@ int32 api_version = B_CUR_DRIVER_API_VERSION; static int32 sOpenCount = 0; +static status_t sInitializationStatus = B_NO_INIT; +static sem_id sInitializationSem; static struct net_socket_module_info *sSocket = NULL; @@ -219,19 +222,33 @@ // networking stack module_info *module; status_t status = get_module(NET_STARTER_MODULE_NAME, &module); - if (status < B_OK) { + if (status == B_OK) { + status = get_module(NET_SOCKET_MODULE_NAME, + (module_info **)&sSocket); + if (status != B_OK) { + put_module(NET_STARTER_MODULE_NAME); + ERROR("Can't load " NET_SOCKET_MODULE_NAME " module: %ld\n", + status); + } + } else ERROR("Can't load network stack module: %ld\n", status); - atomic_add(&sOpenCount, -1); - return status; - } - status = get_module(NET_SOCKET_MODULE_NAME, (module_info **)&sSocket); + sInitializationStatus = status; + release_sem_etc(sInitializationSem, 1, + B_RELEASE_ALL | B_DO_NOT_RESCHEDULE); + if (status < B_OK) { - ERROR("Can't load " NET_SOCKET_MODULE_NAME " module: %ld\n", status); - put_module(NET_STARTER_MODULE_NAME); atomic_add(&sOpenCount, -1); return status; } + } else { + while (sInitializationStatus == B_NO_INIT) { + acquire_sem(sInitializationSem); + } + if (sInitializationStatus != B_OK) { + atomic_add(&sOpenCount, -1); + return sInitializationStatus; + } } net_stack_cookie *cookie = (net_stack_cookie *)malloc(sizeof(net_stack_cookie)); @@ -284,6 +301,7 @@ // no interface defined) put_module(NET_SOCKET_MODULE_NAME); put_module(NET_STARTER_MODULE_NAME); + sInitializationStatus = B_NO_INIT; } return B_OK; @@ -653,6 +671,11 @@ status_t init_driver(void) { + sInitializationSem = create_sem(1, "net stack init"); + if (sInitializationSem < B_OK) + return sInitializationSem; + + sInitializationStatus = B_NO_INIT; return B_OK; } @@ -660,6 +683,7 @@ void uninit_driver(void) { + delete_sem(sInitializationSem); } From axeld at mail.berlios.de Tue Oct 2 13:56:34 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 2 Oct 2007 13:56:34 +0200 Subject: [Haiku-commits] r22408 - haiku/trunk/src/add-ons/kernel/bus_managers/acpi Message-ID: <200710021156.l92BuYNr032371@sheep.berlios.de> Author: axeld Date: 2007-10-02 13:56:33 +0200 (Tue, 02 Oct 2007) New Revision: 22408 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22408&view=rev Modified: haiku/trunk/src/add-ons/kernel/bus_managers/acpi/acpi_busman.c Log: * Fixed module leak in case there was an error during init when used on BeOS. * Check safemode settings only when it's not already disabled (doesn't make sense to check those then). * Minor cleanup Modified: haiku/trunk/src/add-ons/kernel/bus_managers/acpi/acpi_busman.c =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/acpi/acpi_busman.c 2007-10-02 10:54:32 UTC (rev 22407) +++ haiku/trunk/src/add-ons/kernel/bus_managers/acpi/acpi_busman.c 2007-10-02 11:56:33 UTC (rev 22408) @@ -62,100 +62,121 @@ status_t acpi_std_ops(int32 op,...) { - ACPI_STATUS Status; - bool acpiDisabled = false; - void *settings; - - switch(op) { + switch (op) { case B_MODULE_INIT: - // check if safemode settings disable DMA - + { + ACPI_STATUS status; + bool acpiDisabled = false; + void *settings; + settings = load_driver_settings("kernel"); if (settings != NULL) { - acpiDisabled = !get_driver_boolean_parameter(settings, "acpi", true, true); + acpiDisabled = !get_driver_boolean_parameter(settings, "acpi", + true, true); unload_driver_settings(settings); } - - settings = load_driver_settings(B_SAFEMODE_DRIVER_SETTINGS); - if (settings != NULL) { - acpiDisabled = get_driver_boolean_parameter(settings, B_SAFEMODE_DISABLE_ACPI, - acpiDisabled, acpiDisabled); - unload_driver_settings(settings); - } + if (!acpiDisabled) { + // check if safemode settings disable DMA + settings = load_driver_settings(B_SAFEMODE_DRIVER_SETTINGS); + if (settings != NULL) { + acpiDisabled = get_driver_boolean_parameter(settings, + B_SAFEMODE_DISABLE_ACPI, false, false); + unload_driver_settings(settings); + } + } + if (acpiDisabled) { ERROR("ACPI disabled"); return ENOSYS; } - - #ifndef __HAIKU__ + +#ifndef __HAIKU__ { // Once upon a time, there was no module(s) dependency(ies) automatic loading feature. // Let's do it the old way status_t status; - - status = get_module(B_DPC_MODULE_NAME, (module_info **) &gDPC); - if (status != B_OK) return status; - - status = get_module(B_PCI_MODULE_NAME, (module_info **) &gPCIManager); - if (status != B_OK) return status; + + status = get_module(B_DPC_MODULE_NAME, (module_info **)&gDPC); + if (status != B_OK) + return status; + + status = get_module(B_PCI_MODULE_NAME, + (module_info **)&gPCIManager); + if (status != B_OK) { + put_module(B_DPC_MODULE_NAME); + return status; + } } - #endif - +#endif + gDPChandle = gDPC->new_dpc_queue("acpi_task", B_NORMAL_PRIORITY, 10); - #ifdef ACPI_DEBUG_OUTPUT - AcpiDbgLevel = ACPI_DEBUG_ALL | ACPI_LV_VERBOSE; - AcpiDbgLayer = ACPI_ALL_COMPONENTS; - #endif +#ifdef ACPI_DEBUG_OUTPUT + AcpiDbgLevel = ACPI_DEBUG_ALL | ACPI_LV_VERBOSE; + AcpiDbgLayer = ACPI_ALL_COMPONENTS; +#endif - Status = AcpiInitializeSubsystem(); - if (Status != AE_OK) { - ERROR("AcpiInitializeSubsystem failed (%s)\n", AcpiFormatException(Status)); - return B_ERROR; + status = AcpiInitializeSubsystem(); + if (status != AE_OK) { + ERROR("AcpiInitializeSubsystem failed (%s)\n", + AcpiFormatException(status)); + goto err; } - - Status = AcpiInitializeTables(NULL, 0, TRUE); - if (Status != AE_OK) { - ERROR("AcpiInitializeTables failed (%s)\n", AcpiFormatException(Status)); - return B_ERROR; + + status = AcpiInitializeTables(NULL, 0, TRUE); + if (status != AE_OK) { + ERROR("AcpiInitializeTables failed (%s)\n", + AcpiFormatException(status)); + goto err; } - Status = AcpiLoadTables(); - if (Status != AE_OK) { - ERROR("AcpiLoadTables failed (%s)\n", AcpiFormatException(Status)); - return B_ERROR; + status = AcpiLoadTables(); + if (status != AE_OK) { + ERROR("AcpiLoadTables failed (%s)\n", + AcpiFormatException(status)); + goto err; } - - Status = AcpiEnableSubsystem(ACPI_FULL_INITIALIZATION); - if (Status != AE_OK) { - ERROR("AcpiEnableSubsystem failed (%s)\n", AcpiFormatException(Status)); - return B_ERROR; + + status = AcpiEnableSubsystem(ACPI_FULL_INITIALIZATION); + if (status != AE_OK) { + ERROR("AcpiEnableSubsystem failed (%s)\n", + AcpiFormatException(status)); + goto err; } - + /* Phew. Now in ACPI mode */ TRACE("ACPI initialized\n"); - break; + return B_OK; + err: +#ifndef __HAIKU__ + put_module(B_DPC_MODULE_NAME); + put_module(B_PCI_MODULE_NAME); +#endif + return B_ERROR; + } + case B_MODULE_UNINIT: - Status = AcpiTerminate(); - if (Status != AE_OK) + { + if (AcpiTerminate() != AE_OK) ERROR("Could not bring system out of ACPI mode. Oh well.\n"); - + /* This isn't so terrible. We'll just fail silently */ if (gDPChandle != NULL) { gDPC->delete_dpc_queue(gDPChandle); gDPChandle = NULL; } - #ifndef __HAIKU__ +#ifndef __HAIKU__ // Once upon a time, there was no module(s) dependency(ies) automatic UNloading feature. // Let's do it the old way put_module(B_DPC_MODULE_NAME); put_module(B_PCI_MODULE_NAME); - #endif +#endif + break; + } - break; default: return B_ERROR; } From axeld at mail.berlios.de Tue Oct 2 15:17:20 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 2 Oct 2007 15:17:20 +0200 Subject: [Haiku-commits] r22409 - haiku/trunk/src/system/runtime_loader Message-ID: <200710021317.l92DHKoW004135@sheep.berlios.de> Author: axeld Date: 2007-10-02 15:17:19 +0200 (Tue, 02 Oct 2007) New Revision: 22409 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22409&view=rev Modified: haiku/trunk/src/system/runtime_loader/elf.cpp Log: * load_program() (and probably others) could call delete_image() with a NULL pointer - which it now handles gracefully. * This also fixes starting the runtime loader directly: it no longer crashes but will just return an error. Modified: haiku/trunk/src/system/runtime_loader/elf.cpp =================================================================== --- haiku/trunk/src/system/runtime_loader/elf.cpp 2007-10-02 11:56:33 UTC (rev 22408) +++ haiku/trunk/src/system/runtime_loader/elf.cpp 2007-10-02 13:17:19 UTC (rev 22409) @@ -370,6 +370,9 @@ static void delete_image(image_t *image) { + if (image == NULL) + return; + _kern_unregister_image(image->id); // registered in load_container() From stippi at mail.berlios.de Tue Oct 2 16:09:12 2007 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Tue, 2 Oct 2007 16:09:12 +0200 Subject: [Haiku-commits] r22410 - haiku/trunk/src/servers/app Message-ID: <200710021409.l92E9CFN007505@sheep.berlios.de> Author: stippi Date: 2007-10-02 16:09:11 +0200 (Tue, 02 Oct 2007) New Revision: 22410 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22410&view=rev Modified: haiku/trunk/src/servers/app/Desktop.cpp haiku/trunk/src/servers/app/Desktop.h haiku/trunk/src/servers/app/EventDispatcher.cpp haiku/trunk/src/servers/app/MultiLocker.cpp haiku/trunk/src/servers/app/ServerWindow.cpp haiku/trunk/src/servers/app/ServerWindow.h haiku/trunk/src/servers/app/ViewLayer.cpp Log: * added a way for the ServerWindow message loop to determine the required type of locking before processing the message (single/all window lock) -> in most message cases, I could comment out the unlocking/locking which switched to the different lock, because the required lock is now already held, this removes some race conditions which were commented in the code already * EventDispatcher::SetDragMessage() didn't lock the object, this would have been bad if multiple windows tried to set a drag bitmap at once * the Desktop object keeps track of mouse position and pressed buttons, so that it doesn't need to lock the EventDispatcher for sending fake mouse moves to windows on show/hide of windows (solves some cases of possible dead locks with the new locking strategy) * the keyboard EventFilter switches the current workspace asynchrnously from the Desktop thread (another source of possible deadlocks) * the "reader is trying to become writer" check in MultiLocker is only used in DEBUG mode now As a summary: It would be nice if ServerWindow used a readlock for all messages it processes itself, and forwards all messages for which it needs a write lock to the Desktop thread. All cases where either the Desktop or the ServerWindow mess with the EventDispatcher are possible sources of deadlocks. This is solved right now by making sure that the lock is released before using the EventDispatcher. I have not observed any deadlocks while switching workspaces and launching many apps anymore, neither crashes. But I have not tested extensively except for in the test environment. That being said, I could reproduce the problems on first try before in Haiku. Modified: haiku/trunk/src/servers/app/Desktop.cpp =================================================================== --- haiku/trunk/src/servers/app/Desktop.cpp 2007-10-02 13:17:19 UTC (rev 22409) +++ haiku/trunk/src/servers/app/Desktop.cpp 2007-10-02 14:09:11 UTC (rev 22410) @@ -167,7 +167,7 @@ { STRACE(("Set Workspace %ld\n", key - 1)); - fDesktop->SetWorkspace(key - 2); + fDesktop->SetWorkspaceAsync(key - 2); return B_SKIP_MESSAGE; } } @@ -228,6 +228,10 @@ if (message->FindPoint("where", &where) != B_OK) return B_DISPATCH_MESSAGE; + int32 buttons; + if (message->FindInt32("buttons", &buttons) != B_OK) + buttons = 0; + if (!fDesktop->LockAllWindows()) return B_DISPATCH_MESSAGE; @@ -271,6 +275,8 @@ *_target = NULL; } + fDesktop->SetLastMouseState(where, buttons); + fDesktop->UnlockAllWindows(); return B_DISPATCH_MESSAGE; @@ -310,10 +316,17 @@ fSubsetWindows(kSubsetList), fWorkspacesLayer(NULL), fActiveScreen(NULL), + fWindowLock("window lock"), + + fFocusFollowsMouse(false), + fMouseEventWindow(NULL), fWindowUnderMouse(NULL), fViewUnderMouse(B_NULL_TOKEN), + fLastMousePosition(B_ORIGIN), + fLastMouseButtons(0), + fFocus(NULL), fFront(NULL), fBack(NULL) @@ -605,6 +618,14 @@ PostMessage(kMsgQuitLooper); break; + case AS_ACTIVATE_WORKSPACE: { + int32 index; + link.Read(&index); + + SetWorkspace(index); + break; + } + default: printf("Desktop %d:%s received unexpected code %ld\n", 0, "baron", code); @@ -660,11 +681,7 @@ } -ServerCursor* -Desktop::Cursor() const -{ - return HWInterface()->Cursor(); -} +// #pragma mark - void @@ -681,6 +698,32 @@ } +ServerCursor* +Desktop::Cursor() const +{ + return HWInterface()->Cursor(); +} + + +void +Desktop::SetLastMouseState(const BPoint& position, int32 buttons) +{ + fLastMousePosition = position; + fLastMouseButtons = buttons; +} + + +void +Desktop::GetLastMouseState(BPoint* position, int32* buttons) const +{ + *position = fLastMousePosition; + *buttons = fLastMouseButtons; +} + + +// #pragma mark - + + /*! \brief Redraws the background (ie. the desktop window, if any). */ @@ -774,6 +817,20 @@ You must not hold any window lock when calling this method. */ void +Desktop::SetWorkspaceAsync(int32 index) +{ + BPrivate::LinkSender link(MessagePort()); + link.StartMessage(AS_ACTIVATE_WORKSPACE); + link.Attach(index); + link.Flush(); +} + + +/*! + Changes the current workspace to the one specified by \a index. + You must not hold any window lock when calling this method. +*/ +void Desktop::SetWorkspace(int32 index) { LockAllWindows(); @@ -1163,10 +1220,6 @@ void Desktop::_SendFakeMouseMoved(WindowLayer* window) { - BPoint where; - int32 buttons; - EventDispatcher().GetMouse(where, buttons); - int32 viewToken = B_NULL_TOKEN; EventTarget* target = NULL; @@ -1175,11 +1228,11 @@ if (window == NULL) window = MouseEventWindow(); if (window == NULL) - window = WindowAt(where); + window = WindowAt(fLastMousePosition); if (window != NULL) { BMessage message; - window->MouseMoved(&message, where, &viewToken, true); + window->MouseMoved(&message, fLastMousePosition, &viewToken, true); if (viewToken != B_NULL_TOKEN) target = &window->EventTarget(); Modified: haiku/trunk/src/servers/app/Desktop.h =================================================================== --- haiku/trunk/src/servers/app/Desktop.h 2007-10-02 13:17:19 UTC (rev 22409) +++ haiku/trunk/src/servers/app/Desktop.h 2007-10-02 14:09:11 UTC (rev 22410) @@ -77,6 +77,15 @@ void SetCursor(ServerCursor* cursor); ServerCursor* Cursor() const; + void SetLastMouseState(const BPoint& position, + int32 buttons); + // for use by the mouse filter only + // both mouse position calls require + // the Desktop object to be locked + // already + void GetLastMouseState(BPoint* position, + int32* buttons) const; + // for use by ServerWindow void ScreenChanged(Screen* screen, bool makeDefault); @@ -92,6 +101,7 @@ // Workspace methods + void SetWorkspaceAsync(int32 index); void SetWorkspace(int32 index); int32 CurrentWorkspace() { return fCurrentWorkspace; } @@ -263,6 +273,8 @@ WindowLayer* fMouseEventWindow; const WindowLayer* fWindowUnderMouse; int32 fViewUnderMouse; + BPoint fLastMousePosition; + int32 fLastMouseButtons; WindowLayer* fFocus; WindowLayer* fFront; Modified: haiku/trunk/src/servers/app/EventDispatcher.cpp =================================================================== --- haiku/trunk/src/servers/app/EventDispatcher.cpp 2007-10-02 13:17:19 UTC (rev 22409) +++ haiku/trunk/src/servers/app/EventDispatcher.cpp 2007-10-02 14:09:11 UTC (rev 22410) @@ -551,6 +551,8 @@ { ETRACE(("EventDispatcher::SetDragMessage()\n")); + BAutolock _(this); + if (fDragBitmap != bitmap) { if (fDragBitmap) gBitmapManager->DeleteBitmap(fDragBitmap); Modified: haiku/trunk/src/servers/app/MultiLocker.cpp =================================================================== --- haiku/trunk/src/servers/app/MultiLocker.cpp 2007-10-02 13:17:19 UTC (rev 22409) +++ haiku/trunk/src/servers/app/MultiLocker.cpp 2007-10-02 14:09:11 UTC (rev 22410) @@ -443,8 +443,10 @@ locked = true; } else { // new writer acquiring the lock +#if DEBUG if (IsReadLocked()) debugger("Reader wants to become writer!"); +#endif status_t status; do { Modified: haiku/trunk/src/servers/app/ServerWindow.cpp =================================================================== --- haiku/trunk/src/servers/app/ServerWindow.cpp 2007-10-02 13:17:19 UTC (rev 22409) +++ haiku/trunk/src/servers/app/ServerWindow.cpp 2007-10-02 14:09:11 UTC (rev 22410) @@ -368,11 +368,16 @@ if (fQuitting || !fWindowLayer->IsHidden() || fWindowLayer->IsOffscreenWindow()) return; -// TODO: race condition? maybe we need to dispatch a message to the desktop to show/hide us +// TODO: deadlock. Desktop::ShowWindow() will eventually lock the event thread, +// which might be blocking on the all window lock with it's own lock already +// head. +// Maybe we need to dispatch a message to the desktop to show/hide us // instead of doing it from this thread. -fDesktop->UnlockSingleWindow(); +//fDesktop->UnlockSingleWindow(); +fDesktop->UnlockAllWindows(); fDesktop->ShowWindow(fWindowLayer); -fDesktop->LockSingleWindow(); +fDesktop->LockAllWindows(); +//fDesktop->LockSingleWindow(); if (fDirectWindowData != NULL) HandleDirectConnection(B_DIRECT_START | B_BUFFER_RESET); @@ -394,9 +399,7 @@ // TODO: race condition? maybe we need to dispatch a message to the desktop to show/hide us // instead of doing it from this thread. -fDesktop->UnlockSingleWindow(); fDesktop->HideWindow(fWindowLayer); -fDesktop->LockSingleWindow(); } @@ -436,9 +439,9 @@ } if (fWindowLayer != NULL) { -fDesktop->UnlockSingleWindow(); +//fDesktop->UnlockSingleWindow(); fDesktop->SetWindowTitle(fWindowLayer, newTitle); -fDesktop->LockSingleWindow(); +//fDesktop->LockSingleWindow(); } } @@ -586,12 +589,18 @@ newLayer->SetEventMask(eventMask, eventOptions); if (eventMask != 0 || eventOptions != 0) { - fDesktop->UnlockSingleWindow(); +// fDesktop->UnlockSingleWindow(); +// fDesktop->LockAllWindows(); +fDesktop->UnlockAllWindows(); + // TODO: possible deadlock fDesktop->EventDispatcher().AddListener(EventTarget(), newLayer->Token(), eventMask, eventOptions); - fDesktop->LockSingleWindow(); +fDesktop->LockAllWindows(); +// fDesktop->UnlockAllWindows(); +// fDesktop->LockSingleWindow(); } + // TODO: default fonts should be created and stored in the Application DesktopSettings settings(fDesktop); ServerFont font; settings.GetDefaultPlainFont(font); @@ -661,12 +670,12 @@ link.Read(&activate); -fDesktop->UnlockSingleWindow(); +//fDesktop->UnlockSingleWindow(); if (activate) fDesktop->ActivateWindow(fWindowLayer); else fDesktop->SendWindowBehind(fWindowLayer, NULL); -fDesktop->LockSingleWindow(); +//fDesktop->LockSingleWindow(); break; } case AS_SEND_BEHIND: @@ -681,10 +690,10 @@ WindowLayer *behindOf; if ((behindOf = fDesktop->FindWindowLayerByClientToken(token, teamID)) != NULL) { -fDesktop->UnlockSingleWindow(); +//fDesktop->UnlockSingleWindow(); // TODO: there is a big race condition when we unlock here (window could be gone by now)! fDesktop->SendWindowBehind(fWindowLayer, behindOf); -fDesktop->LockSingleWindow(); +//fDesktop->LockSingleWindow(); status = B_OK; } else status = B_NAME_NOT_FOUND; @@ -748,11 +757,11 @@ || windowLayer->Feel() != B_NORMAL_WINDOW_FEEL) { status = B_BAD_VALUE; } else { -fDesktop->UnlockSingleWindow(); +//fDesktop->UnlockSingleWindow(); // TODO: there is a big race condition when we unlock here (window could be gone by now)! status = fDesktop->AddWindowToSubset(fWindowLayer, windowLayer) ? B_OK : B_NO_MEMORY; -fDesktop->LockSingleWindow(); +//fDesktop->LockSingleWindow(); } } @@ -770,10 +779,10 @@ WindowLayer* windowLayer = fDesktop->FindWindowLayerByClientToken( token, App()->ClientTeam()); if (windowLayer != NULL) { -fDesktop->UnlockSingleWindow(); +//fDesktop->UnlockSingleWindow(); // TODO: there is a big race condition when we unlock here (window could be gone by now)! fDesktop->RemoveWindowFromSubset(fWindowLayer, windowLayer); -fDesktop->LockSingleWindow(); +//fDesktop->LockSingleWindow(); status = B_OK; } else status = B_BAD_VALUE; @@ -797,9 +806,9 @@ } if (status == B_OK && !fWindowLayer->IsOffscreenWindow()) { -fDesktop->UnlockSingleWindow(); +//fDesktop->UnlockSingleWindow(); fDesktop->SetWindowLook(fWindowLayer, (window_look)look); -fDesktop->LockSingleWindow(); +//fDesktop->LockSingleWindow(); } fLink.StartMessage(status); @@ -819,9 +828,9 @@ } if (status == B_OK && !fWindowLayer->IsOffscreenWindow()) { -fDesktop->UnlockSingleWindow(); +//fDesktop->UnlockSingleWindow(); fDesktop->SetWindowFeel(fWindowLayer, (window_feel)feel); -fDesktop->LockSingleWindow(); +//fDesktop->LockSingleWindow(); } fLink.StartMessage(status); @@ -841,9 +850,9 @@ } if (status == B_OK && !fWindowLayer->IsOffscreenWindow()) { -fDesktop->UnlockSingleWindow(); +//fDesktop->UnlockSingleWindow(); fDesktop->SetWindowFlags(fWindowLayer, flags); -fDesktop->LockSingleWindow(); +//fDesktop->LockSingleWindow(); } fLink.StartMessage(status); @@ -886,9 +895,9 @@ STRACE(("ServerWindow %s: Message AS_SET_WORKSPACES %lx\n", Title(), newWorkspaces)); -fDesktop->UnlockSingleWindow(); +//fDesktop->UnlockSingleWindow(); fDesktop->SetWindowWorkspaces(fWindowLayer, newWorkspaces); -fDesktop->LockSingleWindow(); +//fDesktop->LockSingleWindow(); break; } case AS_WINDOW_RESIZE: @@ -907,9 +916,9 @@ // pragmatically set window bounds fLink.StartMessage(B_BUSY); } else { -fDesktop->UnlockSingleWindow(); +//fDesktop->UnlockSingleWindow(); fDesktop->ResizeWindowBy(fWindowLayer, xResizeBy, yResizeBy); -fDesktop->LockSingleWindow(); +//fDesktop->LockSingleWindow(); fLink.StartMessage(B_OK); } fLink.Flush(); @@ -931,9 +940,9 @@ // pragmatically set window positions fLink.StartMessage(B_BUSY); } else { -fDesktop->UnlockSingleWindow(); +//fDesktop->UnlockSingleWindow(); fDesktop->MoveWindowBy(fWindowLayer, xMoveBy, yMoveBy); -fDesktop->LockSingleWindow(); +//fDesktop->LockSingleWindow(); fLink.StartMessage(B_OK); } fLink.Flush(); @@ -960,7 +969,7 @@ link.Read(&minHeight); link.Read(&maxHeight); */ - fDesktop->UnlockSingleWindow(); +//fDesktop->UnlockSingleWindow(); if (fDesktop->LockAllWindows()) { fWindowLayer->SetSizeLimits(minWidth, maxWidth, @@ -968,7 +977,7 @@ fDesktop->UnlockAllWindows(); } - fDesktop->LockSingleWindow(); +//fDesktop->LockSingleWindow(); // and now, sync the client to the limits that we were able to enforce fWindowLayer->GetSizeLimits(&minWidth, &maxWidth, @@ -995,9 +1004,9 @@ if (link.Read(buffer, size) == B_OK) { BMessage settings; if (settings.Unflatten(buffer) == B_OK) { -fDesktop->UnlockSingleWindow(); +//fDesktop->UnlockSingleWindow(); fDesktop->SetWindowDecoratorSettings(fWindowLayer, settings); -fDesktop->LockSingleWindow(); +//fDesktop->LockSingleWindow(); } } } @@ -1058,15 +1067,15 @@ { DTRACE(("ServerWindow %s: Message AS_GET_MOUSE\n", fTitle)); - fDesktop->UnlockSingleWindow(); +//fDesktop->UnlockSingleWindow(); // Returns // 1) BPoint mouse location // 2) int32 button state BPoint where; int32 buttons; - fDesktop->EventDispatcher().GetMouse(where, buttons); - fDesktop->LockSingleWindow(); + fDesktop->GetLastMouseState(&where, &buttons); +//fDesktop->LockSingleWindow(); fLink.StartMessage(B_OK); fLink.Attach(where); @@ -1103,10 +1112,10 @@ status_t status = B_OK; if (!fWindowLayer->IsOffscreenWindow()) { - fDesktop->UnlockSingleWindow(); +//fDesktop->UnlockSingleWindow(); fDesktop->SetWindowFeel(fWindowLayer, enable ? kWindowScreenFeel : B_NORMAL_WINDOW_FEEL); - fDesktop->LockSingleWindow(); +//fDesktop->LockSingleWindow(); } else status = B_BAD_TYPE; @@ -1246,8 +1255,14 @@ parent->RemoveChild(view); if (view->EventMask() != 0) { - fDesktop->EventDispatcher().RemoveListener(EventTarget(), - token); + // TODO: possible deadlock (event dispatcher already + // locked itself, waits for Desktop write lock, but + // we have it, now we are trying to lock the event + // dispatcher -> deadlock) +fDesktop->UnlockSingleWindow(); + fDesktop->EventDispatcher().RemoveListener( + EventTarget(), token); +fDesktop->LockSingleWindow(); } if (fCurrentLayer == view) _SetCurrentLayer(parent); @@ -1288,14 +1303,15 @@ } case AS_LAYER_SET_EVENT_MASK: { - STRACE(("ServerWindow %s: Message AS_LAYER_SET_MOUSE_EVENT_MASK: ViewLayer name: %s\n", fTitle, fCurrentLayer->Name())); + STRACE(("ServerWindow %s: Message AS_LAYER_SET_EVENT_MASK: ViewLayer name: %s\n", fTitle, fCurrentLayer->Name())); uint32 eventMask, options; link.Read(&eventMask); if (link.Read(&options) == B_OK) { - fDesktop->UnlockSingleWindow(); fCurrentLayer->SetEventMask(eventMask, options); +fDesktop->UnlockSingleWindow(); + // TODO: possible deadlock! if (eventMask != 0 || options != 0) { fDesktop->EventDispatcher().AddListener(EventTarget(), fCurrentLayer->Token(), eventMask, options); @@ -1303,7 +1319,7 @@ fDesktop->EventDispatcher().RemoveListener(EventTarget(), fCurrentLayer->Token()); } - fDesktop->LockSingleWindow(); +fDesktop->LockSingleWindow(); } break; } @@ -1314,7 +1330,8 @@ link.Read(&eventMask); if (link.Read(&options) == B_OK) { - fDesktop->UnlockSingleWindow(); +fDesktop->UnlockSingleWindow(); + // TODO: possible deadlock if (eventMask != 0 || options != 0) { fDesktop->EventDispatcher().AddTemporaryListener(EventTarget(), fCurrentLayer->Token(), eventMask, options); @@ -1322,7 +1339,7 @@ fDesktop->EventDispatcher().RemoveTemporaryListener(EventTarget(), fCurrentLayer->Token()); } - fDesktop->LockSingleWindow(); +fDesktop->LockSingleWindow(); } // TODO: support B_LOCK_WINDOW_FOCUS option in Desktop @@ -1896,8 +1913,11 @@ if (link.Read(buffer, bufferSize) == B_OK && dragMessage.Unflatten(buffer) == B_OK) { ServerBitmap* bitmap = fServerApp->FindBitmap(bitmapToken); + // TODO: possible deadlock +fDesktop->UnlockSingleWindow(); fDesktop->EventDispatcher().SetDragMessage(dragMessage, - bitmap, offset); + bitmap, offset); +fDesktop->LockSingleWindow(); } delete[] buffer; } @@ -1925,8 +1945,11 @@ BMessage dragMessage; if (link.Read(buffer, bufferSize) == B_OK && dragMessage.Unflatten(buffer) == B_OK) { + // TODO: possible deadlock +fDesktop->UnlockSingleWindow(); fDesktop->EventDispatcher().SetDragMessage(dragMessage, NULL /* should be dragRect */, offset); +fDesktop->LockSingleWindow(); } delete[] buffer; } @@ -2857,6 +2880,7 @@ int32 messagesProcessed = 0; bool lockedDesktop = false; + bool needsAllWindowsLocked = false; while (true) { if (code == AS_DELETE_WINDOW || code == kMsgQuitLooper) { @@ -2881,10 +2905,21 @@ break; } - if (!lockedDesktop) { + needsAllWindowsLocked = _MessageNeedsAllWindowsLocked(code); + + if (!lockedDesktop && !needsAllWindowsLocked) { // only lock it once fDesktop->LockSingleWindow(); lockedDesktop = true; + } else if (lockedDesktop && !needsAllWindowsLocked) { + // nothing to do + } else if (needsAllWindowsLocked) { + if (lockedDesktop) { + // unlock single before locking all + fDesktop->UnlockSingleWindow(); + lockedDesktop = false; + } + fDesktop->LockAllWindows(); } if (atomic_and(&fRedrawRequested, 0) != 0) { @@ -2902,7 +2937,6 @@ # endif #endif } - #ifdef PROFILE_MESSAGE_LOOP @@ -2924,9 +2958,13 @@ } #endif + if (needsAllWindowsLocked) + fDesktop->UnlockAllWindows(); + // only process up to 70 waiting messages at once (we have the Desktop locked) if (!receiver.HasMessages() || ++messagesProcessed > 70) { - fDesktop->UnlockSingleWindow(); + if (lockedDesktop) + fDesktop->UnlockSingleWindow(); break; } @@ -2935,7 +2973,8 @@ if (status < B_OK) { // that shouldn't happen, it's our port printf("Someone deleted our message port!\n"); - fDesktop->UnlockSingleWindow(); + if (lockedDesktop) + fDesktop->UnlockSingleWindow(); // try to let our client die happily NotifyQuitRequested(); @@ -3152,6 +3191,39 @@ } +bool +ServerWindow::_MessageNeedsAllWindowsLocked(uint32 code) const +{ + switch (code) { + case AS_SHOW_WINDOW: + case AS_HIDE_WINDOW: + case AS_MINIMIZE_WINDOW: + case AS_ACTIVATE_WINDOW: + case AS_SET_WINDOW_TITLE: + case AS_ADD_TO_SUBSET: + case AS_REMOVE_FROM_SUBSET: + case AS_LAYER_CREATE_ROOT: + case AS_LAYER_CREATE: + case AS_SEND_BEHIND: + case AS_SET_LOOK: + case AS_SET_FEEL: + case AS_SET_FLAGS: + case AS_SET_WORKSPACES: + case AS_WINDOW_MOVE: + case AS_WINDOW_RESIZE: + case AS_SET_SIZE_LIMITS: + case AS_SET_DECORATOR_SETTINGS: + case AS_GET_MOUSE: + case AS_DIRECT_WINDOW_SET_FULLSCREEN: +// case AS_LAYER_SET_EVENT_MASK: +// case AS_LAYER_SET_MOUSE_EVENT_MASK: + return true; + default: + return false; + } +} + + status_t ServerWindow::PictureToRegion(ServerPicture *picture, BRegion ®ion, bool inverse, BPoint where) Modified: haiku/trunk/src/servers/app/ServerWindow.h =================================================================== --- haiku/trunk/src/servers/app/ServerWindow.h 2007-10-02 13:17:19 UTC (rev 22409) +++ haiku/trunk/src/servers/app/ServerWindow.h 2007-10-02 14:09:11 UTC (rev 22410) @@ -127,6 +127,8 @@ void _SetCurrentLayer(ViewLayer* view); void _UpdateDrawState(ViewLayer* view); + bool _MessageNeedsAllWindowsLocked(uint32 code) const; + // TODO: Move me elsewhere status_t PictureToRegion(ServerPicture *picture, BRegion &, @@ -158,7 +160,7 @@ ViewLayer* fCurrentLayer; BRegion fCurrentDrawingRegion; bool fCurrentDrawingRegionValid; - + direct_window_data* fDirectWindowData; }; Modified: haiku/trunk/src/servers/app/ViewLayer.cpp =================================================================== --- haiku/trunk/src/servers/app/ViewLayer.cpp 2007-10-02 13:17:19 UTC (rev 22409) +++ haiku/trunk/src/servers/app/ViewLayer.cpp 2007-10-02 14:09:11 UTC (rev 22410) @@ -1289,6 +1289,9 @@ } +// #pragma mark - + + void ViewLayer::MouseDown(BMessage* message, BPoint where) { From stippi at mail.berlios.de Tue Oct 2 16:54:15 2007 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Tue, 2 Oct 2007 16:54:15 +0200 Subject: [Haiku-commits] r22411 - haiku/trunk/src/apps/clock Message-ID: <200710021454.l92EsF9r010387@sheep.berlios.de> Author: stippi Date: 2007-10-02 16:54:15 +0200 (Tue, 02 Oct 2007) New Revision: 22411 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22411&view=rev Modified: haiku/trunk/src/apps/clock/cl_view.cpp haiku/trunk/src/apps/clock/cl_view.h haiku/trunk/src/apps/clock/cl_wind.cpp haiku/trunk/src/apps/clock/cl_wind.h haiku/trunk/src/apps/clock/clock.cpp haiku/trunk/src/apps/clock/clock.h Log: patch by Julun: * fixed ticket #1500 * big cleanup and removal of unused code Modified: haiku/trunk/src/apps/clock/cl_view.cpp =================================================================== --- haiku/trunk/src/apps/clock/cl_view.cpp 2007-10-02 14:09:11 UTC (rev 22410) +++ haiku/trunk/src/apps/clock/cl_view.cpp 2007-10-02 14:54:15 UTC (rev 22411) @@ -1,75 +1,65 @@ /* - - cl_view.cpp - -*/ + * Copyright 1999, Be Incorporated. All Rights Reserved. + * This file may be used under the terms of the Be Sample Code License. + * + */ -/* - Copyright 1999, Be Incorporated. All Rights Reserved. - This file may be used under the terms of the Be Sample Code License. -*/ +#include "clock.h" +#include "cl_view.h" -#define DEBUG 1 -#include -#include -#include -#include -#include #include -#include +#include #include #include #include #include #include -#include "clock.h" -#include "cl_view.h" -/* ---------------------------------------------------------------- */ -TOffscreenView::TOffscreenView(BRect frame, char *name, short mRadius, - short hRadius, short offset, long face, bool show) - :BView(frame, name, B_NOT_RESIZABLE, B_WILL_DRAW) -{ - BRect theRect; - short loop; - void *picH; - size_t len; - float counter; - short index; - float x,y; - entry_ref ref; - long error; - - fFace = face; - theRect.Set(0,0,82,82); +#include - for (index = 0; index <= 8; index++) - fClockFace[index] = NULL; +TOffscreenView::TOffscreenView(BRect frame, char *name, short mRadius, + short hRadius, short offset, long face, bool show) + : BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW), + fHours(0), + fMinutes(0), + fSeconds(0), + fOffset(offset), + fHoursRadius(hRadius), + fMinutesRadius(mRadius), + fFace(face), + fShowSeconds(show) +{ + status_t error; #ifdef __HAIKU__ BResources rsrcs; error = rsrcs.SetToImage(&&dummy_label); dummy_label: if (error == B_OK) { { -#else // !__HAIKU__ - // Note: Since we can be run as replicant, we get our resources this way, - // not via be_app->AppResources(). - error = be_roster->FindApp(app_signature, &ref); - printf("be_roster->FindApp() returned %s\n", strerror(error)); +#else + // Note: Since we can be run as replicant, we get our + // resources this way, not via be_app->AppResources(). + entry_ref ref; + error = be_roster->FindApp(kAppSignature, &ref); if (error == B_NO_ERROR) { BFile file(&ref, O_RDONLY); error = file.InitCheck(); if (error == B_NO_ERROR) { BResources rsrcs(&file); -#endif // !__HAIKU__ - - for (loop = 0; loop <= 8; loop++) { - if ((picH = rsrcs.FindResource('PICT', loop+4, &len))) { +#endif + for (short i = 0; i <= 8; i++) + fClockFace[i] = NULL; + + size_t len; + void *picH; + BRect theRect(0, 0, 82, 82); + for (short loop = 0; loop <= 8; loop++) { + if ((picH = rsrcs.FindResource('PICT', loop + 4, &len))) { fClockFace[loop] = new BBitmap(theRect, B_CMAP8); - fClockFace[loop]->SetBits(picH,len,0, B_CMAP8); + fClockFace[loop]->SetBits(picH, len, 0, B_CMAP8); free(picH); } } @@ -77,33 +67,25 @@ theRect.Set(0,0,15,15); if ((picH = rsrcs.FindResource('MICN', "center", &len))) { fCenter = new BBitmap(theRect, B_CMAP8); - fCenter->SetBits(picH,len,0, B_CMAP8); + fCenter->SetBits(picH, len, 0, B_CMAP8); free(picH); } theRect.Set(0,0,2,2); if ((picH = rsrcs.FindResource('PICT', 13, &len))) { fInner = new BBitmap(theRect, B_CMAP8); - fInner->SetBits(picH,len,0, B_CMAP8); + fInner->SetBits(picH, len, 0, B_CMAP8); free(picH); } } } - fMinutesRadius = mRadius; - fHoursRadius = hRadius; - fOffset = offset; - fHours = 0; - fMinutes = 0; - fSeconds = 0; - fShowSeconds = show; - - index = 0; - - // + float x, y; + float counter; + short index = 0; + // Generate minutes points array - // - for (counter = 90; counter >= 0; counter -= 6,index++) { + for (counter = 90; counter >= 0; counter -= 6, index++) { x = mRadius * cos(((360 - counter)/180.0) * 3.1415); x += 41; y = mRadius * sin(((360 - counter)/180.0) * 3.1415); @@ -115,6 +97,7 @@ y += 41; fHourPoints[index].Set(x,y); } + for (counter = 354; counter > 90; counter -= 6,index++) { x = mRadius * cos(((360 - counter)/180.0) * 3.1415); x += 41; @@ -140,14 +123,6 @@ void -TOffscreenView::AttachedToWindow() -{ - SetFontSize(18); - SetFont(be_plain_font); -} - - -void TOffscreenView::DrawX() { ASSERT(Window()); @@ -190,22 +165,22 @@ }; -/* - * Onscreen view object - */ -TOnscreenView::TOnscreenView(BRect rect, char *title, - short mRadius, short hRadius, short offset) - :BView(rect, title, B_NOT_RESIZABLE, - B_WILL_DRAW | B_PULSE_NEEDED | B_DRAW_ON_CHILDREN) +// #pragma mark - + + +TOnscreenView::TOnscreenView(BRect rect, char *title, short mRadius, + short hRadius, short offset) + : BView(rect, title, B_FOLLOW_NONE, + B_WILL_DRAW | B_PULSE_NEEDED | B_DRAW_ON_CHILDREN), + fOffscreen(NULL), + fOffscreenView(NULL) { InitObject(rect, mRadius, hRadius, offset, 1, TRUE); - BRect r = rect; - r.OffsetTo(B_ORIGIN); - r.top = r.bottom - 7; - r.left = r.right - 7; - - BDragger *dw = new BDragger(r, this, 0); + rect.OffsetTo(B_ORIGIN); + rect.top = rect.bottom - 7; + rect.left = rect.right - 7; + BDragger *dw = new BDragger(rect, this); AddChild(dw); } @@ -214,14 +189,7 @@ TOnscreenView::InitObject(BRect rect, short mRadius, short hRadius, short offset, long face, bool show) { - fmRadius = mRadius; - fhRadius = hRadius; - fOffset = offset; - fRect = rect; - fOffscreenView = NULL; - fOffscreen = NULL; - - fOffscreenView = new TOffscreenView(rect, "freqd",mRadius,hRadius, offset, face, show); + fOffscreenView = new TOffscreenView(rect, "freqd", mRadius, hRadius, offset, face, show); fOffscreen = new BBitmap(rect, B_CMAP8, true); if (fOffscreen != NULL && fOffscreen->Lock()) { fOffscreen->AddChild(fOffscreenView); @@ -239,7 +207,9 @@ TOnscreenView::TOnscreenView(BMessage *data) - : BView(data) + : BView(data), + fOffscreen(NULL), + fOffscreenView(NULL) { InitObject(data->FindRect("bounds"), data->FindInt32("mRadius"), data->FindInt32("hRadius"), data->FindInt32("offset"), @@ -250,17 +220,29 @@ status_t TOnscreenView::Archive(BMessage *data, bool deep) const { - inherited::Archive(data, deep); - data->AddString("add_on", app_signature); -//+ data->AddString("add_on_path", "/boot/apps/Clock"); + status_t status = BView::Archive(data, deep); + if (status == B_OK) + status = data->AddString("add_on", kAppSignature); - data->AddRect("bounds", Bounds()); - data->AddInt32("mRadius", fOffscreenView->fMinutesRadius); - data->AddInt32("hRadius", fOffscreenView->fHoursRadius); - data->AddInt32("offset", fOffscreenView->fOffset); - data->AddBool("seconds", fOffscreenView->fShowSeconds); - data->AddInt32("face", fOffscreenView->fFace); - return 0; + if (status == B_OK) + status = data->AddRect("bounds", Bounds()); + + if (status == B_OK) + status = data->AddInt32("mRadius", fOffscreenView->fMinutesRadius); + + if (status == B_OK) + status = data->AddInt32("hRadius", fOffscreenView->fHoursRadius); + + if (status == B_OK) + status = data->AddInt32("offset", fOffscreenView->fOffset); + + if (status == B_OK) + status = data->AddBool("seconds", fOffscreenView->fShowSeconds); + + if (status == B_OK) + status = data->AddInt32("face", fOffscreenView->fFace); + + return status; } @@ -274,34 +256,24 @@ void -TOnscreenView::AttachedToWindow() -{ -//+ PRINT(("InitData m=%d, h=%d, offset=%d\n", fmRadius, fhRadius, fOffset)); -//+ PRINT_OBJECT(fRect); -} - - -void TOnscreenView::Pulse() { - short hours,minutes,seconds; - struct tm *loctime; - time_t current; - ASSERT(fOffscreen); ASSERT(fOffscreenView); - current = time(0); - loctime = localtime(¤t); - hours = loctime->tm_hour; - minutes = loctime->tm_min; - seconds = loctime->tm_sec; + + time_t current = time(0); + struct tm *loctime = localtime(¤t); - if ((fOffscreenView->fShowSeconds && (seconds != fOffscreenView->fSeconds)) || - (minutes != fOffscreenView->fMinutes)) { + short hours = loctime->tm_hour; + short minutes = loctime->tm_min; + short seconds = loctime->tm_sec; + + if ((fOffscreenView->fShowSeconds && (seconds != fOffscreenView->fSeconds)) + || (minutes != fOffscreenView->fMinutes)) { fOffscreenView->fHours = hours; fOffscreenView->fMinutes = minutes; fOffscreenView->fSeconds = seconds; - BRect b = Bounds(); + BRect b = Bounds(); b.InsetBy(12,12); Draw(b); } @@ -309,36 +281,36 @@ void -TOnscreenView::UseFace( short face ) +TOnscreenView::UseFace(short face) { fOffscreenView->fFace = face; - BRect b = Bounds(); + BRect b = Bounds(); b.InsetBy(12,12); Draw(b); } void -TOnscreenView::ShowSecs( bool secs ) +TOnscreenView::ShowSecs(bool secs) { fOffscreenView->fShowSeconds = secs; - BRect b = Bounds(); + BRect b = Bounds(); b.InsetBy(12,12); Invalidate(b); } short -TOnscreenView::ReturnFace( void ) +TOnscreenView::ReturnFace() { - return(fOffscreenView->fFace); + return fOffscreenView->fFace; } short -TOnscreenView::ReturnSeconds( void ) +TOnscreenView::ReturnSeconds() { - return(fOffscreenView->fShowSeconds); + return fOffscreenView->fShowSeconds; } @@ -349,7 +321,8 @@ ASSERT(fOffscreenView); if (fOffscreen->Lock()) { - fOffscreenView->DrawX(); // Composite the clock offscreen... + // Composite the clock offscreen... + fOffscreenView->DrawX(); DrawBitmap(fOffscreen, rect, rect); fOffscreen->Unlock(); } @@ -366,7 +339,6 @@ GetMouse(&cursor,&buttons); if (buttons & B_SECONDARY_MOUSE_BUTTON) { fOffscreenView->fShowSeconds = !fOffscreenView->fShowSeconds; - be_app->PostMessage(SHOW_SECONDS); bounds.InsetBy(12,12); Invalidate(bounds); } else { @@ -384,9 +356,16 @@ { switch(msg->what) { case B_ABOUT_REQUESTED: - (new BAlert("About Clock", "Clock (The Replicant version)\n\n(C)2002 OpenBeOS\n\nOriginally coded by the folks at Be.\n Copyright Be Inc., 1991-1998","OK"))->Go(); - break; + { + BAlert *alert = new BAlert("About Clock", + "Clock (The Replicant version)\n\n(C)2002, 2003 OpenBeOS,\n" + "2004 - 2007, Haiku, Inc.\n\nOriginally coded by the folks " + "at Be.\n Copyright Be Inc., 1991 - 1998", "OK"); + + alert->Go(); + } break; + default: - inherited::MessageReceived(msg); + BView::MessageReceived(msg); } } Modified: haiku/trunk/src/apps/clock/cl_view.h =================================================================== --- haiku/trunk/src/apps/clock/cl_view.h 2007-10-02 14:09:11 UTC (rev 22410) +++ haiku/trunk/src/apps/clock/cl_view.h 2007-10-02 14:54:15 UTC (rev 22411) @@ -1,83 +1,75 @@ /* - - cl_view.h - -*/ -/* - Copyright 1999, Be Incorporated. All Rights Reserved. - This file may be used under the terms of the Be Sample Code License. -*/ - + * Copyright 1999, Be Incorporated. All Rights Reserved. + * This file may be used under the terms of the Be Sample Code License. + * + */ #ifndef _CL_VIEW_H_ #define _CL_VIEW_H_ -#include -#include + #include -#include -#include -class TOffscreenView : public BView { +class BBitmap; +class BMessage; -public: - TOffscreenView(BRect frame, char *name, short mRadius, + +class TOffscreenView : public BView { + public: + TOffscreenView(BRect frame, char *name, short mRadius, short hRadius, short offset, long face, bool show); - virtual ~TOffscreenView(); - virtual void AttachedToWindow(); - virtual void DrawX(); - void NextFace(); + virtual ~TOffscreenView(); + + void DrawX(); + void NextFace(); - BBitmap *fClockFace[9]; - BBitmap *fCenter; - BBitmap *fInner; - short fFace; - BPoint fMinutePoints[60]; - BPoint fHourPoints[60]; - short fMinutesRadius; - short fHoursRadius; - short fOffset; - short fHours; - short fMinutes; - short fSeconds; - bool fShowSeconds; + short fHours; + short fMinutes; + short fSeconds; + + short fOffset; + short fHoursRadius; + short fMinutesRadius; + + short fFace; + bool fShowSeconds; + + private: + BBitmap *fInner; + BBitmap *fCenter; + BBitmap *fClockFace[9]; + + BPoint fHourPoints[60]; + BPoint fMinutePoints[60]; }; -class _EXPORT TOnscreenView : public BView { +class TOnscreenView : public BView { + public: + TOnscreenView(BRect frame, char *name, + short mRadius, short hRadius, short offset); + TOnscreenView(BMessage *data); + virtual ~TOnscreenView(); -public: - TOnscreenView(BRect frame, char *name, short mRadius, - short hRadius, short offset); -virtual ~TOnscreenView(); - TOnscreenView(BMessage *data); -static BArchivable *Instantiate(BMessage *data); -virtual status_t Archive(BMessage *data, bool deep = true) const; - void InitObject(BRect frame, short mRadius, short hRadius, + static BArchivable *Instantiate(BMessage *data); + virtual status_t Archive(BMessage *data, bool deep = true) const; + void InitObject(BRect frame, short mRadius, short hRadius, short offset, long face, bool show); -//+virtual void AllAttached(); -virtual void AttachedToWindow(); -virtual void Draw(BRect updateRect); -virtual void MouseDown( BPoint point); -virtual void MessageReceived(BMessage *msg); -virtual void Pulse(); - void UseFace( short face ); - void ShowSecs( bool secs ); - short ReturnFace( void ); - short ReturnSeconds( void ); + virtual void Pulse(); + virtual void Draw(BRect updateRect); + virtual void MouseDown(BPoint point); + virtual void MessageReceived(BMessage *msg); + short ReturnFace(); + void UseFace(short face); -private: + short ReturnSeconds(); + void ShowSecs(bool secs); - typedef BView inherited; - - BBitmap *fOffscreen; - TOffscreenView *fOffscreenView; - short fmRadius; - short fhRadius; - short fOffset; - BRect fRect; + private: + BBitmap *fOffscreen; + TOffscreenView *fOffscreenView; }; #endif Modified: haiku/trunk/src/apps/clock/cl_wind.cpp =================================================================== --- haiku/trunk/src/apps/clock/cl_wind.cpp 2007-10-02 14:09:11 UTC (rev 22410) +++ haiku/trunk/src/apps/clock/cl_wind.cpp 2007-10-02 14:54:15 UTC (rev 22411) @@ -1,15 +1,11 @@ /* - - cl_wind.cpp - -*/ + * Copyright 1999, Be Incorporated. All Rights Reserved. + * This file may be used under the terms of the Be Sample Code License. + */ -/* - Copyright 1999, Be Incorporated. All Rights Reserved. - This file may be used under the terms of the Be Sample Code License. -*/ - #include "cl_wind.h" + +#include #include #include #include @@ -19,37 +15,40 @@ #include -TClockWindow::TClockWindow(BRect r, const char* t) - :BWindow(r, t, B_TITLED_WINDOW, - B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AVOID_FRONT, - B_ALL_WORKSPACES) +#include "cl_view.h" + + +TClockWindow::TClockWindow(BRect frame, const char* title) + : BWindow(frame, title, B_TITLED_WINDOW, + B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AVOID_FRONT, B_ALL_WORKSPACES) { - SetPulseRate(500000); // half second pulse rate + SetPulseRate(500000); + // half second pulse rate } -bool TClockWindow::QuitRequested( void ) + +TClockWindow::~TClockWindow() { - int ref; - BPoint lefttop; - short face; - bool seconds; - BPath path; -// int len; +} - + +bool +TClockWindow::QuitRequested() +{ + BPath path; if (find_directory (B_USER_SETTINGS_DIRECTORY, &path, true) == B_OK) { path.Append("Clock_settings"); - ref = creat(path.Path(), 0777); + int ref = creat(path.Path(), 0777); if (ref >= 0) { - lefttop = Frame().LeftTop(); + BPoint lefttop = Frame().LeftTop(); write(ref, (char *)&lefttop, sizeof(BPoint)); - face = theOnscreenView->ReturnFace(); + short face = theOnscreenView->ReturnFace(); write(ref, (char *)&face, sizeof(short)); - seconds = theOnscreenView->ReturnSeconds(); + bool seconds = theOnscreenView->ReturnSeconds(); write(ref, (char *)&seconds, sizeof(bool)); close(ref); } } be_app->PostMessage(B_QUIT_REQUESTED); - return(TRUE); + return true; } Modified: haiku/trunk/src/apps/clock/cl_wind.h =================================================================== --- haiku/trunk/src/apps/clock/cl_wind.h 2007-10-02 14:09:11 UTC (rev 22410) +++ haiku/trunk/src/apps/clock/cl_wind.h 2007-10-02 14:54:15 UTC (rev 22411) @@ -1,26 +1,30 @@ /* - - cl_wind.h - -*/ + * Copyright 1999, Be Incorporated. All Rights Reserved. + * This file may be used under the terms of the Be Sample Code License. + * + */ +#ifndef _CLOCK_WINDOW_H +#define _CLOCK_WINDOW_H -/* - Copyright 1999, Be Incorporated. All Rights Reserved. - This file may be used under the terms of the Be Sample Code License. -*/ -#ifndef _WINDOW_H #include -#endif -#ifndef _CL_VIEW_H_ -#include "cl_view.h" -#endif + +class TOnscreenView; + + class TClockWindow : public BWindow { + public: + TClockWindow(BRect rect, const char* name); + virtual ~TClockWindow(); -public: - TClockWindow(BRect, const char*); -virtual bool QuitRequested( void ); + virtual bool QuitRequested(); -TOnscreenView *theOnscreenView; + private: + void _InitWindow(); + + private: + TOnscreenView *theOnscreenView; }; + +#endif // _CLOCK_WINDOW_H Modified: haiku/trunk/src/apps/clock/clock.cpp =================================================================== --- haiku/trunk/src/apps/clock/clock.cpp 2007-10-02 14:09:11 UTC (rev 22410) +++ haiku/trunk/src/apps/clock/clock.cpp 2007-10-02 14:54:15 UTC (rev 22411) @@ -1,114 +1,45 @@ /* - - Clock.cpp - - 13 apr 94 elr new today + * Copyright 1999, Be Incorporated. All Rights Reserved. + * This file may be used under the terms of the Be Sample Code License. + * + */ -*/ +#include "clock.h" +#include "cl_wind.h" -/* - Copyright 1999, Be Incorporated. All Rights Reserved. - This file may be used under the terms of the Be Sample Code License. -*/ -#include +const char *kAppSignature = "application/x-vnd.Haiku-Clock"; -#include "clock.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include +THelloApplication::THelloApplication() + :BApplication(kAppSignature) +{ + BRect windowRect(100, 100, 182, 182); + myWindow = new TClockWindow(windowRect, "Clock"); + myWindow->Show(); +} -int main(int argc, char* argv[]) -{ - THelloApplication *myApplication; - myApplication = new THelloApplication(); - myApplication->Run(); - - delete myApplication; - return 0; +THelloApplication::~THelloApplication() +{ } -const char *app_signature = "application/x-vnd.Haiku-Clock"; -THelloApplication::THelloApplication() - :BApplication(app_signature) +void +THelloApplication::MessageReceived(BMessage *msg) { - BRect windowRect, viewRect; - BPoint wind_loc; - int ref; - short face; - bool secs; - BPath path; + BApplication::MessageReceived(msg); +} - viewRect.Set(0, 0, 82, 82); - myView = new TOnscreenView(viewRect, "Clock",22,15,41); - windowRect.Set(100, 100, 182, 182); - myWindow = new TClockWindow(windowRect, "Clock"); - face = 1; - if (find_directory (B_USER_SETTINGS_DIRECTORY, &path) == B_OK) { - path.Append("Clock_settings"); - ref = open(path.Path(), O_RDONLY); - if (ref >= 0) { - read(ref, (char *)&wind_loc, sizeof(wind_loc)); - read(ref, (char *)&face, sizeof(short)); - read(ref, (char *)&secs, sizeof(bool)); - close(ref); - myWindow->MoveTo(wind_loc); - BRect frame = myWindow->Frame(); - frame.InsetBy(-4, -4); - if (!frame.Intersects(BScreen(myWindow).Frame())) { - // it's not visible so reposition. I'm not going to get - // fancy here, just place in the default location - myWindow->MoveTo(100, 100); - } - } - } +// #pragma mark - -//+ BPopUpMenu *menu = MainMenu(); -//+ BMenuItem *item = new BMenuItem("Show Seconds", new BMessage(SHOW_SECONDS)); -//+ item->SetTarget(this); -//+ item->SetMarked(secs); -//+ -//+ menu->AddItem(new BSeparatorItem(), 1); -//+ menu->AddItem(item, 2); -//+ menu->AddItem(new BSeparatorItem(), 3); - myWindow->Lock(); - myWindow->AddChild(myView); - myWindow->theOnscreenView = myView; +int +main(int argc, char* argv[]) +{ + THelloApplication app; + app.Run(); -//+ BRect r = myView->Frame(); -//+ r.top = r.bottom - 7; -//+ r.left = r.right - 7; -//+ BDragger *dw = new BDragger(r, myView, 0); -//+ myWindow->AddChild(dw); - - myView->UseFace( face ); - myView->ShowSecs( secs ); - myView->Pulse(); // Force update - myWindow->Show(); - myWindow->Unlock(); + return 0; } - -void THelloApplication::MessageReceived(BMessage *msg) -{ - if (msg->what == SHOW_SECONDS) { -//+ if (myWindow->Lock()) { -//+ BMenuItem *item = MainMenu()->FindItem(SHOW_SECONDS); -//+ item->SetMarked(!item->IsMarked()); -//+//+ myView->ShowSecs(item->IsMarked()); -//+ myWindow->Unlock(); -//+ } - } else { - BApplication::MessageReceived(msg); - } -} Modified: haiku/trunk/src/apps/clock/clock.h =================================================================== --- haiku/trunk/src/apps/clock/clock.h 2007-10-02 14:09:11 UTC (rev 22410) +++ haiku/trunk/src/apps/clock/clock.h 2007-10-02 14:54:15 UTC (rev 22411) @@ -1,32 +1,31 @@ /* - - clock.h - -*/ + * Copyright 1999, Be Incorporated. All Rights Reserved. + * This file may be used under the terms of the Be Sample Code License. + * + */ +#ifndef _CLOCK_APPLICATION_H +#define _CLOCK_APPLICATION_H -/* - Copyright 1999, Be Incorporated. All Rights Reserved. - This file may be used under the terms of the Be Sample Code License. -*/ -#ifndef _APPLICATION_H #include -#endif -#include "cl_view.h" -#include "cl_wind.h" -#define SHOW_SECONDS 'ssec' +class TClockWindow; -extern const char *app_signature; class THelloApplication : public BApplication { - -public: + public: THelloApplication(); -virtual void MessageReceived(BMessage *msg); + virtual ~THelloApplication(); -private: - TClockWindow* myWindow; - TOnscreenView *myView; + virtual void MessageReceived(BMessage *msg); + + private: + TClockWindow *myWindow; }; + + +extern const char *kAppSignature; + + +#endif // _CLOCK_APPLICATION_H From axeld at mail.berlios.de Tue Oct 2 17:22:14 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 2 Oct 2007 17:22:14 +0200 Subject: [Haiku-commits] r22412 - in haiku/trunk: build/jam src/system/boot src/system/runtime_loader Message-ID: <200710021522.l92FMEGe012896@sheep.berlios.de> Author: axeld Date: 2007-10-02 17:22:13 +0200 (Tue, 02 Oct 2007) New Revision: 22412 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22412&view=rev Added: haiku/trunk/src/system/boot/boot_loader.rdef haiku/trunk/src/system/runtime_loader/runtime_loader.rdef Modified: haiku/trunk/build/jam/BeOSRules haiku/trunk/build/jam/HaikuImage haiku/trunk/build/jam/MainBuildRules haiku/trunk/src/system/boot/Jamfile haiku/trunk/src/system/runtime_loader/Jamfile Log: * Changed Ld rule to allow adding resource files. * Changed ResAttr rule to allow not deleting the file before writing the attributes. * Added application signatures for the runtime_loader and zbeos, just so that they may have an icon, too (hint, hint) :-) * As a side effect, this also let's FileTypes handle these two as apps (even though they aren't), so that I can close bug #606. Modified: haiku/trunk/build/jam/BeOSRules =================================================================== --- haiku/trunk/build/jam/BeOSRules 2007-10-02 14:54:15 UTC (rev 22411) +++ haiku/trunk/build/jam/BeOSRules 2007-10-02 15:22:13 UTC (rev 22412) @@ -224,16 +224,21 @@ cat "$(2[2-])" | $(CC) -E $(CCDEFS) $(HDRS) - | egrep -v '^#' | $(2[1]) $(RCHDRS) --auto-names -o "$(1)" - } -rule ResAttr attributeFile : _resourceFiles +rule ResAttr attributeFile : _resourceFiles : deleteAttributeFile { - # ResAttr : ; + # ResAttr : [ : ] ; # # and must be gristed. # can also be .rdef files -- they will be compiled first in # this case. + # is a boolean that specifies wether or not the target file + # should be removed before writing. Defaults to true. local resourceFiles ; local resourceFile ; + deleteAttributeFile ?= true ; + deleteAttributeFile1 on $(1) = $(deleteAttributeFile) ; + for resourceFile in $(_resourceFiles) { # if the specified resource file is an .rdef file, we compile it first if $(resourceFile:S) = ".rdef" { @@ -256,6 +261,8 @@ actions ResAttr1 { $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) - rm -f $(1) - $(2[1]) -o "$(1)" "$(2[2-])" + if [ \\"$(deleteAttributeFile1)\\" = "true" ]; then + rm -f $(1) + fi + $(2[1]) -O -o "$(1)" "$(2[2-])" } Modified: haiku/trunk/build/jam/HaikuImage =================================================================== --- haiku/trunk/build/jam/HaikuImage 2007-10-02 14:54:15 UTC (rev 22411) +++ haiku/trunk/build/jam/HaikuImage 2007-10-02 15:22:13 UTC (rev 22412) @@ -270,7 +270,6 @@ spellFiles = $(spellFiles:G=spell) ; SEARCH on $(spellFiles) = [ FDirName $(HAIKU_TOP) src apps mail ] ; -#AddDirectoryToHaikuImage beos etc word_dictionary ; AddFilesToHaikuImage beos etc word_dictionary : $(spellFiles) ; local svgFiles = "lion.svg" ; Modified: haiku/trunk/build/jam/MainBuildRules =================================================================== --- haiku/trunk/build/jam/MainBuildRules 2007-10-02 14:54:15 UTC (rev 22411) +++ haiku/trunk/build/jam/MainBuildRules 2007-10-02 15:22:13 UTC (rev 22412) @@ -198,6 +198,13 @@ Depends $(target) : $(objects) ; MakeLocateDebug $(target) ; + + on $(1) XRes $(1) : $(RESFILES) ; + if ! [ on $(1) return $(DONT_USE_BEOS_RULES) ] { + SetType $(1) ; + MimeSet $(1) ; + SetVersion $(1) ; + } } actions Ld Modified: haiku/trunk/src/system/boot/Jamfile =================================================================== --- haiku/trunk/src/system/boot/Jamfile 2007-10-02 14:54:15 UTC (rev 22411) +++ haiku/trunk/src/system/boot/Jamfile 2007-10-02 15:22:13 UTC (rev 22412) @@ -30,6 +30,8 @@ platformObjects += cpuid.o ; } +AddResources zbeos : boot_loader.rdef ; + KernelLd boot_loader_$(TARGET_BOOT_PLATFORM) : boot_platform_$(TARGET_BOOT_PLATFORM).o boot_arch_$(TARGET_ARCH).o @@ -61,6 +63,12 @@ Depends $(zbeos) : $(bootLoader) ; MakeLocateDebug $(zbeos) ; + + on $(1) ResAttr $(1) : $(RESFILES) : false ; + if ! [ on $(1) return $(DONT_USE_BEOS_RULES) ] { + SetType $(1) ; + MimeSet $(1) ; + } } actions BuildZbeos { Added: haiku/trunk/src/system/boot/boot_loader.rdef =================================================================== --- haiku/trunk/src/system/boot/boot_loader.rdef 2007-10-02 14:54:15 UTC (rev 22411) +++ haiku/trunk/src/system/boot/boot_loader.rdef 2007-10-02 15:22:13 UTC (rev 22412) @@ -0,0 +1,13 @@ +resource app_signature "application/x-vnd.Haiku-BootLoader"; + +resource app_version { + major = 1, + middle = 0, + minor = 0, + + variety = B_APPV_DEVELOPMENT, + internal = 0, + + short_info = "Boot Loader", + long_info = "Boot Loader ?2002-2007 Haiku Inc." +}; Modified: haiku/trunk/src/system/runtime_loader/Jamfile =================================================================== --- haiku/trunk/src/system/runtime_loader/Jamfile 2007-10-02 14:54:15 UTC (rev 22411) +++ haiku/trunk/src/system/runtime_loader/Jamfile 2007-10-02 15:22:13 UTC (rev 22412) @@ -14,6 +14,8 @@ _LOADER_MODE ; +AddResources runtime_loader : runtime_loader.rdef ; + # needed for "runtime_loader" only StaticLibrary libruntime_loader.a : kernel_vsprintf.c Added: haiku/trunk/src/system/runtime_loader/runtime_loader.rdef =================================================================== --- haiku/trunk/src/system/runtime_loader/runtime_loader.rdef 2007-10-02 14:54:15 UTC (rev 22411) +++ haiku/trunk/src/system/runtime_loader/runtime_loader.rdef 2007-10-02 15:22:13 UTC (rev 22412) @@ -0,0 +1,13 @@ +resource app_signature "application/x-vnd.Haiku-RuntimeLoader"; + +resource app_version { + major = 1, + middle = 0, + minor = 0, + + variety = B_APPV_DEVELOPMENT, + internal = 0, + + short_info = "Runtime Loader", + long_info = "Runtime Loader ?2002-2007 Haiku Inc." +}; From axeld at mail.berlios.de Tue Oct 2 18:06:17 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 2 Oct 2007 18:06:17 +0200 Subject: [Haiku-commits] r22413 - haiku/trunk/src/system/kernel/vm Message-ID: <200710021606.l92G6HqV018322@sheep.berlios.de> Author: axeld Date: 2007-10-02 18:06:17 +0200 (Tue, 02 Oct 2007) New Revision: 22413 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22413&view=rev Modified: haiku/trunk/src/system/kernel/vm/vm_page.cpp Log: Added a TODO what we need to do with stolen active pages - for now, we don't do anything with them, though. Modified: haiku/trunk/src/system/kernel/vm/vm_page.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_page.cpp 2007-10-02 15:22:13 UTC (rev 22412) +++ haiku/trunk/src/system/kernel/vm/vm_page.cpp 2007-10-02 16:06:17 UTC (rev 22413) @@ -851,6 +851,10 @@ continue; } if (page->state != PAGE_STATE_INACTIVE) { + // TODO: if this is an active page (as in stealActive), we need + // to unmap it and check if it's modified in an atomic operation. + // For now, we'll just ignore it, even though this might let + // vm_page_allocate_page() wait forever... mutex_unlock(&cache->lock); vm_cache_release_ref(cache); continue; From stippi at mail.berlios.de Tue Oct 2 18:54:34 2007 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Tue, 2 Oct 2007 18:54:34 +0200 Subject: [Haiku-commits] r22414 - in haiku/trunk/src: kits/storage libs/icon Message-ID: <200710021654.l92GsYR9028919@sheep.berlios.de> Author: stippi Date: 2007-10-02 18:54:34 +0200 (Tue, 02 Oct 2007) New Revision: 22414 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22414&view=rev Modified: haiku/trunk/src/kits/storage/AppFileInfo.cpp haiku/trunk/src/libs/icon/IconUtils.cpp Log: * when a vector icon was present, BAppFileInfo::GetIcon() would return an error if the provided bitmap was B_CMAP8, now BIconUtils will convert the icon to B_CMAP8 -> this behaviour is a little inconsistent compared to what happens when reading icons from attributes, there, the CMAP8 icon is prefered in case such a bitmap is passed, even if a vector icon exists. I am not really sure which behaviour is better. For a consistent UI, maybe it is better to prefer the vector icon always. I've added a note to BAppFileInfo. Modified: haiku/trunk/src/kits/storage/AppFileInfo.cpp =================================================================== --- haiku/trunk/src/kits/storage/AppFileInfo.cpp 2007-10-02 16:06:17 UTC (rev 22413) +++ haiku/trunk/src/kits/storage/AppFileInfo.cpp 2007-10-02 16:54:34 UTC (rev 22414) @@ -831,6 +831,13 @@ if (!icon || icon->InitCheck() != B_OK) return B_BAD_VALUE; + // TODO: for consistency with attribute based icon reading, we + // could also prefer B_CMAP8 icons here if the provided bitmap + // is in that format. Right now, an existing B_CMAP8 icon resource + // would be ignored as soon as a vector icon is present. On the other + // hand, maybe this still results in a more consistent user interface, + // since Tracker/Deskbar would surely show the vector icon. + // try vector icon first BString vectorAttributeName(kIconAttribute); Modified: haiku/trunk/src/libs/icon/IconUtils.cpp =================================================================== --- haiku/trunk/src/libs/icon/IconUtils.cpp 2007-10-02 16:06:17 UTC (rev 22413) +++ haiku/trunk/src/libs/icon/IconUtils.cpp 2007-10-02 16:54:34 UTC (rev 22414) @@ -19,6 +19,7 @@ #include #include +#include "AutoDeleter.h" #include "Icon.h" #include "IconRenderer.h" #include "FlatIconImporter.h" @@ -165,9 +166,17 @@ if (ret < B_OK) return ret; - if (result->ColorSpace() != B_RGBA32 && result->ColorSpace() != B_RGB32) - return B_BAD_VALUE; + BBitmap* temp = result; + ObjectDeleter deleter; + if (result->ColorSpace() != B_RGBA32 && result->ColorSpace() != B_RGB32) { + temp = new (nothrow) BBitmap(result->Bounds(), + B_BITMAP_NO_SERVER_LINK, B_RGBA32); + deleter.SetTo(temp); + if (!temp || temp->InitCheck() != B_OK) + return B_NO_MEMORY; + } + Icon icon; ret = icon.InitCheck(); if (ret < B_OK) @@ -178,11 +187,19 @@ if (ret < B_OK) return ret; - IconRenderer renderer(result); + IconRenderer renderer(temp); renderer.SetIcon(&icon); - renderer.SetScale((result->Bounds().Width() + 1.0) / 64.0); + renderer.SetScale((temp->Bounds().Width() + 1.0) / 64.0); renderer.Render(); + if (temp != result) { + uint8* src = (uint8*)temp->Bits(); + uint32 width = temp->Bounds().IntegerWidth() + 1; + uint32 height = temp->Bounds().IntegerHeight() + 1; + uint32 srcBPR = temp->BytesPerRow(); + ret = ConvertToCMAP8(src, width, height, srcBPR, result); + } + // TODO: would be nice to get rid of this // (B_RGBA32_PREMULTIPLIED or better yet, new blending_mode) // NOTE: probably not necessary only because @@ -191,7 +208,7 @@ // app_server uses correct blending // renderer.Demultiply(); - return B_OK; + return ret; } // #pragma mark - @@ -465,6 +482,9 @@ if (ret < B_OK) return ret; + if (result->ColorSpace() != B_CMAP8) + return B_BAD_VALUE; + uint32 dstWidth = result->Bounds().IntegerWidth() + 1; uint32 dstHeight = result->Bounds().IntegerHeight() + 1; @@ -483,13 +503,12 @@ // //#else - if (result->ColorSpace() != B_CMAP8) - return B_BAD_VALUE; - uint8* dst = (uint8*)result->Bits(); uint32 dstBPR = result->BytesPerRow(); const color_map* colorMap = system_colors(); + if (!colorMap) + return B_NO_INIT; uint16 index; for (uint32 y = 0; y < height; y++) { From axeld at mail.berlios.de Tue Oct 2 19:40:06 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 2 Oct 2007 19:40:06 +0200 Subject: [Haiku-commits] r22415 - haiku/trunk/src/add-ons/accelerants/intel_extreme Message-ID: <200710021740.l92He6lB010048@sheep.berlios.de> Author: axeld Date: 2007-10-02 19:40:05 +0200 (Tue, 02 Oct 2007) New Revision: 22415 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22415&view=rev Modified: haiku/trunk/src/add-ons/accelerants/intel_extreme/mode.cpp Log: Fixed PLL clock for i8xx chips again. Modified: haiku/trunk/src/add-ons/accelerants/intel_extreme/mode.cpp =================================================================== --- haiku/trunk/src/add-ons/accelerants/intel_extreme/mode.cpp 2007-10-02 16:54:34 UTC (rev 22414) +++ haiku/trunk/src/add-ons/accelerants/intel_extreme/mode.cpp 2007-10-02 17:40:05 UTC (rev 22415) @@ -529,7 +529,7 @@ if ((gInfo->shared_info->device_type & INTEL_TYPE_GROUP_MASK) == INTEL_TYPE_965) pll |= 6 << DISPLAY_PLL_PULSE_PHASE_SHIFT; } else { - if (divisors.post2_high) + if (!divisors.post2_high) pll |= DISPLAY_PLL_DIVIDE_4X; pll |= DISPLAY_PLL_2X_CLOCK; From bonefish at mail.berlios.de Tue Oct 2 21:47:35 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Tue, 2 Oct 2007 21:47:35 +0200 Subject: [Haiku-commits] r22416 - in haiku/trunk: headers/os/drivers headers/os/kernel headers/private/kernel headers/private/kernel/fs headers/private/userlandfs/private src/add-ons/kernel/drivers/random src/add-ons/kernel/drivers/tty src/add-ons/kernel/file_systems/userlandfs/kernel_add_on src/add-ons/kernel/file_systems/userlandfs/server src/add-ons/kernel/network/stack src/system/kernel src/system/kernel/fs src/system/libroot/os Message-ID: <200710021947.l92JlZWh016478@sheep.berlios.de> Author: bonefish Date: 2007-10-02 21:47:31 +0200 (Tue, 02 Oct 2007) New Revision: 22416 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22416&view=rev Added: haiku/trunk/headers/private/kernel/wait_for_objects.h haiku/trunk/src/system/kernel/wait_for_objects.cpp haiku/trunk/src/system/libroot/os/wait_for_objects.cpp Removed: haiku/trunk/src/system/kernel/fs/vfs_select.cpp haiku/trunk/src/system/kernel/fs/vfs_select.h Modified: haiku/trunk/headers/os/drivers/Select.h haiku/trunk/headers/os/kernel/OS.h haiku/trunk/headers/private/kernel/fs/fd.h haiku/trunk/headers/private/kernel/fs/select_sync_pool.h haiku/trunk/headers/private/kernel/port.h haiku/trunk/headers/private/kernel/sem.h haiku/trunk/headers/private/kernel/syscalls.h haiku/trunk/headers/private/kernel/thread.h haiku/trunk/headers/private/kernel/thread_types.h haiku/trunk/headers/private/userlandfs/private/Requests.h haiku/trunk/src/add-ons/kernel/drivers/random/driver.c haiku/trunk/src/add-ons/kernel/drivers/tty/tty.cpp haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/kernel_add_on/KernelRequestHandler.cpp haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/kernel_add_on/Volume.cpp haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/BeOSKernelVolume.cpp haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/HaikuKernelVolume.cpp haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/UserlandRequestHandler.cpp haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/beos_kernel_emu.cpp haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/haiku_kernel_emu.cpp haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/kernel_emu.cpp haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/kernel_emu.h haiku/trunk/src/add-ons/kernel/network/stack/net_socket.cpp haiku/trunk/src/system/kernel/Jamfile haiku/trunk/src/system/kernel/fs/Jamfile haiku/trunk/src/system/kernel/fs/devfs.cpp haiku/trunk/src/system/kernel/fs/fd.cpp haiku/trunk/src/system/kernel/fs/pipefs.cpp haiku/trunk/src/system/kernel/fs/vfs.cpp haiku/trunk/src/system/kernel/port.c haiku/trunk/src/system/kernel/sem.c haiku/trunk/src/system/kernel/syscalls.c haiku/trunk/src/system/kernel/thread.cpp haiku/trunk/src/system/libroot/os/Jamfile Log: * Renamed fs/vfs_select.cpp to wait_for_objects.cpp and got rid of vfs_select.h, respectively moved most of it into the new kernel private header wait_for_objects.h. * Added new experimental API functions wait_for_objects[_etc](). They work pretty much like poll(), but also for semaphores, ports, and threads. * Removed the "ref" parameter from notify_select_events() and the select_sync_pool functions as well as from fd_ops::fd_[de]select(). It is no longer needed. The FS interface select() hook still has it, though -- the VFS will always pass 0. * de]select_fd() take a select_info* instead of a select_sync* + ref pair, now. Added respective functions for semaphores, ports, and threads. Modified: haiku/trunk/headers/os/drivers/Select.h =================================================================== --- haiku/trunk/headers/os/drivers/Select.h 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/headers/os/drivers/Select.h 2007-10-02 19:47:31 UTC (rev 22416) @@ -31,11 +31,7 @@ extern "C" { #endif -#ifdef COMPILE_FOR_R5 -extern void notify_select_event(struct selectsync *sync, uint32 ref); -#else -extern status_t notify_select_event(struct selectsync *sync, uint32 ref, uint8 event); -#endif +extern status_t notify_select_event(struct selectsync *sync, uint8 event); #ifdef __cplusplus } Modified: haiku/trunk/headers/os/kernel/OS.h =================================================================== --- haiku/trunk/headers/os/kernel/OS.h 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/headers/os/kernel/OS.h 2007-10-02 19:47:31 UTC (rev 22416) @@ -658,6 +658,52 @@ extern int32 is_computer_on(void); extern double is_computer_on_fire(void); + +// WARNING: Experimental API! + +enum { + B_OBJECT_TYPE_FD = 0, + B_OBJECT_TYPE_SEMAPHORE = 1, + B_OBJECT_TYPE_PORT = 2, + B_OBJECT_TYPE_THREAD = 3 +}; + +enum { + B_EVENT_READ = 0x0001, // FD/port readable + B_EVENT_WRITE = 0x0002, // FD/port writable + B_EVENT_ERROR = 0x0004, // FD error + B_EVENT_PRIORITY_READ = 0x0008, // FD priority readable + B_EVENT_PRIORITY_WRITE = 0x0010, // FD priority writable + B_EVENT_HIGH_PRIORITY_READ = 0x0020, // FD high priority readable + B_EVENT_HIGH_PRIORITY_WRITE = 0x0040, // FD high priority writable + B_EVENT_DISCONNECTED = 0x0080, // FD disconnected + + B_EVENT_ACQUIRE_SEMAPHORE = 0x0001, // semaphore can be acquired + + B_EVENT_INVALID = 0x1000 // FD/port/sem/thread ID not or + // no longer valid (e.g. has been + // close/deleted) +}; + +typedef struct object_wait_info { + int32 object; // ID of the object + uint16 type; // type of the object + uint16 events; // events mask +} object_wait_info; + +// wait_for_objects[_etc]() waits until at least one of the specified events or, +// if given, the timeout occurred. When entering the function the +// object_wait_info::events field specifies the events for each object the +// caller is interested in. When the function returns the fields reflect the +// events that actually occurred. The events B_EVENT_INVALID, B_EVENT_ERROR, +// and B_EVENT_DISCONNECTED don't need to be specified. They will always be +// reported, when they occur. + +extern ssize_t wait_for_objects(object_wait_info* infos, int numInfos); +extern ssize_t wait_for_objects_etc(object_wait_info* infos, int numInfos, + uint32 flags, bigtime_t timeout); + + #ifdef __cplusplus } #endif Modified: haiku/trunk/headers/private/kernel/fs/fd.h =================================================================== --- haiku/trunk/headers/private/kernel/fs/fd.h 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/headers/private/kernel/fs/fd.h 2007-10-02 19:47:31 UTC (rev 22416) @@ -17,14 +17,14 @@ struct file_descriptor; struct selectsync; -struct select_sync; +struct select_info; struct fd_ops { status_t (*fd_read)(struct file_descriptor *, off_t pos, void *buffer, size_t *length); status_t (*fd_write)(struct file_descriptor *, off_t pos, const void *buffer, size_t *length); off_t (*fd_seek)(struct file_descriptor *, off_t pos, int seekType); status_t (*fd_ioctl)(struct file_descriptor *, ulong op, void *buffer, size_t length); - status_t (*fd_select)(struct file_descriptor *, uint8 event, uint32 ref, + status_t (*fd_select)(struct file_descriptor *, uint8 event, struct selectsync *sync); status_t (*fd_deselect)(struct file_descriptor *, uint8 event, struct selectsync *sync); @@ -77,10 +77,8 @@ extern void put_fd(struct file_descriptor *descriptor); extern void disconnect_fd(struct file_descriptor *descriptor); extern void inc_fd_ref_count(struct file_descriptor *descriptor); -extern status_t select_fd(int fd, struct select_sync *sync, uint32 ref, - bool kernel); -extern status_t deselect_fd(int fd, struct select_sync *sync, uint32 ref, - bool kernel); +extern status_t select_fd(int32 fd, struct select_info *info, bool kernel); +extern status_t deselect_fd(int32 fd, struct select_info *info, bool kernel); extern bool fd_is_valid(int fd, bool kernel); extern struct vnode *fd_vnode(struct file_descriptor *descriptor); Modified: haiku/trunk/headers/private/kernel/fs/select_sync_pool.h =================================================================== --- haiku/trunk/headers/private/kernel/fs/select_sync_pool.h 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/headers/private/kernel/fs/select_sync_pool.h 2007-10-02 19:47:31 UTC (rev 22416) @@ -17,7 +17,7 @@ status_t add_select_sync_pool_entry(select_sync_pool **pool, selectsync *sync, - uint32 ref, uint8 event); + uint8 event); status_t remove_select_sync_pool_entry(select_sync_pool **pool, selectsync *sync, uint8 event); void delete_select_sync_pool(select_sync_pool *pool); Modified: haiku/trunk/headers/private/kernel/port.h =================================================================== --- haiku/trunk/headers/private/kernel/port.h 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/headers/private/kernel/port.h 2007-10-02 19:47:31 UTC (rev 22416) @@ -10,6 +10,7 @@ #include struct kernel_args; +struct select_info; #define PORT_FLAG_USE_USER_MEMCPY 0x80000000 @@ -23,6 +24,9 @@ int32 port_max_ports(void); int32 port_used_ports(void); +status_t select_port(int32 object, struct select_info *info, bool kernel); +status_t deselect_port(int32 object, struct select_info *info, bool kernel); + // currently private API status_t writev_port_etc(port_id id, int32 msgCode, const iovec *msgVecs, size_t vecCount, size_t bufferSize, uint32 flags, bigtime_t timeout); Modified: haiku/trunk/headers/private/kernel/sem.h =================================================================== --- haiku/trunk/headers/private/kernel/sem.h 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/headers/private/kernel/sem.h 2007-10-02 19:47:31 UTC (rev 22416) @@ -13,6 +13,7 @@ #include struct kernel_args; +struct select_info; #ifdef __cplusplus @@ -25,6 +26,10 @@ extern int32 sem_used_sems(void); extern int32 sem_max_sems(void); +extern status_t select_sem(int32 object, struct select_info *info, bool kernel); +extern status_t deselect_sem(int32 object, struct select_info *info, + bool kernel); + extern sem_id create_sem_etc(int32 count, const char *name, team_id owner); /* user calls */ Modified: haiku/trunk/headers/private/kernel/syscalls.h =================================================================== --- haiku/trunk/headers/private/kernel/syscalls.h 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/headers/private/kernel/syscalls.h 2007-10-02 19:47:31 UTC (rev 22416) @@ -53,6 +53,10 @@ extern status_t _kern_shutdown(bool reboot); extern status_t _kern_get_safemode_option(const char *parameter, char *buffer, size_t *_bufferSize); +extern ssize_t _kern_wait_for_objects(object_wait_info* infos, int numInfos, + uint32 flags, bigtime_t timeout); + + /* sem functions */ extern sem_id _kern_create_sem(int count, const char *name); extern status_t _kern_delete_sem(sem_id id); Modified: haiku/trunk/headers/private/kernel/thread.h =================================================================== --- haiku/trunk/headers/private/kernel/thread.h 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/headers/private/kernel/thread.h 2007-10-02 19:47:31 UTC (rev 22416) @@ -14,6 +14,7 @@ #include struct kernel_args; +struct select_info; #ifdef __cplusplus @@ -65,6 +66,9 @@ status_t wait_for_thread_etc(thread_id id, uint32 flags, bigtime_t timeout, status_t *_returnCode); +status_t select_thread(int32 object, struct select_info *info, bool kernel); +status_t deselect_thread(int32 object, struct select_info *info, bool kernel); + // used in syscalls.c status_t _user_set_thread_priority(thread_id thread, int32 newPriority); status_t _user_rename_thread(thread_id thread, const char *name); Modified: haiku/trunk/headers/private/kernel/thread_types.h =================================================================== --- haiku/trunk/headers/private/kernel/thread_types.h 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/headers/private/kernel/thread_types.h 2007-10-02 19:47:31 UTC (rev 22416) @@ -54,6 +54,7 @@ struct image; // defined in image.c +struct select_info; struct death_entry { struct list_link link; @@ -234,6 +235,8 @@ struct list waiters; } exit; + struct select_info *select_infos; + struct thread_debug_info debug_info; // stack Added: haiku/trunk/headers/private/kernel/wait_for_objects.h =================================================================== --- haiku/trunk/headers/private/kernel/wait_for_objects.h 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/headers/private/kernel/wait_for_objects.h 2007-10-02 19:47:31 UTC (rev 22416) @@ -0,0 +1,52 @@ +/* + * Copyright 2007, Ingo Weinhold, bonefish at cs.tu-berlin.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ + +#ifndef _KERNEL_WAIT_FOR_OBJECTS_H +#define _KERNEL_WAIT_FOR_OBJECTS_H + +#include + +#include + + +struct select_sync; + + +typedef struct select_info { + struct select_info* next; // next in the object's list + struct select_sync* sync; + uint16 selected_events; + uint16 events; +} select_info; + +typedef struct select_sync { + vint32 ref_count; + benaphore lock; + sem_id sem; + uint32 count; + struct select_info* set; +} select_sync; + +#define SELECT_FLAG(type) (1L << (type - 1)) + + +#ifdef __cplusplus +extern "C" { +#endif + + +extern void put_select_sync(select_sync* sync); +extern status_t notify_select_events(select_info* info, uint16 events); +extern void notify_select_events_list(select_info* list, uint16 events); + +extern ssize_t _user_wait_for_objects(object_wait_info* userInfos, + int numInfos, uint32 flags, bigtime_t timeout); + + +#ifdef __cplusplus +} +#endif + +#endif // _KERNEL_WAIT_FOR_OBJECTS_H Modified: haiku/trunk/headers/private/userlandfs/private/Requests.h =================================================================== --- haiku/trunk/headers/private/userlandfs/private/Requests.h 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/headers/private/userlandfs/private/Requests.h 2007-10-02 19:47:31 UTC (rev 22416) @@ -547,7 +547,6 @@ SelectRequest() : FileRequest(SELECT_REQUEST) {} uint8 event; - uint32 ref; selectsync* sync; }; @@ -1394,7 +1393,6 @@ NotifySelectEventRequest() : Request(NOTIFY_SELECT_EVENT_REQUEST) {} selectsync* sync; - uint32 ref; uint8 event; bool unspecifiedEvent; }; Modified: haiku/trunk/src/add-ons/kernel/drivers/random/driver.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/random/driver.c 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/src/add-ons/kernel/drivers/random/driver.c 2007-10-02 19:47:31 UTC (rev 22416) @@ -466,7 +466,7 @@ #ifdef COMPILE_FOR_R5 notify_select_event(sync, ref); #else - notify_select_event(sync, ref, event); + notify_select_event(sync, event); #endif } else if (event == B_SELECT_WRITE) { /* we're not writable */ Modified: haiku/trunk/src/add-ons/kernel/drivers/tty/tty.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/tty/tty.cpp 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/src/add-ons/kernel/drivers/tty/tty.cpp 2007-10-02 19:47:31 UTC (rev 22416) @@ -1676,7 +1676,7 @@ if (!ttyReference.IsLocked()) { TRACE(("tty_select() done: cookie %p already closed\n", cookie)); - notify_select_event(sync, ref, event); + notify_select_event(sync, event); return B_OK; } @@ -1690,8 +1690,7 @@ otherTTY = NULL; // add the event to the TTY's pool - status_t error = add_select_sync_pool_entry(&tty->select_pool, sync, ref, - event); + status_t error = add_select_sync_pool_entry(&tty->select_pool, sync, event); if (error != B_OK) { TRACE(("tty_select() done: add_select_sync_pool_entry() failed: %lx\n", error)); @@ -1708,7 +1707,7 @@ case B_SELECT_READ: if (tty->reader_queue.IsEmpty() && line_buffer_readable(tty->input_buffer) > 0) { - notify_select_event(sync, ref, event); + notify_select_event(sync, event); } break; @@ -1716,7 +1715,7 @@ { // writes go to the other TTY if (!otherTTY) { - notify_select_event(sync, ref, event); + notify_select_event(sync, event); break; } @@ -1730,7 +1729,7 @@ if (!echo || (tty->writer_queue.IsEmpty() && line_buffer_writable(tty->input_buffer) > 0)) { - notify_select_event(sync, ref, event); + notify_select_event(sync, event); } } Modified: haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/kernel_add_on/KernelRequestHandler.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/kernel_add_on/KernelRequestHandler.cpp 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/kernel_add_on/KernelRequestHandler.cpp 2007-10-02 19:47:31 UTC (rev 22416) @@ -211,13 +211,13 @@ if (request->unspecifiedEvent) { // old style add-ons can't provide an event argument; we shoot // all events - notify_select_event(request->sync, request->ref, B_SELECT_READ); - notify_select_event(request->sync, request->ref, B_SELECT_WRITE); - notify_select_event(request->sync, request->ref, B_SELECT_ERROR); + notify_select_event(request->sync, B_SELECT_READ); + notify_select_event(request->sync, B_SELECT_WRITE); + notify_select_event(request->sync, B_SELECT_ERROR); } else { - PRINT(("notify_select_event(%p, %lu, %d)\n", request->sync, - request->ref, (int)request->event)); - notify_select_event(request->sync, request->ref, request->event); + PRINT(("notify_select_event(%p, %d)\n", request->sync, + (int)request->event)); + notify_select_event(request->sync, request->event); } } else result = B_BAD_VALUE; Modified: haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/kernel_add_on/Volume.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/kernel_add_on/Volume.cpp 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/kernel_add_on/Volume.cpp 2007-10-02 19:47:31 UTC (rev 22416) @@ -736,7 +736,7 @@ { // check capability if (!fFileSystem->HasCapability(FS_CAPABILITY_SELECT)) { - notify_select_event(sync, ref, event); + notify_select_event(sync, event); return B_OK; } @@ -757,7 +757,6 @@ request->node = node; request->fileCookie = cookie; request->event = event; - request->ref = ref; request->sync = sync; // add a selectsync entry Modified: haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/BeOSKernelVolume.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/BeOSKernelVolume.cpp 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/BeOSKernelVolume.cpp 2007-10-02 19:47:31 UTC (rev 22416) @@ -224,7 +224,7 @@ uint32 ref, selectsync* sync) { if (!fFSOps->select) { - UserlandFS::KernelEmu::notify_select_event(sync, ref, event, false); + UserlandFS::KernelEmu::notify_select_event(sync, event, false); return B_OK; } return fFSOps->select(fVolumeCookie, node, cookie, event, ref, sync); Modified: haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/HaikuKernelVolume.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/HaikuKernelVolume.cpp 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/HaikuKernelVolume.cpp 2007-10-02 19:47:31 UTC (rev 22416) @@ -194,7 +194,7 @@ uint32 ref, selectsync* sync) { if (!fFSModule->select) { - UserlandFS::KernelEmu::notify_select_event(sync, ref, event, false); + UserlandFS::KernelEmu::notify_select_event(sync, event, false); return B_OK; } return fFSModule->select(fVolumeCookie, node, cookie, event, ref, sync); Modified: haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/UserlandRequestHandler.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/UserlandRequestHandler.cpp 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/UserlandRequestHandler.cpp 2007-10-02 19:47:31 UTC (rev 22416) @@ -627,7 +627,7 @@ if (result == B_OK) { RequestThreadContext context(volume); result = volume->Select(request->node, request->fileCookie, - request->event, request->ref, request->sync); + request->event, 0, request->sync); } // prepare the reply Modified: haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/beos_kernel_emu.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/beos_kernel_emu.cpp 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/beos_kernel_emu.cpp 2007-10-02 19:47:31 UTC (rev 22416) @@ -82,7 +82,7 @@ void notify_select_event(selectsync *sync, uint32 ref) { - UserlandFS::KernelEmu::notify_select_event(sync, ref, 0, true); + UserlandFS::KernelEmu::notify_select_event(sync, 0, true); } // send_notification Modified: haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/haiku_kernel_emu.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/haiku_kernel_emu.cpp 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/haiku_kernel_emu.cpp 2007-10-02 19:47:31 UTC (rev 22416) @@ -76,9 +76,9 @@ // notify_select_event status_t -notify_select_event(selectsync *sync, uint32 ref, uint8 event) +notify_select_event(selectsync *sync, uint8 event) { - return UserlandFS::KernelEmu::notify_select_event(sync, ref, event, false); + return UserlandFS::KernelEmu::notify_select_event(sync, event, false); } // notify_query_entry_created Modified: haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/kernel_emu.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/kernel_emu.cpp 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/kernel_emu.cpp 2007-10-02 19:47:31 UTC (rev 22416) @@ -170,8 +170,8 @@ // notify_select_event status_t -UserlandFS::KernelEmu::notify_select_event(selectsync *sync, uint32 ref, - uint8 event, bool unspecifiedEvent) +UserlandFS::KernelEmu::notify_select_event(selectsync *sync, uint8 event, + bool unspecifiedEvent) { // get the request port and the file system RequestPort* port; @@ -188,7 +188,6 @@ return error; request->sync = sync; - request->ref = ref; request->event = event; request->unspecifiedEvent = unspecifiedEvent; Modified: haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/kernel_emu.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/kernel_emu.h 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/src/add-ons/kernel/file_systems/userlandfs/server/kernel_emu.h 2007-10-02 19:47:31 UTC (rev 22416) @@ -17,7 +17,7 @@ status_t notify_listener(int32 operation, uint32 details, dev_t device, ino_t oldDirectory, ino_t directory, ino_t node, const char* oldName, const char* name); -status_t notify_select_event(selectsync *sync, uint32 ref, uint8 event, +status_t notify_select_event(selectsync *sync, uint8 event, bool unspecifiedEvent); status_t notify_query(port_id port, int32 token, int32 operation, dev_t device, ino_t directory, const char* name, ino_t node); Modified: haiku/trunk/src/add-ons/kernel/network/stack/net_socket.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/stack/net_socket.cpp 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/src/add-ons/kernel/network/stack/net_socket.cpp 2007-10-02 19:47:31 UTC (rev 22416) @@ -470,7 +470,7 @@ benaphore_lock(&socket->lock); status_t status = add_select_sync_pool_entry(&socket->select_pool, sync, - ref, event); + event); benaphore_unlock(&socket->lock); @@ -486,7 +486,7 @@ ssize_t available = socket_read_avail(socket); if ((ssize_t)socket->receive.low_water_mark <= available || available < B_OK) - notify_select_event(sync, ref, event); + notify_select_event(sync, event); break; } case B_SELECT_WRITE: @@ -494,7 +494,7 @@ ssize_t available = socket_send_avail(socket); if ((ssize_t)socket->send.low_water_mark <= available || available < B_OK) - notify_select_event(sync, ref, event); + notify_select_event(sync, event); break; } case B_SELECT_ERROR: Modified: haiku/trunk/src/system/kernel/Jamfile =================================================================== --- haiku/trunk/src/system/kernel/Jamfile 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/src/system/kernel/Jamfile 2007-10-02 19:47:31 UTC (rev 22416) @@ -40,6 +40,7 @@ team.cpp thread.cpp timer.c + wait_for_objects.cpp : $(TARGET_KERNEL_PIC_CCFLAGS) ; Modified: haiku/trunk/src/system/kernel/fs/Jamfile =================================================================== --- haiku/trunk/src/system/kernel/fs/Jamfile 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/src/system/kernel/fs/Jamfile 2007-10-02 19:47:31 UTC (rev 22416) @@ -13,7 +13,6 @@ vfs.cpp vfs_boot.cpp vfs_net_boot.cpp - vfs_select.cpp node_monitor.cpp IOScheduler.cpp KPath.cpp Modified: haiku/trunk/src/system/kernel/fs/devfs.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/devfs.cpp 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/src/system/kernel/fs/devfs.cpp 2007-10-02 19:47:31 UTC (rev 22416) @@ -1839,7 +1839,7 @@ // If the device has no select() hook, notify select() now. if (!vnode->stream.u.dev.info->select) - return notify_select_event((selectsync*)sync, ref, event); + return notify_select_event((selectsync*)sync, event); return vnode->stream.u.dev.info->select(cookie->device_cookie, event, ref, (selectsync*)sync); Modified: haiku/trunk/src/system/kernel/fs/fd.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/fd.cpp 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/src/system/kernel/fs/fd.cpp 2007-10-02 19:47:31 UTC (rev 22416) @@ -4,7 +4,6 @@ * Distributed under the terms of the MIT License. */ - #include #include @@ -15,10 +14,9 @@ #include #include #include +#include -#include "vfs_select.h" - //#define TRACE_FD #ifdef TRACE_FD # define TRACE(x) dprintf x @@ -448,6 +446,7 @@ } } + notify_select_events(info, B_EVENT_INVALID); info = info->next; put_select_sync(sync); } @@ -455,9 +454,10 @@ status_t -select_fd(int fd, struct select_sync* sync, uint32 ref, bool kernel) +select_fd(int32 fd, struct select_info* info, bool kernel) { - TRACE(("select_fd(fd = %d, selectsync = %p, ref = %lu, 0x%x)\n", fd, sync, ref, sync->set[ref].selected_events)); + TRACE(("select_fd(fd = %d, info = %p (%p), 0x%x)\n", fd, info, + info->sync, info.selected_events)); FDGetter fdGetter; // define before the context locker, so it will be destroyed after it @@ -469,7 +469,6 @@ if (descriptor == NULL) return B_FILE_ERROR; - select_info* info = &sync->set[ref]; if (info->selected_events == 0) return B_OK; @@ -485,7 +484,7 @@ // as long as the info is in the list, we keep a reference to the sync // object - atomic_add(&sync->ref_count, 1); + atomic_add(&info->sync->ref_count, 1); locker.Unlock(); @@ -494,7 +493,7 @@ for (uint16 event = 1; event < 16; event++) { if (info->selected_events & SELECT_FLAG(event) - && descriptor->ops->fd_select(descriptor, event, ref, + && descriptor->ops->fd_select(descriptor, event, (selectsync*)info) == B_OK) { selectedEvents |= SELECT_FLAG(event); } @@ -503,18 +502,18 @@ // if nothing has been selected, we deselect immediately if (selectedEvents == 0) - deselect_fd(fd, sync, ref, kernel); + deselect_fd(fd, info, kernel); return B_OK; } status_t -deselect_fd(int fd, struct select_sync* sync, uint32 ref, bool kernel) +deselect_fd(int32 fd, struct select_info* info, bool kernel) { - TRACE(("deselect_fd(fd = %d, selectsync = %p, ref = %lu)\n", fd, sync, ref)); + TRACE(("deselect_fd(fd = %d, info = %p (%p), 0x%x)\n", fd, info, + info->sync, info.selected_events)); - select_info* info = &sync->set[ref]; if (info->selected_events == 0) return B_OK; @@ -552,7 +551,7 @@ } } - put_select_sync(sync); + put_select_sync(info->sync); return B_OK; } Modified: haiku/trunk/src/system/kernel/fs/pipefs.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/pipefs.cpp 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/src/system/kernel/fs/pipefs.cpp 2007-10-02 19:47:31 UTC (rev 22416) @@ -12,20 +12,19 @@ #include #include +#include #include -#include +#include +#include +#include +#include +#include #include #include #include #include -#include "vfs_select.h" -#include -#include -#include -#include #include -#include //#define TRACE_PIPEFS @@ -960,7 +959,7 @@ } else return B_NOT_ALLOWED; - if (add_select_sync_pool_entry(pool, sync, ref, event) != B_OK) + if (add_select_sync_pool_entry(pool, sync, event) != B_OK) return B_ERROR; // signal right away, if the condition holds already @@ -968,12 +967,12 @@ if (event == B_SELECT_WRITE && (fBuffer.Writable() > 0 || fReaderCount == 0) || event == B_SELECT_ERROR && fReaderCount == 0) { - return notify_select_event(sync, ref, event); + return notify_select_event(sync, event); } } else { if (event == B_SELECT_READ && (fBuffer.Readable() > 0 || fWriterCount == 0)) { - return notify_select_event(sync, ref, event); + return notify_select_event(sync, event); } } Modified: haiku/trunk/src/system/kernel/fs/vfs.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/vfs.cpp 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/src/system/kernel/fs/vfs.cpp 2007-10-02 19:47:31 UTC (rev 22416) @@ -201,7 +201,7 @@ static off_t file_seek(struct file_descriptor *, off_t pos, int seek_type); static void file_free_fd(struct file_descriptor *); static status_t file_close(struct file_descriptor *); -static status_t file_select(struct file_descriptor *, uint8 event, uint32 ref, +static status_t file_select(struct file_descriptor *, uint8 event, struct selectsync *sync); static status_t file_deselect(struct file_descriptor *, uint8 event, struct selectsync *sync); @@ -3894,7 +3894,7 @@ static status_t -file_select(struct file_descriptor *descriptor, uint8 event, uint32 ref, +file_select(struct file_descriptor *descriptor, uint8 event, struct selectsync *sync) { FUNCTION(("file_select(%p, %u, %lu, %p)\n", descriptor, event, ref, sync)); @@ -3903,10 +3903,10 @@ // If the FS has no select() hook, notify select() now. if (FS_CALL(vnode, select) == NULL) - return notify_select_event(sync, ref, event); + return notify_select_event(sync, event); return FS_CALL(vnode, select)(vnode->mount->cookie, vnode->private_node, - descriptor->cookie, event, ref, sync); + descriptor->cookie, event, 0, sync); } Deleted: haiku/trunk/src/system/kernel/fs/vfs_select.cpp Deleted: haiku/trunk/src/system/kernel/fs/vfs_select.h Modified: haiku/trunk/src/system/kernel/port.c =================================================================== --- haiku/trunk/src/system/kernel/port.c 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/src/system/kernel/port.c 2007-10-02 19:47:31 UTC (rev 22416) @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -49,6 +50,7 @@ sem_id read_sem; sem_id write_sem; int32 total_count; // messages read from port since creation + select_info *select_infos; struct list msg_queue; }; @@ -312,6 +314,14 @@ } +static void +notify_port_select_events(int slot, uint16 events) +{ + if (sPorts[slot].select_infos) + notify_select_events_list(sPorts[slot].select_infos, events); +} + + /** this function cycles through the ports table, deleting all * the ports that are owned by the passed team_id */ @@ -499,6 +509,7 @@ list_init(&sPorts[i].msg_queue); sPorts[i].total_count = 0; + sPorts[i].select_infos = NULL; id = sPorts[i].id; RELEASE_PORT_LOCK(sPorts[i]); @@ -565,6 +576,9 @@ readSem = sPorts[slot].read_sem; writeSem = sPorts[slot].write_sem; + notify_port_select_events(slot, B_EVENT_INVALID); + sPorts[slot].select_infos = NULL; + RELEASE_PORT_LOCK(sPorts[slot]); restore_interrupts(state); @@ -611,6 +625,9 @@ sPorts[slot].name = NULL; list_move_to_list(&sPorts[slot].msg_queue, &list); + notify_port_select_events(slot, B_EVENT_INVALID); + sPorts[slot].select_infos = NULL; + RELEASE_PORT_LOCK(sPorts[slot]); // update the first free slot hint in the array @@ -639,6 +656,93 @@ } +status_t +select_port(int32 id, struct select_info *info, bool kernel) +{ + cpu_status state; + int32 slot; + status_t error = B_OK; + + if (id < 0) + return B_BAD_PORT_ID; + + slot = id % sMaxPorts; + + state = disable_interrupts(); + GRAB_PORT_LOCK(sPorts[slot]); + + if (sPorts[slot].id != id || is_port_closed(slot)) { + // bad port ID + error = B_BAD_SEM_ID; + } else if (!kernel && sPorts[slot].owner == team_get_kernel_team_id()) { + // kernel port, but call from userland + error = B_NOT_ALLOWED; + } else { + info->selected_events &= B_EVENT_READ | B_EVENT_WRITE | B_EVENT_INVALID; + + if (info->selected_events != 0) { + uint16 events = 0; + int32 writeCount = 0; + + info->next = sPorts[slot].select_infos; + sPorts[slot].select_infos = info; + + // check for events + if ((info->selected_events & B_EVENT_READ) != 0 + && !list_is_empty(&sPorts[slot].msg_queue)) { + events |= B_EVENT_READ; + } + + if (get_sem_count(sPorts[slot].write_sem, &writeCount) == B_OK + && writeCount > 0) { + events |= B_EVENT_WRITE; + } + + if (events != 0) + notify_select_events(info, events); + } + } + + RELEASE_PORT_LOCK(sPorts[slot]); + restore_interrupts(state); + + return error; +} + + +status_t +deselect_port(int32 id, struct select_info *info, bool kernel) +{ + cpu_status state; + int32 slot; + + if (id < 0) + return B_BAD_PORT_ID; + + if (info->selected_events == 0) + return B_OK; + + slot = id % sMaxPorts; + + state = disable_interrupts(); + GRAB_PORT_LOCK(sPorts[slot]); + + if (sPorts[slot].id == id) { + select_info** infoLocation = &sPorts[slot].select_infos; + while (*infoLocation != NULL && *infoLocation != info) + infoLocation = &(*infoLocation)->next; + + if (*infoLocation == info) + *infoLocation = info->next; + } + + RELEASE_PORT_LOCK(sPorts[slot]); + restore_interrupts(state); + + return B_OK; +} + + port_id find_port(const char *name) { @@ -988,6 +1092,8 @@ sPorts[slot].total_count++; + notify_port_select_events(slot, B_EVENT_WRITE); + cachedSem = sPorts[slot].write_sem; RELEASE_PORT_LOCK(sPorts[slot]); @@ -1151,6 +1257,8 @@ list_add_item(&sPorts[slot].msg_queue, msg); + notify_port_select_events(slot, B_EVENT_READ); + // store sem_id in local variable cachedSem = sPorts[slot].read_sem; Modified: haiku/trunk/src/system/kernel/sem.c =================================================================== --- haiku/trunk/src/system/kernel/sem.c 2007-10-02 17:40:05 UTC (rev 22415) +++ haiku/trunk/src/system/kernel/sem.c 2007-10-02 19:47:31 UTC (rev 22416) @@ -25,10 +25,12 @@ #include #include #include +#include #include #include + //#define TRACE_SEM #ifdef TRACE_SEM # define TRACE(x) dprintf x [... truncated: 1221 lines follow ...] From bonefish at mail.berlios.de Tue Oct 2 21:48:39 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Tue, 2 Oct 2007 21:48:39 +0200 Subject: [Haiku-commits] r22417 - haiku/trunk/src/tests/system/kernel Message-ID: <200710021948.l92JmdhM016539@sheep.berlios.de> Author: bonefish Date: 2007-10-02 21:48:39 +0200 (Tue, 02 Oct 2007) New Revision: 22417 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22417&view=rev Added: haiku/trunk/src/tests/system/kernel/wait_for_objects_test.cpp Modified: haiku/trunk/src/tests/system/kernel/Jamfile Log: Little test program for wait_for_objects_etc(). Modified: haiku/trunk/src/tests/system/kernel/Jamfile =================================================================== --- haiku/trunk/src/tests/system/kernel/Jamfile 2007-10-02 19:47:31 UTC (rev 22416) +++ haiku/trunk/src/tests/system/kernel/Jamfile 2007-10-02 19:48:39 UTC (rev 22417) @@ -41,6 +41,8 @@ SimpleTest wait_test_3 : wait_test_3.cpp ; SimpleTest wait_test_4 : wait_test_4.cpp ; +SimpleTest wait_for_objects_test : wait_for_objects_test.cpp ; + SimpleTest yield_test : yield_test.cpp ; SetSupportedPlatformsForTarget sigint_bug113_test Added: haiku/trunk/src/tests/system/kernel/wait_for_objects_test.cpp =================================================================== --- haiku/trunk/src/tests/system/kernel/wait_for_objects_test.cpp 2007-10-02 19:47:31 UTC (rev 22416) +++ haiku/trunk/src/tests/system/kernel/wait_for_objects_test.cpp 2007-10-02 19:48:39 UTC (rev 22417) @@ -0,0 +1,150 @@ +#include +#include +#include +#include +#include +#include + +#include + + +static sem_id sSemaphore1; +static sem_id sSemaphore2; +static port_id sPort1; +static port_id sPort2; + + +static status_t +notifier_thread(void* data) +{ + snooze(1000000); + release_sem(sSemaphore1); + snooze(1000000); + release_sem(sSemaphore2); + snooze(1000000); + write_port(sPort1, 0xcafe, "test", 4); + snooze(1000000); + int32 code; + read_port(sPort2, &code, &code, sizeof(code)); + snooze(1000000); + + return B_OK; +} + + +static void +print_events(const object_wait_info* infos, int infoCount) +{ + printf("events:\n"); + for (int i = 0; i < infoCount; i++) + printf(" %d: 0x%x\n", i, infos[i].events); +} + + +int +main() +{ + sSemaphore1 = create_sem(0L, "test semaphore 1"); + sSemaphore2 = create_sem(0L, "test semaphore 2"); + sPort1 = create_port(2L, "test port 1"); + sPort2 = create_port(1L, "test port 2"); + + printf("semaphore 1: %ld\n", sSemaphore1); + printf("semaphore 2: %ld\n", sSemaphore2); + printf("port 1: %ld\n", sPort1); + printf("port 2: %ld\n", sPort2); + + thread_id thread = spawn_thread(notifier_thread, "notifier", + B_NORMAL_PRIORITY, NULL); + resume_thread(thread); + + printf("thread: %ld\n", thread); + + object_wait_info initialInfos[] = { + { + sSemaphore1, + B_OBJECT_TYPE_SEMAPHORE, + B_EVENT_ACQUIRE_SEMAPHORE + }, + { + sSemaphore2, + B_OBJECT_TYPE_SEMAPHORE, + B_EVENT_ACQUIRE_SEMAPHORE + }, + { + sPort1, + B_OBJECT_TYPE_PORT, + B_EVENT_READ + }, + { + sPort2, + B_OBJECT_TYPE_PORT, + B_EVENT_WRITE + }, + { + 0, + B_OBJECT_TYPE_FD, + B_EVENT_READ + }, + { + thread, + B_OBJECT_TYPE_THREAD, + B_EVENT_INVALID + } + }; + int infoCount = sizeof(initialInfos) / sizeof(object_wait_info); + + while (true) { + object_wait_info infos[infoCount]; + memcpy(infos, initialInfos, sizeof(initialInfos)); + + ssize_t result = wait_for_objects_etc(infos, infoCount, + B_RELATIVE_TIMEOUT, 10000000LL); + + if (result >= 0) + printf("\nwait_for_objects(): %ld\n", result); + else + printf("\nwait_for_objects(): %s\n", strerror(result)); + + print_events(infos, infoCount); + + for (int i = 0; i < infoCount; i++) { + int32 type = infos[i].type; + int32 object = infos[i].object; + uint16 events = infos[i].events; + char buffer[256]; + + if (type == B_OBJECT_TYPE_SEMAPHORE) { + if (events & B_EVENT_ACQUIRE_SEMAPHORE) { + status_t error = acquire_sem_etc(object, 1, + B_RELATIVE_TIMEOUT, 0); + printf("acquire_sem(%ld): %s\n", object, strerror(error)); + } + } else if (type == B_OBJECT_TYPE_PORT) { + if (events & B_EVENT_READ) { + int32 code; + ssize_t bytesRead = read_port_etc(object, &code, + buffer, sizeof(buffer), B_RELATIVE_TIMEOUT, 0); + printf("read_port(%ld): %ld\n", object, bytesRead); + } + if (events & B_EVENT_WRITE) { + status_t error = write_port_etc(object, 0xc0de, buffer, 10, + B_RELATIVE_TIMEOUT, 0); + printf("write_port(%ld): %s\n", object, strerror(error)); + } + } else if (type == B_OBJECT_TYPE_FD) { + if (events & B_EVENT_READ) { + ssize_t bytesRead = read(object, buffer, sizeof(buffer)); + printf("read(%ld): %ld\n", object, bytesRead); + } + } else if (type == B_OBJECT_TYPE_THREAD) { + if (events & B_EVENT_INVALID) { + printf("thread %ld quit\n", object); + infoCount--; + } + } + } + } + + return 0; +} From bonefish at mail.berlios.de Tue Oct 2 21:52:47 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Tue, 2 Oct 2007 21:52:47 +0200 Subject: [Haiku-commits] r22418 - haiku/trunk/src/system/kernel/lib Message-ID: <200710021952.l92JqliB016793@sheep.berlios.de> Author: bonefish Date: 2007-10-02 21:52:47 +0200 (Tue, 02 Oct 2007) New Revision: 22418 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22418&view=rev Modified: haiku/trunk/src/system/kernel/lib/Jamfile Log: Add wait_for_objects.cpp to the kernel, too. Modified: haiku/trunk/src/system/kernel/lib/Jamfile =================================================================== --- haiku/trunk/src/system/kernel/lib/Jamfile 2007-10-02 19:48:39 UTC (rev 22417) +++ haiku/trunk/src/system/kernel/lib/Jamfile 2007-10-02 19:52:47 UTC (rev 22418) @@ -6,11 +6,16 @@ driver_settings.c find_directory.c fs_info.c + wait_for_objects.cpp : $(TARGET_KERNEL_PIC_CCFLAGS) ; -SEARCH on [ FGristFiles driver_settings.c find_directory.c fs_info.c ] - = [ FDirName $(HAIKU_TOP) src system libroot os ] ; +SEARCH on [ FGristFiles + driver_settings.c + find_directory.c + fs_info.c + wait_for_objects.cpp + ] = [ FDirName $(HAIKU_TOP) src system libroot os ] ; # kernel libroot posix files From marcusoverhagen at mail.berlios.de Wed Oct 3 18:05:24 2007 From: marcusoverhagen at mail.berlios.de (marcusoverhagen at BerliOS) Date: Wed, 3 Oct 2007 18:05:24 +0200 Subject: [Haiku-commits] r22419 - haiku/trunk/src/add-ons/kernel/busses/scsi/ahci Message-ID: <200710031605.l93G5OgH006602@sheep.berlios.de> Author: marcusoverhagen Date: 2007-10-03 18:05:23 +0200 (Wed, 03 Oct 2007) New Revision: 22419 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22419&view=rev Modified: haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci.c haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.h haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_defs.h haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_sim.cpp Log: Changed device detection. The driver now first uses device and vendor id to check for devices. This allows using devices that are in IDE compatibility mode. Modified: haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci.c =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci.c 2007-10-02 19:52:47 UTC (rev 22418) +++ haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci.c 2007-10-03 16:05:23 UTC (rev 22419) @@ -20,6 +20,36 @@ device_manager_info *gDeviceManager; +device_info sSupportedDevices[] = +{ + { 0x197b, 0x2360, "JMicron JMB360" }, + { 0x197b, 0x2361, "JMicron JMB361" }, + { 0x197b, 0x2362, "JMicron JMB362" }, + { 0x197b, 0x2363, "JMicron JMB363" }, + { 0x197b, 0x2366, "JMicron JMB366" }, + { 0x8086, 0x27c0, "Intel ICH7 (IDE mode)" }, + { 0x8086, 0x27c1, "Intel ICH7 (AHCI mode)" }, + {} +}; + + +status_t +get_device_info(uint16 vendorID, uint16 deviceID, const char **name, uint32 *flags) +{ + device_info *info; + for (info = sSupportedDevices; info->vendor; info++) { + if (info->vendor == vendorID && info->device == deviceID) { + if (name) + *name = info->name; + if (flags) + *flags = info->flags; + return B_OK; + } + } + return B_ERROR; +} + + static status_t register_sim(device_node_handle parent) { @@ -58,42 +88,64 @@ // #pragma mark - - static float ahci_supports_device(device_node_handle parent, bool *_noConnection) { uint8 baseClass, subClass, classAPI; uint16 vendorID; uint16 deviceID; + bool isPCI; + const char *name; char *bus; TRACE("ahci_supports_device\n"); - if (gDeviceManager->get_attr_string(parent, B_DRIVER_BUS, &bus, - false) != B_OK - || gDeviceManager->get_attr_uint8(parent, - PCI_DEVICE_BASE_CLASS_ID_ITEM, &baseClass, false) != B_OK - || gDeviceManager->get_attr_uint8(parent, - PCI_DEVICE_SUB_CLASS_ID_ITEM, &subClass, false) != B_OK - || gDeviceManager->get_attr_uint8(parent, - PCI_DEVICE_API_ID_ITEM, &classAPI, false) != B_OK - || gDeviceManager->get_attr_uint16(parent, - PCI_DEVICE_VENDOR_ID_ITEM, &vendorID, false) != B_OK - || gDeviceManager->get_attr_uint16(parent, - PCI_DEVICE_DEVICE_ID_ITEM, &deviceID, false) != B_OK) - return B_ERROR; + if (gDeviceManager->get_attr_string(parent, B_DRIVER_BUS, &bus, false) < B_OK) + return 0.0f; + isPCI = !strcmp(bus, "pci"); + free(bus); + if (!isPCI) + return 0.0f; - if (strcmp(bus, "pci") || baseClass != PCI_mass_storage - || subClass != PCI_sata || classAPI != PCI_sata_ahci) { - free(bus); + if (gDeviceManager->get_attr_uint8(parent, PCI_DEVICE_BASE_CLASS_ID_ITEM, &baseClass, false) < B_OK + || gDeviceManager->get_attr_uint8(parent, PCI_DEVICE_SUB_CLASS_ID_ITEM, &subClass, false) < B_OK + || gDeviceManager->get_attr_uint8(parent, PCI_DEVICE_API_ID_ITEM, &classAPI, false) < B_OK + || gDeviceManager->get_attr_uint16(parent, PCI_DEVICE_VENDOR_ID_ITEM, &vendorID, false) < B_OK + || gDeviceManager->get_attr_uint16(parent, PCI_DEVICE_DEVICE_ID_ITEM, &deviceID, false) < B_OK) return 0.0f; + + if (get_device_info(vendorID, deviceID, &name, NULL) < B_OK) { + if (baseClass != PCI_mass_storage || subClass != PCI_sata || classAPI != PCI_sata_ahci) + return 0.0f; + TRACE("generic AHCI controller found! vendor 0x%04x, device 0x%04x\n", vendorID, deviceID); + return 0.8f; } - TRACE("controller found! vendor 0x%04x, device 0x%04x\n", - vendorID, deviceID); + if (vendorID == PCI_VENDOR_JMICRON) { + // JMicron uses the same device ID for SATA and PATA controllers, + // check if BAR5 exists to determine if it's a AHCI controller + uint8 bus, device, function; + pci_info info; + pci_module_info *pci; + size_t size = 0; + int i; + gDeviceManager->get_attr_uint8(parent, PCI_DEVICE_BUS_ITEM, &bus, false); + gDeviceManager->get_attr_uint8(parent, PCI_DEVICE_DEVICE_ITEM, &device, false); + gDeviceManager->get_attr_uint8(parent, PCI_DEVICE_FUNCTION_ITEM, &function, false); + get_module(B_PCI_MODULE_NAME, (module_info **)&pci); + for (i = 0; B_OK == pci->get_nth_pci_info(i, &info); i++) { + if (info.bus == bus && info.device == device && info.function == function) { + size = info.u.h0.base_register_sizes[5]; + break; + } + } + put_module(B_PCI_MODULE_NAME); + if (size == 0) + return 0.0f; + } - free(bus); - return 0.5; + TRACE("AHCI controller %s found!\n", name); + return 1.0f; } @@ -156,6 +208,8 @@ if (status != B_OK) return status; + TRACE("ahci_init_driver: gPCI %p, pciDevice %p\n", gPCI, pciDevice); + gDeviceManager->put_device_node(parent); *_userCookie = pciDevice; Modified: haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp 2007-10-02 19:52:47 UTC (rev 22418) +++ haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp 2007-10-03 16:05:23 UTC (rev 22419) @@ -20,6 +20,7 @@ , fPCIDevice(device) , fPCIVendorID(0xffff) , fPCIDeviceID(0xffff) + , fFlags(0) , fCommandSlotCount(0) , fPortCountMax(0) , fPortCountAvail(0) @@ -69,6 +70,8 @@ fInstanceCheck = create_port(1, sName); // --- Instance check workaround end + get_device_info(fPCIVendorID, fPCIDeviceID, NULL, &fFlags); + uchar capabilityOffset; status_t res = gPCI->find_pci_capability(fPCIDevice, PCI_cap_id_sata, &capabilityOffset); if (res == B_OK) { Modified: haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.h =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.h 2007-10-02 19:52:47 UTC (rev 22418) +++ haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.h 2007-10-03 16:05:23 UTC (rev 22419) @@ -40,6 +40,7 @@ pci_device_info* fPCIDevice; uint16 fPCIVendorID; uint16 fPCIDeviceID; + uint32 fFlags; volatile ahci_hba * fRegs; area_id fRegsArea; @@ -49,7 +50,6 @@ uint8 fIRQ; AHCIPort * fPort[32]; - // --- Instance check workaround begin port_id fInstanceCheck; // --- Instance check workaround end @@ -64,5 +64,4 @@ dummy = dummy; } - #endif // _AHCI_CONTROLLER_H Modified: haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_defs.h =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_defs.h 2007-10-02 19:52:47 UTC (rev 22418) +++ haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_defs.h 2007-10-03 16:05:23 UTC (rev 22419) @@ -8,6 +8,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + #define AHCI_DEVICE_MODULE_NAME "busses/scsi/ahci/device_v1" #define AHCI_SIM_MODULE_NAME "busses/scsi/ahci/sim/v1" @@ -211,6 +215,16 @@ #define PRD_MAX_DATA_LENGTH 0x400000 /* 4 MB */ +typedef struct { + uint16 vendor; + uint16 device; + const char *name; + uint32 flags; +} device_info; + +status_t get_device_info(uint16 vendorID, uint16 deviceID, const char **name, uint32 *flags); + + extern scsi_sim_interface gAHCISimInterface; extern device_manager_info *gDeviceManager; extern pci_device_module_info *gPCI; @@ -225,7 +239,11 @@ #define PCI_JMICRON_CONTROLLER_CONTROL_1 0x40 #ifdef __cplusplus +} +#endif +#ifdef __cplusplus + template int count_bits_set(T value) { @@ -264,5 +282,4 @@ #endif /* __cplusplus */ - #endif /* _AHCI_DEFS_H */ Modified: haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_sim.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_sim.cpp 2007-10-02 19:52:47 UTC (rev 22418) +++ haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_sim.cpp 2007-10-03 16:05:23 UTC (rev 22419) @@ -130,15 +130,19 @@ AHCIController *controller; status_t status; - TRACE("ahci_sim_init_bus, userCookie %p\n", userCookie); + TRACE("ahci_sim_init_bus: userCookie %p\n", userCookie); - // initialize parent (the bus) to get the PCI interface and device + TRACE("ahci_sim_init_bus: gPCI %p\n", gPCI); + + // initialize parent (the bus) to get the PCI device parent = gDeviceManager->get_parent(node); status = gDeviceManager->init_driver(parent, &pciDevice, NULL, NULL); gDeviceManager->put_device_node(parent); if (status != B_OK) return status; + TRACE("ahci_sim_init_bus: pciDevice %p\n", pciDevice); + controller = new(std::nothrow) AHCIController(node, pciDevice); if (!controller) return B_NO_MEMORY; From marcusoverhagen at mail.berlios.de Wed Oct 3 19:57:10 2007 From: marcusoverhagen at mail.berlios.de (marcusoverhagen at BerliOS) Date: Wed, 3 Oct 2007 19:57:10 +0200 Subject: [Haiku-commits] r22420 - haiku/trunk/src/add-ons/kernel/busses/scsi/ahci Message-ID: <200710031757.l93HvAu7032286@sheep.berlios.de> Author: marcusoverhagen Date: 2007-10-03 19:57:09 +0200 (Wed, 03 Oct 2007) New Revision: 22420 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22420&view=rev Modified: haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci.c Log: Added PCI ids from Freebsd, Netbsd and Openbsd pcidevs files. Modified: haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci.c =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci.c 2007-10-03 16:05:23 UTC (rev 22419) +++ haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci.c 2007-10-03 17:57:09 UTC (rev 22420) @@ -22,13 +22,56 @@ device_info sSupportedDevices[] = { + { 0x1002, 0x4391, "ATI IXP700" }, + { 0x10de, 0x044c, "NVIDIA MCP65" }, + { 0x10de, 0x044d, "NVIDIA MCP65" }, + { 0x10de, 0x044e, "NVIDIA MCP65" }, + { 0x10de, 0x044f, "NVIDIA MCP65" }, + { 0x10de, 0x0554, "NVIDIA MCP67" }, + { 0x10de, 0x0555, "NVIDIA MCP67" }, + { 0x10de, 0x0556, "NVIDIA MCP67" }, + { 0x10de, 0x0557, "NVIDIA MCP67" }, + { 0x10de, 0x0558, "NVIDIA MCP67" }, + { 0x10de, 0x0559, "NVIDIA MCP67" }, + { 0x10de, 0x055a, "NVIDIA MCP67" }, + { 0x10de, 0x055b, "NVIDIA MCP67" }, + { 0x10de, 0x07f0, "NVIDIA MCP73" }, + { 0x10de, 0x07f1, "NVIDIA MCP73" }, + { 0x10de, 0x07f2, "NVIDIA MCP73" }, + { 0x10de, 0x07f3, "NVIDIA MCP73" }, + { 0x10de, 0x07f4, "NVIDIA MCP73" }, + { 0x10de, 0x07f5, "NVIDIA MCP73" }, + { 0x10de, 0x07f6, "NVIDIA MCP73" }, + { 0x10de, 0x07f7, "NVIDIA MCP73" }, + { 0x10de, 0x07f8, "NVIDIA MCP73" }, + { 0x10de, 0x07f9, "NVIDIA MCP73" }, + { 0x10de, 0x07fa, "NVIDIA MCP73" }, + { 0x10de, 0x07fb, "NVIDIA MCP73" }, + { 0x10de, 0x0ad0, "NVIDIA MCP77" }, + { 0x10de, 0x0ad1, "NVIDIA MCP77" }, + { 0x10de, 0x0ad2, "NVIDIA MCP77" }, + { 0x10de, 0x0ad3, "NVIDIA MCP77" }, + { 0x10de, 0x0ad4, "NVIDIA MCP77" }, + { 0x10de, 0x0ad5, "NVIDIA MCP77" }, + { 0x10de, 0x0ad6, "NVIDIA MCP77" }, + { 0x10de, 0x0ad7, "NVIDIA MCP77" }, + { 0x10de, 0x0ad8, "NVIDIA MCP77" }, + { 0x10de, 0x0ad9, "NVIDIA MCP77" }, + { 0x10de, 0x0ada, "NVIDIA MCP77" }, + { 0x10de, 0x0adb, "NVIDIA MCP77" }, { 0x197b, 0x2360, "JMicron JMB360" }, { 0x197b, 0x2361, "JMicron JMB361" }, { 0x197b, 0x2362, "JMicron JMB362" }, { 0x197b, 0x2363, "JMicron JMB363" }, { 0x197b, 0x2366, "JMicron JMB366" }, + { 0x8086, 0x2681, "Intel 63xxESB" }, { 0x8086, 0x27c0, "Intel ICH7 (IDE mode)" }, { 0x8086, 0x27c1, "Intel ICH7 (AHCI mode)" }, + { 0x8086, 0x27c5, "Intel 82801GBM" }, + { 0x8086, 0x2821, "Intel 82801H" }, + { 0x8086, 0x2824, "Intel 82801H" }, + { 0x8086, 0x2922, "Intel 82801I" }, + { 0x8086, 0x2923, "Intel 82801I" }, {} }; From bonefish at mail.berlios.de Wed Oct 3 21:04:45 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 3 Oct 2007 21:04:45 +0200 Subject: [Haiku-commits] r22421 - haiku/trunk/src/add-ons/kernel/drivers/tty Message-ID: <200710031904.l93J4jWP007736@sheep.berlios.de> Author: bonefish Date: 2007-10-03 21:04:44 +0200 (Wed, 03 Oct 2007) New Revision: 22421 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22421&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/tty/driver.cpp haiku/trunk/src/add-ons/kernel/drivers/tty/tty.cpp haiku/trunk/src/add-ons/kernel/drivers/tty/tty_private.h Log: * Added debugger command "tty", which dumps some info about a tty. * RequestOwner was removing the wrong request from the second queue, which could cause the list structure to become invalid and result in bug #1526. * In the writer loops we do now call tty_notify_if_available() when we're potentially going to wait and had written something before, so that a waiting reader will be woken up also when we write more bytes than fit into the ring buffer. Modified: haiku/trunk/src/add-ons/kernel/drivers/tty/driver.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/tty/driver.cpp 2007-10-03 17:57:09 UTC (rev 22420) +++ haiku/trunk/src/add-ons/kernel/drivers/tty/driver.cpp 2007-10-03 19:04:44 UTC (rev 22421) @@ -100,6 +100,8 @@ } } + tty_add_debugger_commands(); + return B_OK; } @@ -109,6 +111,8 @@ { TRACE((DRIVER_NAME ": uninit_driver()\n")); + tty_remove_debugger_commands(); + for (int32 i = 0; i < (int32)kNumTTYs * 2; i++) free(sDeviceNames[i]); Modified: haiku/trunk/src/add-ons/kernel/drivers/tty/tty.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/tty/tty.cpp 2007-10-03 17:57:09 UTC (rev 22420) +++ haiku/trunk/src/add-ons/kernel/drivers/tty/tty.cpp 2007-10-03 19:04:44 UTC (rev 22421) @@ -223,6 +223,18 @@ } +void +Request::Dump(const char* prefix) +{ + kprintf("%srequest: %p\n", prefix, this); + kprintf("%s owner: %p\n", prefix, fOwner); + kprintf("%s cookie: %p\n", prefix, fCookie); + kprintf("%s bytes needed: %lu\n", prefix, fBytesNeeded); + kprintf("%s notified: %s\n", prefix, fNotified ? "true" : "false"); + kprintf("%s error: %s\n", prefix, fError ? "true" : "false"); +} + + // #pragma mark - @@ -290,6 +302,15 @@ } +void +RequestQueue::Dump(const char* prefix) +{ + RequestList::Iterator it = fRequests.GetIterator(); + while (Request* request = it.Next()) + request->Dump(prefix); +} + + // #pragma mark - @@ -345,7 +366,10 @@ if (fRequestQueues[0]) fRequestQueues[0]->Remove(&fRequests[0]); if (fRequestQueues[1]) - fRequestQueues[1]->Remove(&fRequests[0]); + fRequestQueues[1]->Remove(&fRequests[1]); + + fRequestQueues[0] = NULL; + fRequestQueues[1] = NULL; } @@ -1458,12 +1482,15 @@ "length = %lu%s)\n", source, target, length, (echo ? ", echo mode" : ""))); + // Make sure we are first in the writer queue(s) and AvailableBytes() is + // initialized. status_t status = locker.AcquireWriter(dontBlock, 0); if (status != B_OK) { *_length = 0; return status; } size_t writable = locker.AvailableBytes(); + size_t writtenSinceLastNotify = 0; while (bytesWritten < length) { // fetch next char and do input processing @@ -1489,6 +1516,13 @@ // If there's not enough space to write what we have, we need to wait // until it is available. if (writable < bytesNeeded) { + if (writtenSinceLastNotify > 0) { + tty_notify_if_available(target, source, true); + if (echo) + tty_notify_if_available(source, target, true); + writtenSinceLastNotify = 0; + } + status = locker.AcquireWriter(dontBlock, bytesNeeded); if (status != B_OK) { *_length = bytesWritten; @@ -1514,6 +1548,7 @@ writable -= bytesNeeded; data++; bytesWritten++; + writtenSinceLastNotify++; } return B_OK; @@ -1582,12 +1617,15 @@ TRACE(("tty_write_to_tty_slave(source = %p, target = %p, length = %lu)\n", sourceCookie->tty, target, length)); + // Make sure we are first in the writer queue(s) and AvailableBytes() is + // initialized. status_t status = locker.AcquireWriter(dontBlock, 0); if (status != B_OK) { *_length = 0; return status; } size_t writable = locker.AvailableBytes(); + size_t writtenSinceLastNotify = 0; while (bytesWritten < length) { // fetch next char and do output processing @@ -1598,6 +1636,11 @@ // If there's not enough space to write what we have, we need to wait // until it is available. if (writable < bytesNeeded) { + if (writtenSinceLastNotify > 0) { + tty_notify_if_available(target, sourceCookie->tty, true); + writtenSinceLastNotify = 0; + } + status = locker.AcquireWriter(dontBlock, bytesNeeded); if (status != B_OK) { *_length = bytesWritten; @@ -1618,6 +1661,7 @@ writable -= bytesNeeded; data++; bytesWritten++; + writtenSinceLastNotify++; } return B_OK; @@ -1771,3 +1815,80 @@ return remove_select_sync_pool_entry(&tty->select_pool, sync, event); } + +static void +dump_tty_settings(struct tty_settings& settings) +{ + kprintf(" pgrp_id: %ld\n", settings.pgrp_id); + kprintf(" session_id: %ld\n", settings.session_id); + // struct termios termios; + // struct winsize window_size; + +} + +static void +dump_tty_struct(struct tty& tty) +{ + kprintf(" index: %ld\n", tty.index); + kprintf(" is_master: %s\n", tty.is_master ? "true" : "false"); + kprintf(" open_count: %ld\n", tty.open_count); + kprintf(" select_pool: %p\n", tty.select_pool); + kprintf(" pending_eof: %lu\n", tty.pending_eof); + kprintf(" lock.sem: %ld\n", tty.lock->sem); + + kprintf(" input_buffer:\n"); + kprintf(" first: %ld\n", tty.input_buffer.first); + kprintf(" in: %lu\n", tty.input_buffer.in); + kprintf(" size: %lu\n", tty.input_buffer.size); + kprintf(" buffer: %p\n", tty.input_buffer.buffer); + + kprintf(" reader queue:\n"); + tty.reader_queue.Dump(" "); + kprintf(" writer queue:\n"); + tty.writer_queue.Dump(" "); + + kprintf(" cookies: "); + TTYCookieList::Iterator it = tty.cookies.GetIterator(); + while (tty_cookie* cookie = it.Next()) + kprintf(" %p", cookie); + kprintf("\n"); +} + + +static int +dump_tty(int argc, char** argv) +{ + if (argc < 2) { + kprintf("Usage: %s \n", argv[0]); + return 0; + } + + int32 index = atol(argv[1]); + if (index < 0 || index >= (int32)kNumTTYs) { + kprintf("Invalid tty index.\n"); + return 0; + } + + kprintf("master:\n"); + dump_tty_struct(gMasterTTYs[index]); + kprintf("slave:\n"); + dump_tty_struct(gSlaveTTYs[index]); + kprintf("settings:\n"); + dump_tty_settings(gTTYSettings[index]); + + return 0; +} + + +void +tty_add_debugger_commands() +{ + add_debugger_command("tty", &dump_tty, "Dump info on a tty"); +} + + +void +tty_remove_debugger_commands() +{ + remove_debugger_command("tty", &dump_tty); +} Modified: haiku/trunk/src/add-ons/kernel/drivers/tty/tty_private.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/tty/tty_private.h 2007-10-03 17:57:09 UTC (rev 22420) +++ haiku/trunk/src/add-ons/kernel/drivers/tty/tty_private.h 2007-10-03 19:04:44 UTC (rev 22421) @@ -47,6 +47,8 @@ bool WasNotified() const { return fNotified; } bool HasError() const { return fError; } + void Dump(const char* prefix); + private: RequestOwner *fOwner; tty_cookie *fCookie; @@ -70,6 +72,8 @@ void NotifyError(status_t error); void NotifyError(tty_cookie *cookie, status_t error); + void Dump(const char* prefix); + private: typedef DoublyLinkedList RequestList; @@ -181,4 +185,7 @@ selectsync *sync); extern status_t tty_deselect(tty_cookie *cookie, uint8 event, selectsync *sync); +extern void tty_add_debugger_commands(); +extern void tty_remove_debugger_commands(); + #endif /* TTY_PRIVATE_H */ From bonefish at mail.berlios.de Wed Oct 3 21:07:51 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 3 Oct 2007 21:07:51 +0200 Subject: [Haiku-commits] r22422 - haiku/trunk/src/add-ons/kernel/drivers/tty Message-ID: <200710031907.l93J7pnA008221@sheep.berlios.de> Author: bonefish Date: 2007-10-03 21:07:51 +0200 (Wed, 03 Oct 2007) New Revision: 22422 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22422&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/tty/line_buffer.cpp Log: If the ring buffer is full line_buffer_readable_line() returns the buffer size in case the buffer does not contain an EOL or EOF. This prevents readers from waiting infinitely, if canonical input processing is enabled in that situation. Modified: haiku/trunk/src/add-ons/kernel/drivers/tty/line_buffer.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/tty/line_buffer.cpp 2007-10-03 19:04:44 UTC (rev 22421) +++ haiku/trunk/src/add-ons/kernel/drivers/tty/line_buffer.cpp 2007-10-03 19:07:51 UTC (rev 22422) @@ -63,7 +63,9 @@ return i + 1; } - return 0; + // If the buffer is full, but doesn't contain a EOL or EOF, we report the + // full size anyway, since otherwise the reader would wait forever. + return buffer.in == buffer.size ? buffer.in : 0; } From bonefish at mail.berlios.de Wed Oct 3 21:35:41 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 3 Oct 2007 21:35:41 +0200 Subject: [Haiku-commits] r22423 - haiku/trunk/src/tests/servers/debug Message-ID: <200710031935.l93JZfJN011578@sheep.berlios.de> Author: bonefish Date: 2007-10-03 21:35:40 +0200 (Wed, 03 Oct 2007) New Revision: 22423 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22423&view=rev Modified: haiku/trunk/src/tests/servers/debug/crashing_app.cpp Log: Added option "--thread" which will perform the crashing operation in another thread. Modified: haiku/trunk/src/tests/servers/debug/crashing_app.cpp =================================================================== --- haiku/trunk/src/tests/servers/debug/crashing_app.cpp 2007-10-03 19:07:51 UTC (rev 22422) +++ haiku/trunk/src/tests/servers/debug/crashing_app.cpp 2007-10-03 19:35:40 UTC (rev 22423) @@ -14,6 +14,7 @@ "\n" "Options:\n" " -h, --help - print this info text\n" + " --thread - crash in a separate thread\n" "\n" "Modes:\n" "[general]\n" @@ -45,18 +46,19 @@ } -static void +static int crash_segv() { int *a = 0; *a = 0; + return 0; } -static void +static int crash_segv2() { const char *str = (const char*)0x1; - strcmp(str, "Test"); + return strcmp(str, "Test"); } static int @@ -67,33 +69,72 @@ return i; } -static void +static int crash_debugger() { debugger("crashing_app() invoked debugger()"); + return 0; } #if __INTEL__ -static void +static int crash_int3() { asm("int3"); + return 0; } -static void +static int crash_protection() { asm("movl %0, %%dr7" : : "r"(0)); + return 0; } #endif // __INTEL__ +typedef int crash_function_t(); + + +static crash_function_t* +get_crash_function(const char* mode) +{ + if (strcmp(mode, "segv") == 0) { + return crash_segv; + } else if (strcmp(mode, "segv2") == 0) { + return crash_segv2; + } else if (strcmp(mode, "div") == 0) { + return (crash_function_t*)crash_div; + } else if (strcmp(mode, "debugger") == 0) { + return crash_debugger; +#if __INTEL__ + } else if (strcmp(mode, "int3") == 0) { + return crash_int3; + } else if (strcmp(mode, "protection") == 0) { + return crash_protection; +#endif // __INTEL__ + } + + return NULL; +} + + +static status_t +crashing_thread(void* data) +{ + crash_function_t* doCrash = (crash_function_t*)data; + snooze(100000); + doCrash(); +} + + int -main(int argc, const char *const *argv) +main(int argc, const char* const* argv) { - const char *mode = "segv"; + bool inThread = false; + const char* mode = "segv"; // parse args int argi = 1; @@ -103,6 +144,8 @@ if (arg[0] == '-') { if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) { print_usage_and_exit(false); + } else if (strcmp(arg, "--thread") == 0) { + inThread = true; } else { fprintf(stderr, "Invalid option \"%s\"\n", arg); print_usage_and_exit(true); @@ -112,24 +155,28 @@ } } - if (strcmp(mode, "segv") == 0) { - crash_segv(); - } else if (strcmp(mode, "segv2") == 0) { - crash_segv2(); - } else if (strcmp(mode, "div") == 0) { - crash_div(); - } else if (strcmp(mode, "debugger") == 0) { - crash_debugger(); -#if __INTEL__ - } else if (strcmp(mode, "int3") == 0) { - crash_int3(); - } else if (strcmp(mode, "protection") == 0) { - crash_protection(); -#endif // __INTEL__ - } else { + crash_function_t* doCrash = get_crash_function(mode); + if (doCrash == NULL) { fprintf(stderr, "Invalid mode \"%s\"\n", mode); print_usage_and_exit(true); } + if (inThread) { + thread_id thread = spawn_thread(crashing_thread, "crashing thread", + B_NORMAL_PRIORITY, (void*)doCrash); + if (thread < 0) { + fprintf(stderr, "Error: Failed to spawn thread: %s\n", + strerror(thread)); + exit(1); + } + + resume_thread(thread); + status_t result; + while (wait_for_thread(thread, &result) == B_INTERRUPTED) { + } + } else { + doCrash(); + } + return 0; } From HOST.HAIKU at gmx.de Wed Oct 3 21:46:27 2007 From: HOST.HAIKU at gmx.de (HOST Team) Date: Wed, 03 Oct 2007 21:46:27 +0200 Subject: [Haiku-commits] r22299 - in haiku/trunk/src/add-ons/kernel/drivers/audio: . null In-Reply-To: <200709242309.l8ON9h2r015557@sheep.berlios.de> References: <200709242309.l8ON9h2r015557@sheep.berlios.de> Message-ID: <20071003194627.259250@gmx.net> Hi all, although it is a little bit late, but it is not a good idea to call the driver null as there is already one called this in drivers/common. Thus it will conflict with the other one. I suggest using null_audio or anything else appropriate. Best Regards, Bek -------- Original-Nachricht -------- > Datum: Tue, 25 Sep 2007 01:09:43 +0200 > Von: korli at BerliOS > An: haiku-commits at lists.berlios.de > Betreff: [Haiku-commits] r22299 - in haiku/trunk/src/add-ons/kernel/drivers/audio: . null > Author: korli > Date: 2007-09-25 01:09:42 +0200 (Tue, 25 Sep 2007) > New Revision: 22299 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22299&view=rev > > Added: > haiku/trunk/src/add-ons/kernel/drivers/audio/null/ > haiku/trunk/src/add-ons/kernel/drivers/audio/null/Jamfile > haiku/trunk/src/add-ons/kernel/drivers/audio/null/driver.c > haiku/trunk/src/add-ons/kernel/drivers/audio/null/driver.h > haiku/trunk/src/add-ons/kernel/drivers/audio/null/null_hardware.c > haiku/trunk/src/add-ons/kernel/drivers/audio/null/null_multi.c > Modified: > haiku/trunk/src/add-ons/kernel/drivers/audio/Jamfile > Log: > added null_audio driver from Bek, HOST team. Thanks. > Applied some style fixes. > It's not recognized as a fallback driver. We might also consider a simple > userland BufferConsumer/BufferProducer. > -- Psssst! Schon vom neuen GMX MultiMessenger geh?rt? Der kanns mit allen: http://www.gmx.net/de/go/multimessenger From HOST.HAIKU at gmx.de Wed Oct 3 22:13:02 2007 From: HOST.HAIKU at gmx.de (HOST Team) Date: Wed, 03 Oct 2007 22:13:02 +0200 Subject: [Haiku-commits] r22299 - in haiku/trunk/src/add-ons/kernel/drivers/audio: . null In-Reply-To: <20071003194627.259250@gmx.net> References: <200709242309.l8ON9h2r015557@sheep.berlios.de> <20071003194627.259250@gmx.net> Message-ID: <20071003201302.259290@gmx.net> Sorry, I was a little bit overhasty here. I added null to the BEOS_ADD_ONS_DRIVERS_AUDIO variable instead of null_audio. I guess it did not complain as there is one kernel addon called like this. Sorry again. Btw. is there an easy way to add a driver inside the UserBuildConfig? I did not find any instruction on that in the sample file. I could of course add the file and create the symlink itself, but is that a good solution? Best Regards, Bek -------- Original-Nachricht -------- > Datum: Wed, 03 Oct 2007 21:46:27 +0200 > Von: "HOST Team" > An: SVN commits to the Haiku source repository > Betreff: Re: [Haiku-commits] r22299 - in haiku/trunk/src/add-ons/kernel/drivers/audio: . null > Hi all, > although it is a little bit late, but it is not a good idea to call the > driver null as there is already one called this in drivers/common. Thus it > will conflict with the other one. > > I suggest using null_audio or anything else appropriate. > > Best Regards, > Bek > > -------- Original-Nachricht -------- > > Datum: Tue, 25 Sep 2007 01:09:43 +0200 > > Von: korli at BerliOS > > An: haiku-commits at lists.berlios.de > > Betreff: [Haiku-commits] r22299 - > in haiku/trunk/src/add-ons/kernel/drivers/audio: . null > > > Author: korli > > Date: 2007-09-25 01:09:42 +0200 (Tue, 25 Sep 2007) > > New Revision: 22299 > > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22299&view=rev > > > > Added: > > haiku/trunk/src/add-ons/kernel/drivers/audio/null/ > > haiku/trunk/src/add-ons/kernel/drivers/audio/null/Jamfile > > haiku/trunk/src/add-ons/kernel/drivers/audio/null/driver.c > > haiku/trunk/src/add-ons/kernel/drivers/audio/null/driver.h > > haiku/trunk/src/add-ons/kernel/drivers/audio/null/null_hardware.c > > haiku/trunk/src/add-ons/kernel/drivers/audio/null/null_multi.c > > Modified: > > haiku/trunk/src/add-ons/kernel/drivers/audio/Jamfile > > Log: > > added null_audio driver from Bek, HOST team. Thanks. > > Applied some style fixes. > > It's not recognized as a fallback driver. We might also consider a > simple > > userland BufferConsumer/BufferProducer. > > > -- > Psssst! Schon vom neuen GMX MultiMessenger geh?rt? > Der kanns mit allen: http://www.gmx.net/de/go/multimessenger > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits -- Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! Ideal f?r Modem und ISDN: http://www.gmx.net/de/go/smartsurfer From bonefish at mail.berlios.de Wed Oct 3 22:15:05 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 3 Oct 2007 22:15:05 +0200 Subject: [Haiku-commits] r22424 - haiku/trunk/src/apps/aboutsystem Message-ID: <200710032015.l93KF570016525@sheep.berlios.de> Author: bonefish Date: 2007-10-03 22:15:05 +0200 (Wed, 03 Oct 2007) New Revision: 22424 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22424&view=rev Modified: haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp Log: Added the students who worked on the DDM and intel partitioning system. Modified: haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp =================================================================== --- haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp 2007-10-03 19:35:40 UTC (rev 22423) +++ haiku/trunk/src/apps/aboutsystem/AboutSystem.cpp 2007-10-03 20:15:05 UTC (rev 22424) @@ -394,12 +394,15 @@ "Jan Kl?tzke\n" "Marcin Konicki\n" "Kurtis Kopf\n" + "Tom?? Ku?era\n" + "Lubo? Kuli?\n" "Thomas Kurschel\n" "Elad Lahav\n" "Santiago Lema\n" "Oscar Lesta\n" "Jerome Leveque\n" "Graham MacDonald\n" + "Jan Mat?jek\n" "Brian Matzon\n" "Christopher ML Zumwalt May\n" "Andrew McCall\n" From marcusoverhagen at mail.berlios.de Wed Oct 3 22:16:12 2007 From: marcusoverhagen at mail.berlios.de (marcusoverhagen at BerliOS) Date: Wed, 3 Oct 2007 22:16:12 +0200 Subject: [Haiku-commits] r22425 - haiku/trunk/src/add-ons/kernel/busses/scsi/ahci Message-ID: <200710032016.l93KGCW5016719@sheep.berlios.de> Author: marcusoverhagen Date: 2007-10-03 22:16:11 +0200 (Wed, 03 Oct 2007) New Revision: 22425 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22425&view=rev Modified: haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci.c Log: added more IDs, removed Intel IDE mode ID due to possible collision with a physical PATA interface Modified: haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci.c =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci.c 2007-10-03 20:15:05 UTC (rev 22424) +++ haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci.c 2007-10-03 20:16:11 UTC (rev 22425) @@ -22,11 +22,29 @@ device_info sSupportedDevices[] = { + { 0x1002, 0x4380, "ATI SB600" }, + { 0x1002, 0x4390, "ATI SB700/800" }, { 0x1002, 0x4391, "ATI IXP700" }, + { 0x1002, 0x4392, "ATI SB700/800" }, + { 0x1002, 0x4393, "ATI SB700/800" }, + { 0x1002, 0x4394, "ATI SB700/800" }, + { 0x1002, 0x4395, "ATI SB700/800" }, + { 0x1039, 0x1184, "SiS 966" }, + { 0x1039, 0x1185, "SiS 966" }, + { 0x1039, 0x0186, "SiS 968" }, + { 0x10b9, 0x5288, "Acer Labs M5288" }, { 0x10de, 0x044c, "NVIDIA MCP65" }, { 0x10de, 0x044d, "NVIDIA MCP65" }, { 0x10de, 0x044e, "NVIDIA MCP65" }, { 0x10de, 0x044f, "NVIDIA MCP65" }, + { 0x10de, 0x045c, "NVIDIA MCP65" }, + { 0x10de, 0x045d, "NVIDIA MCP65" }, + { 0x10de, 0x045e, "NVIDIA MCP65" }, + { 0x10de, 0x045f, "NVIDIA MCP65" }, + { 0x10de, 0x0550, "NVIDIA MCP67" }, + { 0x10de, 0x0551, "NVIDIA MCP67" }, + { 0x10de, 0x0552, "NVIDIA MCP67" }, + { 0x10de, 0x0553, "NVIDIA MCP67" }, { 0x10de, 0x0554, "NVIDIA MCP67" }, { 0x10de, 0x0555, "NVIDIA MCP67" }, { 0x10de, 0x0556, "NVIDIA MCP67" }, @@ -59,19 +77,40 @@ { 0x10de, 0x0ad9, "NVIDIA MCP77" }, { 0x10de, 0x0ada, "NVIDIA MCP77" }, { 0x10de, 0x0adb, "NVIDIA MCP77" }, + { 0x1106, 0x3349, "VIA VT8251" }, + { 0x1106, 0x6287, "VIA VT8251" }, + { 0x11ab, 0x6145, "Marvell 6145" }, { 0x197b, 0x2360, "JMicron JMB360" }, { 0x197b, 0x2361, "JMicron JMB361" }, { 0x197b, 0x2362, "JMicron JMB362" }, { 0x197b, 0x2363, "JMicron JMB363" }, { 0x197b, 0x2366, "JMicron JMB366" }, + { 0x8086, 0x2652, "Intel ICH6R" }, + { 0x8086, 0x2653, "Intel ICH6-M" }, { 0x8086, 0x2681, "Intel 63xxESB" }, - { 0x8086, 0x27c0, "Intel ICH7 (IDE mode)" }, - { 0x8086, 0x27c1, "Intel ICH7 (AHCI mode)" }, - { 0x8086, 0x27c5, "Intel 82801GBM" }, - { 0x8086, 0x2821, "Intel 82801H" }, - { 0x8086, 0x2824, "Intel 82801H" }, - { 0x8086, 0x2922, "Intel 82801I" }, - { 0x8086, 0x2923, "Intel 82801I" }, + { 0x8086, 0x2682, "Intel ESB2" }, + { 0x8086, 0x2683, "Intel ESB2" }, + { 0x8086, 0x27c1, "Intel ICH7R (AHCI mode)" }, + { 0x8086, 0x27c3, "Intel ICH7R (RAID mode)" }, + { 0x8086, 0x27c5, "Intel ICH7-M (AHCI mode)" }, + { 0x8086, 0x27c6, "Intel ICH7-M DH (RAID mode)" }, + { 0x8086, 0x2821, "Intel ICH8 (AHCI mode)" }, + { 0x8086, 0x2822, "Intel ICH8R / ICH9 (RAID mode)" }, + { 0x8086, 0x2824, "Intel ICH8 (AHCI mode)" }, + { 0x8086, 0x2829, "Intel ICH8M (AHCI mode)" }, + { 0x8086, 0x282a, "Intel ICH8M (RAID mode)" }, + { 0x8086, 0x2922, "Intel ICH9 (AHCI mode)" }, + { 0x8086, 0x2923, "Intel ICH9 (AHCI mode)" }, + { 0x8086, 0x2924, "Intel ICH9" }, + { 0x8086, 0x2925, "Intel ICH9" }, + { 0x8086, 0x2927, "Intel ICH9" }, + { 0x8086, 0x2929, "Intel ICH9M" }, + { 0x8086, 0x292a, "Intel ICH9M" }, + { 0x8086, 0x292b, "Intel ICH9M" }, + { 0x8086, 0x292c, "Intel ICH9M" }, + { 0x8086, 0x292f, "Intel ICH9M" }, + { 0x8086, 0x294d, "Intel ICH9" }, + { 0x8086, 0x294e, "Intel ICH9M" }, {} }; From bonefish at cs.tu-berlin.de Wed Oct 3 23:06:36 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Wed, 03 Oct 2007 23:06:36 +0200 Subject: [Haiku-commits] r22299 - in haiku/trunk/src/add-ons/kernel/drivers/audio: . null In-Reply-To: <20071003201302.259290@gmx.net> References: <200709242309.l8ON9h2r015557@sheep.berlios.de> <20071003194627.259250@gmx.net> <20071003201302.259290@gmx.net> Message-ID: <20071003230636.4007.2@cs.tu-berlin.de> On 2007-10-03 at 22:13:02 [+0200], HOST Team wrote: [...] > Btw. is there an easy way to add a driver inside the UserBuildConfig? I did > not find any instruction on that in the sample file. I could of course add > the file and create the symlink itself, but is that a good solution? You can use the AddDriversToHaikuImage rule just as you would do it in HaikuImage. CU, Ingo From stippi at mail.berlios.de Wed Oct 3 23:19:18 2007 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Wed, 3 Oct 2007 23:19:18 +0200 Subject: [Haiku-commits] r22426 - haiku/trunk/src/add-ons/media/media-add-ons/mixer Message-ID: <200710032119.l93LJIvT023613@sheep.berlios.de> Author: stippi Date: 2007-10-03 23:19:17 +0200 (Wed, 03 Oct 2007) New Revision: 22426 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22426&view=rev Modified: haiku/trunk/src/add-ons/media/media-add-ons/mixer/AudioMixer.cpp haiku/trunk/src/add-ons/media/media-add-ons/mixer/AudioMixer.h haiku/trunk/src/add-ons/media/media-add-ons/mixer/ByteSwap.cpp haiku/trunk/src/add-ons/media/media-add-ons/mixer/ByteSwap.h haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerAddOn.cpp haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerAddOn.h haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerCore.cpp haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerCore.h haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerDebug.h haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerInput.cpp haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerInput.h haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerOutput.cpp haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerOutput.h haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerSettings.cpp haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerSettings.h Log: large patch by Bek (HOST team): * style improvements, header reformatting, small refactoring and adding of missing copyrights (to Marcus: this is not the original patch, it has already been revised two times by myself and I thought it was very nice now) Modified: haiku/trunk/src/add-ons/media/media-add-ons/mixer/AudioMixer.cpp =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/mixer/AudioMixer.cpp 2007-10-03 20:16:11 UTC (rev 22425) +++ haiku/trunk/src/add-ons/media/media-add-ons/mixer/AudioMixer.cpp 2007-10-03 21:19:17 UTC (rev 22426) @@ -1,26 +1,27 @@ -/* AudioMixer - * - * First implementation by David Shipman, 2002 - * Rewritten by Marcus Overhagen, 2003 +/* + * Copyright 2002 David Shipman, + * Copyright 2003-2007 Marcus Overhagen + * Copyright 2007 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. */ -#include +#include "AudioMixer.h" +#include "MixerCore.h" +#include "MixerInput.h" +#include "MixerOutput.h" +#include "MixerUtils.h" + #include -#include +#include +#include +#include #include -#include -#include #include -#include +#include #include #include -#include +#include +#include -#include "AudioMixer.h" -#include "MixerCore.h" -#include "MixerInput.h" -#include "MixerOutput.h" -#include "MixerUtils.h" - #define VERSION_STRING "0.4" #define BUILD_STRING __DATE__ " " __TIME__ @@ -34,7 +35,9 @@ #define USE_MEDIA_FORMAT_WORKAROUND 1 #if USE_MEDIA_FORMAT_WORKAROUND -static void multi_audio_format_specialize(media_multi_audio_format *format, const media_multi_audio_format *other); +static void +multi_audio_format_specialize(media_multi_audio_format *format, + const media_multi_audio_format *other); #endif #define FORMAT_USER_DATA_TYPE 0x7294a8f3 @@ -238,9 +241,11 @@ //PRINT(4, "buffer received at %12Ld, should arrive at %12Ld, delta %12Ld\n", TimeSource()->Now(), buffer->Header()->start_time, TimeSource()->Now() - buffer->Header()->start_time); -// HandleInputBuffer(buffer, 0); -// buffer->Recycle(); -// return; + // Note: The following code is outcommented on purpose + // and is about to be modified at a later point + // HandleInputBuffer(buffer, 0); + // buffer->Recycle(); + // return; // to receive the buffer at the right time, @@ -256,7 +261,9 @@ void AudioMixer::HandleInputBuffer(BBuffer *buffer, bigtime_t lateness) { -/* + // Note: The following code is outcommented on purpose + // and is about to be modified at a later point + /* if (lateness > 5000) { printf("Received buffer with way to high lateness %Ld\n", lateness); if (RunMode() != B_DROP_DATA) { @@ -267,20 +274,22 @@ return; } } -*/ + */ -// printf("Received buffer with lateness %Ld\n", lateness); + // printf("Received buffer with lateness %Ld\n", lateness); fCore->Lock(); fCore->BufferReceived(buffer, lateness); fCore->Unlock(); -/* + // Note: The following code is outcommented on purpose + // and is about to be modified at a later point + /* if ((B_OFFLINE == RunMode()) && (B_DATA_AVAILABLE == channel->fProducerDataStatus)) { RequestAdditionalBuffer(channel->fInput.source, buffer); } -*/ + */ } void @@ -316,10 +325,11 @@ *out_latency = EventLatency(); *out_timesource = TimeSource()->ID(); - printf("AudioMixer::GetLatencyFor %Ld, timesource is %ld\n", *out_latency, *out_timesource); + printf("AudioMixer::GetLatencyFor %Ld, timesource is %ld\n", + *out_latency, + *out_timesource); return B_OK; - } status_t @@ -331,13 +341,16 @@ // workaround for a crashing bug in RealPlayer. to be proper, RealPlayer's // BBufferProducer::PrepareToConnect() should have removed all wildcards. if (out_input->format.u.raw_audio.frame_rate == 0) { - fprintf(stderr, "Audio Mixer Warning: Producer (port %ld, id %ld) connected with frame_rate=0\n", producer.port, producer.id); + fprintf(stderr, "Audio Mixer Warning: " + "Producer (port %ld, id %ld) connected with frame_rate=0\n", + producer.port, + producer.id); MixerOutput *output = fCore->Output(); float frame_rate = output ? output->MediaOutput().format.u.raw_audio.frame_rate : 44100.0f; out_input->format.u.raw_audio.frame_rate = frame_rate; } - // a BBufferProducer is connection to our BBufferConsumer + // a BBufferProducer is connecting to our BBufferConsumer // incoming connections should always have an incoming ID=0, // and the port number must match our ControlPort() @@ -366,9 +379,9 @@ // If we want the producer to use a specific BBufferGroup, we now need to call // BMediaRoster::SetOutputBuffersFor() here to set the producer's buffer group. // But we have no special buffer requirements anyway... - + UpdateParameterWeb(); - + return B_OK; } @@ -376,7 +389,7 @@ AudioMixer::Disconnected(const media_source &producer, const media_destination &where) { // One of our inputs has been disconnected - + // check if it is really belongs to us if (where.port != ControlPort()) { TRACE("AudioMixer::Disconnected wrong input port\n"); @@ -390,7 +403,6 @@ } fCore->Unlock(); - UpdateParameterWeb(); } @@ -402,7 +414,7 @@ // we will receive buffers in a different format TRACE("AudioMixer::FormatChanged\n"); - + if (consumer.port != ControlPort() || consumer.id == 0) return B_MEDIA_BAD_DESTINATION; @@ -467,6 +479,11 @@ return B_OK; } +// If the format isn't good, put a good format into *io_format and return error +// If format has wildcard, specialize to what you can do (and change). +// If you can change the format, return OK. +// The request comes from your destination sychronously, so you cannot ask it +// whether it likes it -- you should assume it will since it asked. status_t AudioMixer::FormatChangeRequested(const media_source &source, const media_destination &destination, media_format *io_format, int32 *_deprecated_) @@ -498,8 +515,6 @@ if (destination.port == output->MediaOutput().destination.port && destination.id == output->MediaOutput().destination.id + 1) { ERROR("AudioMixer::FormatChangeRequested: this might be the broken R5 multi audio add-on\n"); goto err; -// fCore->Unlock(); -// return B_OK; } else { goto err; } @@ -583,21 +598,23 @@ status_t AudioMixer::DisposeOutputCookie(int32 cookie) { - // nothin to do + // nothing to do return B_OK; } status_t AudioMixer::SetBufferGroup(const media_source &for_source, BBufferGroup *newGroup) { - printf("#############################AudioMixer::SetBufferGroup\n"); + PRINT("AudioMixer::SetBufferGroup\n"); // the downstream consumer (soundcard) node asks us to use another // BBufferGroup (might be NULL). We only have one output (id 0) if (for_source.port != ControlPort() || for_source.id != 0) return B_MEDIA_BAD_SOURCE; - if (newGroup == fBufferGroup) // we're already using this buffergroup + if (newGroup == fBufferGroup) { + // we're already using this buffergroup return B_OK; + } fCore->Lock(); if (!newGroup) @@ -654,11 +671,13 @@ } status_t -AudioMixer::PrepareToConnect(const media_source &what, const media_destination &where, - media_format *format, media_source *out_source, char *out_name) +AudioMixer::PrepareToConnect(const media_source &what, + const media_destination &where, + media_format *format, + media_source *out_source, + char *out_name) { TRACE("AudioMixer::PrepareToConnect\n"); - // PrepareToConnect() is the second stage of format negotiations that happens // inside BMediaRoster::Connect(). At this point, the consumer's AcceptFormat() // method has been called, and that node has potentially changed the proposed @@ -753,14 +772,14 @@ fCore->AddOutput(output); fCore->Unlock(); - return B_OK; } - void -AudioMixer::Connect(status_t error, const media_source &source, const media_destination &dest, - const media_format &format, char *io_name) +AudioMixer::Connect(status_t error, const media_source &source, + const media_destination &dest, + const media_format &format, + char *io_name) { TRACE("AudioMixer::Connect\n"); @@ -837,17 +856,13 @@ fCore->Settings()->LoadConnectionSettings(fCore->Output()); fCore->Unlock(); - UpdateParameterWeb(); } - void AudioMixer::Disconnect(const media_source &what, const media_destination &where) { - TRACE("AudioMixer::Disconnect\n"); - fCore->Lock(); // Make sure that our connection is the one being disconnected @@ -858,9 +873,8 @@ return; } - /* Switch our prefered format back to default - * frame rate and channel count. - */ + // Switch our prefered format back to default + // frame rate and channel count. fDefaultFormat.u.raw_audio.frame_rate = 96000; fDefaultFormat.u.raw_audio.channel_count = 2; @@ -875,7 +889,6 @@ fCore->SetOutputBufferGroup(0); fCore->Unlock(); - UpdateParameterWeb(); } @@ -887,8 +900,9 @@ // is the only runmode in which we can do anything about this ERROR("AudioMixer::LateNoticeReceived, %Ld too late at %Ld\n", how_much, performance_time); - -/* + // Note: The following code is outcommented on purpose + // and is about to be modified at a later point + /* if (what == fOutput.source) { if (RunMode() == B_INCREASE_LATENCY) { fInternalLatency += how_much; @@ -902,7 +916,7 @@ PublishEventLatencyChange(); } } -*/ + */ } @@ -986,7 +1000,7 @@ } } - + // // AudioMixer methods // @@ -1016,18 +1030,19 @@ BBufferGroup * AudioMixer::CreateBufferGroup() { - // allocate enough buffers to span our downstream latency (plus one for rounding up), plus one extra + // allocate enough buffers to span our downstream latency + // (plus one for rounding up), plus one extra int32 count = int32(fDownstreamLatency / BufferDuration()) + 2; TRACE("AudioMixer::CreateBufferGroup: fDownstreamLatency %Ld, BufferDuration %Ld, buffer count = %ld\n", fDownstreamLatency, BufferDuration(), count); if (count < 3) count = 3; - + fCore->Lock(); uint32 size = fCore->Output()->MediaOutput().format.u.raw_audio.buffer_size; fCore->Unlock(); - + TRACE("AudioMixer: allocating %ld buffers of %ld bytes each\n", count, size); return new BBufferGroup(size, count); } @@ -1672,11 +1687,14 @@ dp = group->MakeDiscreteParameter(PARAM_ETC(70), B_MEDIA_RAW_AUDIO, "Resampling algorithm", B_INPUT_MUX); dp->AddItem(0, "Drop/repeat samples"); -/* + + // Note: The following code is outcommented on purpose + // and is about to be modified at a later point + /* dp->AddItem(1, "Drop/repeat samples (template based)"); dp->AddItem(2, "Linear interpolation"); dp->AddItem(3, "17th order filtering"); -*/ + */ group->MakeDiscreteParameter(PARAM_ETC(80), B_MEDIA_RAW_AUDIO, "Refuse output format changes", B_ENABLE); group->MakeDiscreteParameter(PARAM_ETC(90), B_MEDIA_RAW_AUDIO, "Refuse input format changes", B_ENABLE); @@ -1691,7 +1709,6 @@ , B_GENERIC); fCore->Unlock(); - SetParameterWeb(web); } Modified: haiku/trunk/src/add-ons/media/media-add-ons/mixer/AudioMixer.h =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/mixer/AudioMixer.h 2007-10-03 20:16:11 UTC (rev 22425) +++ haiku/trunk/src/add-ons/media/media-add-ons/mixer/AudioMixer.h 2007-10-03 21:19:17 UTC (rev 22426) @@ -1,205 +1,141 @@ -// AudioMixer.h /* - - By David Shipman, 2002 - -*/ - + * Copyright 2002 David Shipman, + * Copyright 2003-2007 Marcus Overhagen + * Copyright 2007 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef _AUDIOMIXER_H #define _AUDIOMIXER_H -// forward declarations +#include +#include +#include +#include +#include +#include class MixerCore; - -// includes - -#include -#include -#include -#include -#include -#include - -// ---------------- -// AudioMixer class - class AudioMixer : public BBufferConsumer, public BBufferProducer, public BControllable, public BMediaEventLooper { - public: - - AudioMixer(BMediaAddOn *addOn, bool isSystemMixer); - ~AudioMixer(); - - + AudioMixer(BMediaAddOn *addOn, bool isSystemMixer); + ~AudioMixer(); + void DisableNodeStop(); - // AudioMixer support - + // AudioMixer support void ApplySettings(); - void PublishEventLatencyChange(); + void PublishEventLatencyChange(); void UpdateParameterWeb(); - + void HandleInputBuffer(BBuffer *buffer, bigtime_t lateness); - + BBufferGroup * CreateBufferGroup(); - + float dB_to_Gain(float db); float Gain_to_dB(float gain); - - // BMediaNode methods - BMediaAddOn * AddOn(int32*) const; - // void SetRunMode(run_mode); - // void Preroll(); - // status_t RequestCompleted(const media_request_info & info); + // BMediaNode methods + BMediaAddOn * AddOn(int32 *internal_id) const; void NodeRegistered(); void Stop(bigtime_t performance_time, bool immediate); void SetTimeSource(BTimeSource * time_source); - using BBufferProducer::SendBuffer; - + protected: - - // BControllable methods - - status_t GetParameterValue( int32 id, bigtime_t* last_change, - void* value, - size_t* ioSize); + // BControllable methods + status_t GetParameterValue(int32 id, + bigtime_t *last_change, + void *value, + size_t *ioSize); - void SetParameterValue( int32 id, bigtime_t when, - const void* value, - size_t size); - - // BBufferConsumer methods - - status_t HandleMessage( int32 message, - const void* data, - size_t size); - - status_t AcceptFormat( const media_destination &dest, media_format *format); - - status_t GetNextInput( int32 *cookie, - media_input *out_input); - - void DisposeInputCookie( int32 cookie); - - void BufferReceived( BBuffer *buffer); - - void ProducerDataStatus( const media_destination &for_whom, - int32 status, - bigtime_t at_performance_time); - - status_t GetLatencyFor( const media_destination &for_whom, - bigtime_t *out_latency, - media_node_id *out_timesource); - - status_t Connected( const media_source &producer, - const media_destination &where, - const media_format &with_format, - media_input *out_input); - - void Disconnected( const media_source &producer, - const media_destination &where); - - status_t FormatChanged( const media_source &producer, - const media_destination &consumer, - int32 change_tag, - const media_format &format); + void SetParameterValue(int32 id, bigtime_t when, + const void *value, + size_t size); - - // - // BBufferProducer methods - // - - status_t FormatSuggestionRequested( media_type type, - int32 quality, - media_format *format); - - status_t FormatProposal( - const media_source& output, - media_format* format); -// -// /* If the format isn't good, put a good format into *io_format and return error */ -// /* If format has wildcard, specialize to what you can do (and change). */ -// /* If you can change the format, return OK. */ -// /* The request comes from your destination sychronously, so you cannot ask it */ -// /* whether it likes it -- you should assume it will since it asked. */ - status_t FormatChangeRequested( - const media_source& source, - const media_destination& destination, - media_format* io_format, - int32* _deprecated_); + // BBufferConsumer methods + status_t HandleMessage(int32 message, const void* data, + size_t size); + status_t AcceptFormat(const media_destination &dest, + media_format *format); + status_t GetNextInput(int32 *cookie, + media_input *out_input); + void DisposeInputCookie(int32 cookie); + void BufferReceived(BBuffer *buffer); + void ProducerDataStatus(const media_destination &for_whom, + int32 status, + bigtime_t at_performance_time); + status_t GetLatencyFor(const media_destination &for_whom, + bigtime_t *out_latency, + media_node_id *out_timesource); + status_t Connected(const media_source &producer, + const media_destination &where, + const media_format &with_format, + media_input *out_input); + void Disconnected(const media_source &producer, + const media_destination &where); + status_t FormatChanged(const media_source &producer, + const media_destination &consumer, + int32 change_tag, + const media_format &format); - status_t GetNextOutput( /* cookie starts as 0 */ - int32* cookie, - media_output* out_output); + // BBufferProducer methods + status_t FormatSuggestionRequested(media_type type, + int32 quality, + media_format *format); + status_t FormatProposal(const media_source &output, + media_format *format); + status_t FormatChangeRequested( + const media_source& source, + const media_destination &destination, + media_format *io_format, + int32 *_deprecated_); + status_t GetNextOutput(int32 *cookie,media_output *out_output); + status_t DisposeOutputCookie(int32 cookie); + status_t SetBufferGroup(const media_source &for_source, + BBufferGroup *group); + status_t GetLatency(bigtime_t *out_latency); + status_t PrepareToConnect(const media_source &what, + const media_destination &where, + media_format *format, + media_source *out_source, + char *out_name); + void Connect(status_t error, + const media_source &source, + const media_destination &destination, + const media_format &format, + char *io_name); + void Disconnect(const media_source &what, + const media_destination &where); + void LateNoticeReceived(const media_source &what, + bigtime_t how_much, + bigtime_t performance_time); + void EnableOutput(const media_source &what, + bool enabled, + int32 *_deprecated_); + void LatencyChanged(const media_source &source, + const media_destination &destination, + bigtime_t new_latency, uint32 flags); - status_t DisposeOutputCookie( - int32 cookie); + // BMediaEventLooper methods + void HandleEvent(const media_timed_event *event, + bigtime_t lateness, + bool realTimeEvent = false); - status_t SetBufferGroup( - const media_source& for_source, - BBufferGroup* group); - - status_t GetLatency( - bigtime_t* out_latency); - - status_t PrepareToConnect( - const media_source& what, - const media_destination& where, - media_format* format, - media_source* out_source, - char* out_name); - - void Connect( - status_t error, - const media_source& source, - const media_destination& destination, - const media_format& format, - char* io_name); - - void Disconnect( - const media_source& what, - const media_destination& where); - - void LateNoticeReceived( - const media_source& what, - bigtime_t how_much, - bigtime_t performance_time); - - void EnableOutput( - const media_source & what, - bool enabled, - int32* _deprecated_); - - void LatencyChanged(const media_source & source, - const media_destination & destination, - bigtime_t new_latency, uint32 flags); - - // BMediaEventLooper methods - - void HandleEvent( const media_timed_event *event, - bigtime_t lateness, - bool realTimeEvent = false); - - private: - BMediaAddOn *fAddOn; - MixerCore *fCore; - BParameterWeb *fWeb; // local pointer to parameterweb - BBufferGroup *fBufferGroup; - bigtime_t fDownstreamLatency; - bigtime_t fInternalLatency; - bool fDisableStop; - media_format fDefaultFormat; -}; - + BMediaAddOn *fAddOn; + MixerCore *fCore; + BParameterWeb *fWeb; // local pointer to parameterweb + BBufferGroup *fBufferGroup; + bigtime_t fDownstreamLatency; + bigtime_t fInternalLatency; + bool fDisableStop; + media_format fDefaultFormat; +}; #endif Modified: haiku/trunk/src/add-ons/media/media-add-ons/mixer/ByteSwap.cpp =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/mixer/ByteSwap.cpp 2007-10-03 20:16:11 UTC (rev 22425) +++ haiku/trunk/src/add-ons/media/media-add-ons/mixer/ByteSwap.cpp 2007-10-03 21:19:17 UTC (rev 22426) @@ -1,14 +1,14 @@ -/* Copyright (C) 2003 Marcus Overhagen - * Released under terms of the MIT license. - * - * A simple byte order swapping class for the audio mixer. +/* + * Copyright 2003-2007 Marcus Overhagen + * Copyright 2007 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. */ - -#include -#include #include "ByteSwap.h" #include "MixerDebug.h" +#include +#include + static void swap_float(void *buffer, size_t bytecount); static void swap_int32(void *buffer, size_t bytecount); static void swap_int16(void *buffer, size_t bytecount); @@ -48,13 +48,15 @@ void swap_float(void *buffer, size_t bytecount) { - swap_data(B_FLOAT_TYPE, buffer, bytecount, B_SWAP_ALWAYS); // XXX should be optimized + // XXX Should be optimized + swap_data(B_FLOAT_TYPE, buffer, bytecount, B_SWAP_ALWAYS); } void swap_int32(void *buffer, size_t bytecount) { - swap_data(B_INT32_TYPE, buffer, bytecount, B_SWAP_ALWAYS); // XXX should be optimized + // XXX Should be optimized + swap_data(B_INT32_TYPE, buffer, bytecount, B_SWAP_ALWAYS); } void @@ -130,5 +132,4 @@ { swap_data(B_INT16_TYPE, buffer, bytecount, B_SWAP_ALWAYS); } - #endif Modified: haiku/trunk/src/add-ons/media/media-add-ons/mixer/ByteSwap.h =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/mixer/ByteSwap.h 2007-10-03 20:16:11 UTC (rev 22425) +++ haiku/trunk/src/add-ons/media/media-add-ons/mixer/ByteSwap.h 2007-10-03 21:19:17 UTC (rev 22426) @@ -1,22 +1,23 @@ +/* + * Copyright 2003-2007 Marcus Overhagen + * Copyright 2007 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef _BYTE_SWAP_H #define _BYTE_SWAP_H -/* Copyright (C) 2003 Marcus Overhagen - * Released under terms of the MIT license. - * - * A simple byte order swapping class for the audio mixer. - */ +#include class ByteSwap { -public: - ByteSwap(uint32 format); - ~ByteSwap(); + public: + ByteSwap(uint32 format); + ~ByteSwap(); - void Swap(void *buffer, size_t bytecount); + void Swap(void *buffer, size_t bytecount); -private: - void (*fFunc)(void *, size_t); + private: + void (*fFunc)(void *, size_t); }; inline void @@ -24,5 +25,4 @@ { (*fFunc)(buffer, bytecount); } - #endif Modified: haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerAddOn.cpp =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerAddOn.cpp 2007-10-03 20:16:11 UTC (rev 22425) +++ haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerAddOn.cpp 2007-10-03 21:19:17 UTC (rev 22426) @@ -1,11 +1,9 @@ -// MixerAddOn.cpp -// -// David Shipman, 2002 -// Marcus Overhagen, 2003 -// -// Allows AudioMixer to be used as an addon. -// The add-on will request to be auto-started. - +/* + * Copyright 2002 David Shipman, + * Copyright 2003-2007 Marcus Overhagen + * Copyright 2007 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ #include #include #include @@ -19,21 +17,15 @@ return new AudioMixerAddon(image); } -// ------------------------------------------------------- // -// ctor/dtor -// -------------------------------------------------------- // - AudioMixerAddon::AudioMixerAddon(image_id image) - : BMediaAddOn(image), - fFormat(new media_format), - fInfo(new flavor_info) + : BMediaAddOn(image), + fFormat(new media_format), + fInfo(new flavor_info) { - // Init media_format memset(fFormat, 0, sizeof(*fFormat)); fFormat->type = B_MEDIA_RAW_AUDIO; fFormat->u.raw_audio = media_raw_audio_format::wildcard; - // Init flavor_info fInfo->internal_id = 0; fInfo->name = "Audio Mixer (Haiku)"; fInfo->info = "Haiku Audio Mixer media addon"; @@ -96,13 +88,12 @@ bool AudioMixerAddon::WantsAutoStart() { - // yes, please kick me return true; } status_t -AudioMixerAddon::AutoStart(int in_index, BMediaNode ** out_node, - int32 * out_internal_id, bool * out_has_more) +AudioMixerAddon::AutoStart(int in_index, BMediaNode **out_node, + int32 *out_internal_id, bool *out_has_more) { *out_has_more = false; Modified: haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerAddOn.h =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerAddOn.h 2007-10-03 20:16:11 UTC (rev 22425) +++ haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerAddOn.h 2007-10-03 21:19:17 UTC (rev 22426) @@ -1,49 +1,39 @@ -// MixerAddon.h -// David Shipman, 2002 -// -// Quick addon header for the Audio Mixer -// +/* + * Copyright 2002 David Shipman, + * Copyright 2003-2007 Marcus Overhagen + * Copyright 2007 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _AUDIOMIXER_ADDON_H +#define _AUDIOMIXER_ADDON_H -#ifndef __AudioMixerAddOn_H_ -#define __AudioMixerAddOn_H_ - #include -// -------------------------------------------------------- // - -class AudioMixerAddon : - public BMediaAddOn { - typedef BMediaAddOn _inherited; +class AudioMixerAddon : public BMediaAddOn { + public: + virtual ~AudioMixerAddon(); + explicit AudioMixerAddon(image_id image); -public: // ctor/dtor - virtual ~AudioMixerAddon(); - explicit AudioMixerAddon(image_id image); - -public: // BMediaAddOn impl -virtual status_t InitCheck( - const char** out_failure_text); -virtual int32 CountFlavors(); -virtual status_t GetFlavorAt( - int32 n, - const flavor_info ** out_info); -virtual BMediaNode * InstantiateNodeFor( - const flavor_info * info, - BMessage * config, - status_t * out_error); -virtual status_t GetConfigurationFor( - BMediaNode * your_node, - BMessage * into_message); + virtual status_t InitCheck(const char** out_failure_text); + virtual int32 CountFlavors(); + virtual status_t GetFlavorAt(int32 n, + const flavor_info ** out_info); + virtual BMediaNode * InstantiateNodeFor( + const flavor_info *info, + BMessage *config, + status_t *out_error); + virtual status_t GetConfigurationFor( + BMediaNode *your_node, + BMessage *into_message); -virtual bool WantsAutoStart(); -virtual status_t AutoStart( - int in_index, - BMediaNode ** out_node, - int32 * out_internal_id, - bool * out_has_more); + virtual bool WantsAutoStart(); + virtual status_t AutoStart(int in_index, + BMediaNode **out_node, + int32 *out_internal_id, + bool *out_has_more); -private: - media_format *fFormat; - flavor_info *fInfo; + private: + media_format *fFormat; + flavor_info *fInfo; }; - -#endif /*__AudioMixerAddOn_H_*/ +#endif Modified: haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerCore.cpp =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerCore.cpp 2007-10-03 20:16:11 UTC (rev 22425) +++ haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerCore.cpp 2007-10-03 21:19:17 UTC (rev 22426) @@ -1,19 +1,27 @@ -#include -#include -#include -#include -#include -#include -#include -#include +/* + * Copyright 2007 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Marcus Overhagen + */ +#include "AudioMixer.h" #include "MixerCore.h" #include "MixerInput.h" #include "MixerOutput.h" #include "MixerUtils.h" -#include "AudioMixer.h" #include "Resampler.h" #include "RtList.h" +#include +#include +#include +#include +#include +#include +#include +#include + #define DOUBLE_RATE_MIXING 0 #if DEBUG > 1 @@ -49,10 +57,10 @@ fMixBufferFrameCount(0), fMixBufferChannelCount(0), fMixBufferChannelTypes(0), - fDoubleRateMixing(DOUBLE_RATE_MIXING), - fDownstreamLatency(1), - fSettings(new MixerSettings), - fNode(node), + fDoubleRateMixing(DOUBLE_RATE_MIXING), + fDownstreamLatency(1), + fSettings(new MixerSettings), [... truncated: 1233 lines follow ...] From bonefish at mail.berlios.de Thu Oct 4 00:10:06 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Thu, 4 Oct 2007 00:10:06 +0200 Subject: [Haiku-commits] r22427 - haiku/trunk/src/system/boot/loader/file_systems/tarfs Message-ID: <200710032210.l93MA6e4029282@sheep.berlios.de> Author: bonefish Date: 2007-10-04 00:10:06 +0200 (Thu, 04 Oct 2007) New Revision: 22427 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22427&view=rev Modified: haiku/trunk/src/system/boot/loader/file_systems/tarfs/Jamfile Log: Define _BOOT_MODE. Modified: haiku/trunk/src/system/boot/loader/file_systems/tarfs/Jamfile =================================================================== --- haiku/trunk/src/system/boot/loader/file_systems/tarfs/Jamfile 2007-10-03 21:19:17 UTC (rev 22426) +++ haiku/trunk/src/system/boot/loader/file_systems/tarfs/Jamfile 2007-10-03 22:10:06 UTC (rev 22427) @@ -7,8 +7,9 @@ UsePrivateHeaders kernel shared storage ; SubDirSysHdrs $(HAIKU_TOP) headers libs zlib ; -SubDirC++Flags -fno-rtti ; -#SubDirCcFlags -DGUNZIP=1 ; +local defines = [ FDefines _BOOT_MODE ] ; +SubDirCcFlags $(defines) ; +SubDirC++Flags -fno-rtti $(defines) ; SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src libs zlib ] ; From bonefish at mail.berlios.de Thu Oct 4 00:14:54 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Thu, 4 Oct 2007 00:14:54 +0200 Subject: [Haiku-commits] r22428 - in haiku/trunk: headers/private/kernel src/system/kernel/debug Message-ID: <200710032214.l93MEsA3029786@sheep.berlios.de> Author: bonefish Date: 2007-10-04 00:14:53 +0200 (Thu, 04 Oct 2007) New Revision: 22428 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22428&view=rev Modified: haiku/trunk/headers/private/kernel/debug.h haiku/trunk/src/system/kernel/debug/debug.c Log: Added function dprintf_no_syslog(). It is basically equivalent to dprintf() with the exception that it doesn't write anything to the syslog. The reason is that syslog_write() releases a semaphore and can therefore not be invoked when the thread spinlock is held. Modified: haiku/trunk/headers/private/kernel/debug.h =================================================================== --- haiku/trunk/headers/private/kernel/debug.h 2007-10-03 22:10:06 UTC (rev 22427) +++ haiku/trunk/headers/private/kernel/debug.h 2007-10-03 22:14:53 UTC (rev 22428) @@ -9,7 +9,7 @@ #define _KERNEL_DEBUG_H -#include +#include #define KDEBUG 1 @@ -27,7 +27,7 @@ #define ASSERT_ALWAYS_PRINT(x, format...) \ do { \ if (!(x)) { \ - dprintf(format); \ + dprintf_no_syslog(format); \ panic("ASSERT FAILED (%s:%d): %s\n", __FILE__, __LINE__, #x); \ } \ } while (0) @@ -56,6 +56,9 @@ extern bool debug_debugger_running(void); extern void debug_stop_screen_debug_output(void); +extern void dprintf_no_syslog(const char *format, ...) + __attribute__ ((format (__printf__, 1, 2))); + extern void _user_debug_output(const char *userString); #ifdef __cplusplus Modified: haiku/trunk/src/system/kernel/debug/debug.c =================================================================== --- haiku/trunk/src/system/kernel/debug/debug.c 2007-10-03 22:10:06 UTC (rev 22427) +++ haiku/trunk/src/system/kernel/debug/debug.c 2007-10-03 22:14:53 UTC (rev 22428) @@ -972,16 +972,12 @@ } -void -dprintf(const char *format, ...) +static void +dprintf_args(const char *format, va_list args, bool syslogOutput) { cpu_status state; - va_list args; int32 length; - if (!sSerialDebugEnabled && !sSyslogOutputEnabled && !sBlueScreenEnabled) - return; - // ToDo: maybe add a non-interrupt buffer and path that only // needs to acquire a semaphore instead of needing to disable // interrupts? @@ -989,9 +985,7 @@ state = disable_interrupts(); acquire_spinlock(&sSpinlock); - va_start(args, format); length = vsnprintf(sOutputBuffer, OUTPUT_BUFFER_SIZE, format, args); - va_end(args); if (length >= OUTPUT_BUFFER_SIZE) length = OUTPUT_BUFFER_SIZE - 1; @@ -1005,7 +999,7 @@ if (sSerialDebugEnabled) arch_debug_serial_puts(sOutputBuffer); - if (sSyslogOutputEnabled) + if (syslogOutput) syslog_write(sOutputBuffer, length); if (sBlueScreenEnabled || sDebugScreenEnabled) blue_screen_puts(sOutputBuffer); @@ -1019,6 +1013,34 @@ } +void +dprintf(const char *format, ...) +{ + va_list args; + + if (!sSerialDebugEnabled && !sSyslogOutputEnabled && !sBlueScreenEnabled) + return; + + va_start(args, format); + dprintf_args(format, args, sSyslogOutputEnabled); + va_end(args); +} + + +void +dprintf_no_syslog(const char *format, ...) +{ + va_list args; + + if (!sSerialDebugEnabled && !sBlueScreenEnabled) + return; + + va_start(args, format); + dprintf_args(format, args, false); + va_end(args); +} + + /** Similar to dprintf() but thought to be used in the kernel * debugger only (it doesn't lock). */ From bonefish at mail.berlios.de Thu Oct 4 00:20:30 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Thu, 4 Oct 2007 00:20:30 +0200 Subject: [Haiku-commits] r22429 - haiku/trunk/src/system/kernel Message-ID: <200710032220.l93MKUPc030383@sheep.berlios.de> Author: bonefish Date: 2007-10-04 00:20:30 +0200 (Thu, 04 Oct 2007) New Revision: 22429 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22429&view=rev Modified: haiku/trunk/src/system/kernel/team.cpp Log: Move the job control entries of a dying team's children to the kernel team as well. Otherwise the children would later try to remove them from a list they weren't in. Modified: haiku/trunk/src/system/kernel/team.cpp =================================================================== --- haiku/trunk/src/system/kernel/team.cpp 2007-10-03 22:14:53 UTC (rev 22428) +++ haiku/trunk/src/system/kernel/team.cpp 2007-10-03 22:20:30 UTC (rev 22429) @@ -402,6 +402,15 @@ remove_team_from_parent(team, child); insert_team_into_parent(sKernelTeam, child); } + + // move job control entries too + sKernelTeam->stopped_children->entries.MoveFrom( + &team->stopped_children->entries); + sKernelTeam->continued_children->entries.MoveFrom( + &team->continued_children->entries); + + // Note, we don't move the dead children entries. Those will be deleted + // when the team structure is deleted. } @@ -2050,7 +2059,7 @@ /*! Sets the team's job control state. - Interrupts must be disabled and the team lock being held. + Interrupts must be disabled and the team lock be held. \a threadsLocked indicates whether the thread lock is being held, too. */ void From bonefish at mail.berlios.de Thu Oct 4 00:22:21 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Thu, 4 Oct 2007 00:22:21 +0200 Subject: [Haiku-commits] r22430 - haiku/trunk/headers/private/kernel/util Message-ID: <200710032222.l93MMLfR030605@sheep.berlios.de> Author: bonefish Date: 2007-10-04 00:22:21 +0200 (Thu, 04 Oct 2007) New Revision: 22430 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22430&view=rev Modified: haiku/trunk/headers/private/kernel/util/DoublyLinkedList.h Log: Some KDEBUG enabled sanity checks. Modified: haiku/trunk/headers/private/kernel/util/DoublyLinkedList.h =================================================================== --- haiku/trunk/headers/private/kernel/util/DoublyLinkedList.h 2007-10-03 22:20:30 UTC (rev 22429) +++ haiku/trunk/headers/private/kernel/util/DoublyLinkedList.h 2007-10-03 22:22:21 UTC (rev 22430) @@ -9,10 +9,14 @@ #include #ifdef _KERNEL_MODE +# include # include + +# if !defined(_BOOT_MODE) && KDEBUG +# define DEBUG_DOUBLY_LINKED_LIST KDEBUG +# endif #endif - #ifdef __cplusplus // DoublyLinkedListLink @@ -381,6 +385,11 @@ DOUBLY_LINKED_LIST_CLASS_NAME::Insert(Element *element, bool back) { if (element) { +#if DEBUG_DOUBLY_LINKED_LIST + ASSERT_PRINT(fFirst == NULL ? fLast == NULL : fLast != NULL, + "list: %p\n", this); +#endif + if (back) { // append Link *elLink = sGetLink(element); @@ -417,6 +426,11 @@ if (element == NULL) return; +#if DEBUG_DOUBLY_LINKED_LIST + ASSERT_PRINT(fFirst == NULL ? fLast == NULL : fLast != NULL, + "list: %p\n", this); +#endif + Link *beforeLink = sGetLink(before); Link *link = sGetLink(element); @@ -444,6 +458,12 @@ DOUBLY_LINKED_LIST_CLASS_NAME::Remove(Element *element) { if (element) { +#if DEBUG_DOUBLY_LINKED_LIST + ASSERT_PRINT(fFirst != NULL && fLast != NULL + && (fFirst != fLast || element == fFirst), + "list: %p, element: %p\n", this, element); +#endif + Link *elLink = sGetLink(element); if (elLink->previous) sGetLink(elLink->previous)->next = elLink->next; From bonefish at mail.berlios.de Thu Oct 4 00:53:20 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Thu, 4 Oct 2007 00:53:20 +0200 Subject: [Haiku-commits] r22431 - haiku/trunk/src/tests/kits/interface/layout Message-ID: <200710032253.l93MrKtx010407@sheep.berlios.de> Author: bonefish Date: 2007-10-04 00:53:19 +0200 (Thu, 04 Oct 2007) New Revision: 22431 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22431&view=rev Modified: haiku/trunk/src/tests/kits/interface/layout/LayoutTest1.cpp Log: The toggledView variable was assigned twice. The last assignment should win. Interestingly with gcc 4 and optimizations enabled the same value was passed twice to Add(). Modified: haiku/trunk/src/tests/kits/interface/layout/LayoutTest1.cpp =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/LayoutTest1.cpp 2007-10-03 22:22:21 UTC (rev 22430) +++ haiku/trunk/src/tests/kits/interface/layout/LayoutTest1.cpp 2007-10-03 22:53:19 UTC (rev 22431) @@ -350,7 +350,7 @@ // row 3 .AddGroup(B_HORIZONTAL, 10, 3) .Add(new TestView(), 3) - .Add(toggledView = new TestView(), 2) + .Add(new TestView(), 2) .Add(new TestView(), 1) .End() .End() From korli at users.berlios.de Thu Oct 4 10:30:37 2007 From: korli at users.berlios.de (=?ISO-8859-1?Q?J=E9r=F4me_Duval?=) Date: Thu, 4 Oct 2007 10:30:37 +0200 Subject: [Haiku-commits] r22299 - in haiku/trunk/src/add-ons/kernel/drivers/audio: . null In-Reply-To: <20071003201302.259290@gmx.net> References: <200709242309.l8ON9h2r015557@sheep.berlios.de> <20071003194627.259250@gmx.net> <20071003201302.259290@gmx.net> Message-ID: 2007/10/3, HOST Team : > Sorry, I was a little bit overhasty here. > You're welcome :) Bye, J?r?me From axeld at pinc-software.de Thu Oct 4 13:31:03 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Thu, 04 Oct 2007 13:31:03 +0200 CEST Subject: [Haiku-commits] =?iso-8859-15?q?r22416_-_in_haiku/trunk=3A_header?= =?iso-8859-15?q?s/os/drivers_headers/os/kernel_headers/private/kernel_hea?= =?iso-8859-15?q?ders/private/kernel/fs__headers/private/userlandfs/privat?= =?iso-8859-15?q?e_src/add-ons/kernel/drivers/random__src/add-ons/kernel/d?= =?iso-8859-15?q?rivers/tty_src/add-ons/kernel/file=5Fsystems/userlandfs/k?= =?iso-8859-15?q?ernel=5Fadd=5Fon_src/add-ons/kernel/file=5Fsystems/userla?= =?iso-8859-15?q?ndfs/server_src/add-ons/kernel/network/stack_src/system/k?= =?iso-8859-15?q?ernel_src/system/kernel/fs__src/system/libroot/os?= In-Reply-To: <200710021947.l92JlZWh016478@sheep.berlios.de> Message-ID: <7694756459-BeMail@zon> bonefish at BerliOS wrote: > * Removed the "ref" parameter from notify_select_events() and the > select_sync_pool functions as well as from fd_ops::fd_[de]select(). > It > is no longer needed. The FS interface select() hook still has it, > though -- the VFS will always pass 0. Is there any reason to keep the "ref" argument then? If not, I would remove it now. Bye, Axel. From jackburton at mail.berlios.de Thu Oct 4 13:32:07 2007 From: jackburton at mail.berlios.de (jackburton at BerliOS) Date: Thu, 4 Oct 2007 13:32:07 +0200 Subject: [Haiku-commits] r22432 - in haiku/trunk: headers/os/interface src/kits/interface Message-ID: <200710041132.l94BW7A9014853@sheep.berlios.de> Author: jackburton Date: 2007-10-04 13:32:06 +0200 (Thu, 04 Oct 2007) New Revision: 22432 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22432&view=rev Modified: haiku/trunk/headers/os/interface/TextView.h haiku/trunk/src/kits/interface/TextInput.cpp haiku/trunk/src/kits/interface/TextInput.h haiku/trunk/src/kits/interface/TextView.cpp Log: Patch by Rene Gollent: TextViews now can scroll even if they aren't attached to a BScrollView. Modified: haiku/trunk/headers/os/interface/TextView.h =================================================================== --- haiku/trunk/headers/os/interface/TextView.h 2007-10-03 22:53:19 UTC (rev 22431) +++ haiku/trunk/headers/os/interface/TextView.h 2007-10-04 11:32:06 UTC (rev 22432) @@ -255,6 +255,7 @@ undo_state UndoState(bool *isRedo) const; protected: +void _ScrollToOffset(int32 nOffset, bool useHorz, bool useVert); virtual void GetDragParameters(BMessage *drag, BBitmap **bitmap, BPoint *point, Modified: haiku/trunk/src/kits/interface/TextInput.cpp =================================================================== --- haiku/trunk/src/kits/interface/TextInput.cpp 2007-10-03 22:53:19 UTC (rev 22431) +++ haiku/trunk/src/kits/interface/TextInput.cpp 2007-10-04 11:32:06 UTC (rev 22432) @@ -100,6 +100,11 @@ } } +void +_BTextInput_::ScrollToOffset(int32 nOffset) +{ + _ScrollToOffset(nOffset, true, false); +} void _BTextInput_::MakeFocus(bool state) Modified: haiku/trunk/src/kits/interface/TextInput.h =================================================================== --- haiku/trunk/src/kits/interface/TextInput.h 2007-10-03 22:53:19 UTC (rev 22431) +++ haiku/trunk/src/kits/interface/TextInput.h 2007-10-04 11:32:06 UTC (rev 22432) @@ -62,6 +62,7 @@ void AlignTextRect(); void SetInitialText(); +virtual void ScrollToOffset(int32 nOffset); virtual void Paste(BClipboard *clipboard); protected: Modified: haiku/trunk/src/kits/interface/TextView.cpp =================================================================== --- haiku/trunk/src/kits/interface/TextView.cpp 2007-10-03 22:53:19 UTC (rev 22431) +++ haiku/trunk/src/kits/interface/TextView.cpp 2007-10-04 11:32:06 UTC (rev 22432) @@ -24,7 +24,7 @@ #include #include using namespace std; - +#define DEBUG 1 #include #include #include @@ -806,6 +806,7 @@ switch (opcode) { case B_INPUT_METHOD_STARTED: { + PRINT(("B_INPUT_METHOD_STARTED\n")); BMessenger messenger; if (message->FindMessenger("be:reply_to", &messenger) == B_OK) { ASSERT(fInline == NULL); @@ -815,16 +816,21 @@ } case B_INPUT_METHOD_STOPPED: + PRINT(("B_INPUT_METHOD_STOPPED\n")); delete fInline; fInline = NULL; break; case B_INPUT_METHOD_CHANGED: - HandleInputMethodChanged(message); + PRINT(("B_INPUT_METHOD_CHANGED\n")); + if (fInline != NULL) + HandleInputMethodChanged(message); break; case B_INPUT_METHOD_LOCATION_REQUEST: - HandleInputMethodLocationRequest(); + PRINT(("B_INPUT_METHOD_LOCATION_REQUEST\n")); + if (fInline != NULL) + HandleInputMethodLocationRequest(); break; default: @@ -1929,24 +1935,39 @@ void BTextView::ScrollToOffset(int32 inOffset) { + _ScrollToOffset(inOffset, ScrollBar(B_HORIZONTAL) != NULL, ScrollBar(B_VERTICAL) != NULL); +} + +void +BTextView::_ScrollToOffset(int32 inOffset, bool useHorz, bool useVert) +{ BRect bounds = Bounds(); float lineHeight = 0.0; + float xdiff = 0.0; + float ydiff = 0.0; BPoint point = PointAt(inOffset, &lineHeight); - // TODO: We should do the following, since otherwise the textview - // won't scroll unless it's attached to a scrollview. - /*if (!bounds.Contains(point)) - ScrollTo(point); */ + if (useHorz) { + if (point.x < bounds.left) { + xdiff = -1 * (bounds.IntegerWidth() / 2); + // normalize scroll value to prevent scrolling past left boundary of view + if (bounds.left < fabs(xdiff)) + xdiff = -1 * bounds.left; + } else if (point.x >= bounds.right) + xdiff = bounds.IntegerWidth() / 2; + } - if (ScrollBar(B_HORIZONTAL) != NULL) { - if (point.x < bounds.left || point.x >= bounds.right) - ScrollBar(B_HORIZONTAL)->SetValue(point.x - (bounds.IntegerWidth() / 2)); + if (useVert) { + if (point.y < bounds.top) { + ydiff = -1 * (bounds.IntegerHeight() / 2); + // normalize scroll value to prevent scrolling past top of view + if (bounds.top < fabs(ydiff)) + ydiff = -1 * bounds.top; + } else if (point.y >= bounds.bottom) + ydiff = bounds.IntegerHeight() / 2; } - if (ScrollBar(B_VERTICAL) != NULL) { - if (point.y < bounds.top || (point.y + lineHeight) >= bounds.bottom) - ScrollBar(B_VERTICAL)->SetValue(point.y - (bounds.IntegerHeight() / 2)); - } + ScrollBy(xdiff, ydiff); } @@ -4398,8 +4419,7 @@ BTextView::HandleInputMethodChanged(BMessage *message) { // TODO: block input if not editable (Andrew) - if (!fInline) - return; + ASSERT(fInline != NULL); const char *string = NULL; if (message->FindString("be:string", &string) < B_OK || string == NULL) @@ -4470,8 +4490,7 @@ void BTextView::HandleInputMethodLocationRequest() { - if (!fInline) - return; + ASSERT(fInline != NULL); int32 offset = fInline->Offset(); const int32 limit = offset + fInline->Length(); From jackburton at mail.berlios.de Thu Oct 4 13:37:04 2007 From: jackburton at mail.berlios.de (jackburton at BerliOS) Date: Thu, 4 Oct 2007 13:37:04 +0200 Subject: [Haiku-commits] r22433 - haiku/trunk/src/kits/interface Message-ID: <200710041137.l94Bb4ZA015046@sheep.berlios.de> Author: jackburton Date: 2007-10-04 13:37:04 +0200 (Thu, 04 Oct 2007) New Revision: 22433 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22433&view=rev Modified: haiku/trunk/src/kits/interface/TextView.cpp Log: oops! Somehow I managed to commit a version with some extra debug code enabled. Modified: haiku/trunk/src/kits/interface/TextView.cpp =================================================================== --- haiku/trunk/src/kits/interface/TextView.cpp 2007-10-04 11:32:06 UTC (rev 22432) +++ haiku/trunk/src/kits/interface/TextView.cpp 2007-10-04 11:37:04 UTC (rev 22433) @@ -24,7 +24,7 @@ #include #include using namespace std; -#define DEBUG 1 + #include #include #include From axeld at mail.berlios.de Thu Oct 4 14:45:19 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 4 Oct 2007 14:45:19 +0200 Subject: [Haiku-commits] r22434 - in haiku/trunk: headers/os/drivers headers/private/fs_shell headers/private/kernel src/add-ons/kernel/file_systems/bfs src/add-ons/kernel/file_systems/cdda src/system/kernel/cache src/system/kernel/fs src/system/kernel/vm Message-ID: <200710041245.l94CjJaK019731@sheep.berlios.de> Author: axeld Date: 2007-10-04 14:45:15 +0200 (Thu, 04 Oct 2007) New Revision: 22434 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22434&view=rev Modified: haiku/trunk/headers/os/drivers/fs_interface.h haiku/trunk/headers/private/fs_shell/fssh_fs_interface.h haiku/trunk/headers/private/kernel/vfs.h haiku/trunk/headers/private/kernel/vm_types.h haiku/trunk/src/add-ons/kernel/file_systems/bfs/Debug.h haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp haiku/trunk/src/system/kernel/cache/file_cache.cpp haiku/trunk/src/system/kernel/cache/vnode_store.cpp haiku/trunk/src/system/kernel/fs/devfs.cpp haiku/trunk/src/system/kernel/fs/pipefs.cpp haiku/trunk/src/system/kernel/fs/rootfs.c haiku/trunk/src/system/kernel/fs/vfs.cpp haiku/trunk/src/system/kernel/vm/vm.cpp haiku/trunk/src/system/kernel/vm/vm_page.cpp haiku/trunk/src/system/kernel/vm/vm_store_anonymous_noswap.cpp haiku/trunk/src/system/kernel/vm/vm_store_device.c haiku/trunk/src/system/kernel/vm/vm_store_null.c Log: * fs_{write|read}_pages() now has an additional argument "mayBlock". * the page writer don't allow to block, while all other writers do. This fixes bug #1509. The reason the page writer needs this is because it marks several pages from different caches as busy. * Fixed a warning about ASSERT being defined already in BFS, since util/DoublyLinkedList.h now includes debug.h. Modified: haiku/trunk/headers/os/drivers/fs_interface.h =================================================================== --- haiku/trunk/headers/os/drivers/fs_interface.h 2007-10-04 11:37:04 UTC (rev 22433) +++ haiku/trunk/headers/os/drivers/fs_interface.h 2007-10-04 12:45:15 UTC (rev 22434) @@ -92,10 +92,10 @@ bool (*can_page)(fs_volume fs, fs_vnode vnode, fs_cookie cookie); status_t (*read_pages)(fs_volume fs, fs_vnode vnode, fs_cookie cookie, off_t pos, const iovec *vecs, size_t count, size_t *_numBytes, - bool reenter); + bool mayBlock, bool reenter); status_t (*write_pages)(fs_volume fs, fs_vnode vnode, fs_cookie cookie, off_t pos, const iovec *vecs, size_t count, size_t *_numBytes, - bool reenter); + bool mayBlock, bool reenter); /* cache file access */ status_t (*get_file_map)(fs_volume fs, fs_vnode vnode, off_t offset, Modified: haiku/trunk/headers/private/fs_shell/fssh_fs_interface.h =================================================================== --- haiku/trunk/headers/private/fs_shell/fssh_fs_interface.h 2007-10-04 11:37:04 UTC (rev 22433) +++ haiku/trunk/headers/private/fs_shell/fssh_fs_interface.h 2007-10-04 12:45:15 UTC (rev 22434) @@ -1,12 +1,13 @@ -/* File System Interface Layer Definition - * - * Copyright 2004-2006, Haiku Inc. All Rights Reserved. +/* + * Copyright 2004-2007, Haiku Inc. All Rights Reserved. * Distributed under the terms of the MIT License. */ #ifndef _FSSH_FS_INTERFACE_H #define _FSSH_FS_INTERFACE_H +/*! File System Interface Layer Definition */ + #include "fssh_disk_device_defs.h" #include "fssh_module.h" #include "fssh_os.h" @@ -95,10 +96,12 @@ fssh_fs_cookie cookie); fssh_status_t (*read_pages)(fssh_fs_volume fs, fssh_fs_vnode vnode, fssh_fs_cookie cookie, fssh_off_t pos, const fssh_iovec *vecs, - fssh_size_t count, fssh_size_t *_numBytes, bool reenter); + fssh_size_t count, fssh_size_t *_numBytes, bool mayBlock, + bool reenter); fssh_status_t (*write_pages)(fssh_fs_volume fs, fssh_fs_vnode vnode, fssh_fs_cookie cookie, fssh_off_t pos, const fssh_iovec *vecs, - fssh_size_t count, fssh_size_t *_numBytes, bool reenter); + fssh_size_t count, fssh_size_t *_numBytes, bool mayBlock, + bool reenter); /* cache file access */ fssh_status_t (*get_file_map)(fssh_fs_volume fs, fssh_fs_vnode vnode, Modified: haiku/trunk/headers/private/kernel/vfs.h =================================================================== --- haiku/trunk/headers/private/kernel/vfs.h 2007-10-04 11:37:04 UTC (rev 22433) +++ haiku/trunk/headers/private/kernel/vfs.h 2007-10-04 12:45:15 UTC (rev 22434) @@ -91,10 +91,13 @@ status_t vfs_get_cookie_from_fd(int fd, void **_cookie); bool vfs_can_page(void *vnode, void *cookie); status_t vfs_read_pages(void *vnode, void *cookie, off_t pos, - const iovec *vecs, size_t count, size_t *_numBytes, bool fsReenter); + const iovec *vecs, size_t count, size_t *_numBytes, bool mayBlock, + bool fsReenter); status_t vfs_write_pages(void *vnode, void *cookie, off_t pos, - const iovec *vecs, size_t count, size_t *_numBytes, bool fsReenter); -status_t vfs_get_vnode_cache(void *vnode, struct vm_cache **_cache, bool allocate); + const iovec *vecs, size_t count, size_t *_numBytes, bool mayBlock, + bool fsReenter); +status_t vfs_get_vnode_cache(void *vnode, struct vm_cache **_cache, + bool allocate); status_t vfs_get_file_map( void *_vnode, off_t offset, size_t size, struct file_io_vec *vecs, size_t *_count); status_t vfs_get_fs_node_from_path(dev_t mountID, const char *path, Modified: haiku/trunk/headers/private/kernel/vm_types.h =================================================================== --- haiku/trunk/headers/private/kernel/vm_types.h 2007-10-04 11:37:04 UTC (rev 22433) +++ haiku/trunk/headers/private/kernel/vm_types.h 2007-10-04 12:45:15 UTC (rev 22434) @@ -223,9 +223,11 @@ status_t (*commit)(struct vm_store *backing_store, off_t size); bool (*has_page)(struct vm_store *backing_store, off_t offset); status_t (*read)(struct vm_store *backing_store, off_t offset, - const iovec *vecs, size_t count, size_t *_numBytes, bool fsReenter); + const iovec *vecs, size_t count, size_t *_numBytes, bool mayBlock, + bool fsReenter); status_t (*write)(struct vm_store *backing_store, off_t offset, - const iovec *vecs, size_t count, size_t *_numBytes, bool fsReenter); + const iovec *vecs, size_t count, size_t *_numBytes, bool mayBlock, + bool fsReenter); status_t (*fault)(struct vm_store *backing_store, struct vm_address_space *aspace, off_t offset); void (*acquire_ref)(struct vm_store *backing_store); Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Debug.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/Debug.h 2007-10-04 11:37:04 UTC (rev 22433) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/Debug.h 2007-10-04 12:45:15 UTC (rev 22434) @@ -1,6 +1,5 @@ -/* Debug - debug stuff - * - * Copyright 2001-2006, Axel D?rfler, axeld at pinc-software.de. +/* + * Copyright 2001-2007, Axel D?rfler, axeld at pinc-software.de. * This file may be used under the terms of the MIT License. */ #ifndef DEBUG_H @@ -60,7 +59,9 @@ #define FUNCTION() ; // #define FUNCTION_START(x) ; #define D(x) {x;}; - #define ASSERT(x) { if (!(x)) DEBUGGER(("bfs: assert failed: " #x "\n")); } + #ifndef ASSERT + # define ASSERT(x) { if (!(x)) DEBUGGER(("bfs: assert failed: " #x "\n")); } + #endif #else #define PRINT(x) ; #define REPORT_ERROR(status) \ @@ -72,7 +73,9 @@ #define FUNCTION() ; #define FUNCTION_START(x) ; #define D(x) ; - #define ASSERT(x) ; + #ifndef ASSERT + # define ASSERT(x) ; + #endif #endif #ifdef DEBUG Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp 2007-10-04 11:37:04 UTC (rev 22433) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp 2007-10-04 12:45:15 UTC (rev 22434) @@ -342,7 +342,8 @@ static status_t bfs_read_pages(fs_volume _fs, fs_vnode _node, fs_cookie _cookie, off_t pos, - const iovec *vecs, size_t count, size_t *_numBytes, bool reenter) + const iovec *vecs, size_t count, size_t *_numBytes, bool mayBlock, + bool reenter) { Inode *inode = (Inode *)_node; @@ -350,7 +351,9 @@ RETURN_ERROR(B_BAD_VALUE); if (!reenter) { - if (inode->Lock().TryLock() < B_OK) + if (mayBlock) + inode->Lock().Lock(); + else if (inode->Lock().TryLock() < B_OK) return B_BUSY; } @@ -366,7 +369,8 @@ static status_t bfs_write_pages(fs_volume _fs, fs_vnode _node, fs_cookie _cookie, off_t pos, - const iovec *vecs, size_t count, size_t *_numBytes, bool reenter) + const iovec *vecs, size_t count, size_t *_numBytes, bool mayBlock, + bool reenter) { Inode *inode = (Inode *)_node; @@ -374,7 +378,9 @@ RETURN_ERROR(B_BAD_VALUE); if (!reenter) { - if (inode->Lock().TryLock() < B_OK) + if (mayBlock) + inode->Lock().Lock(); + else if (inode->Lock().TryLock() < B_OK) return B_BUSY; } Modified: haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp 2007-10-04 11:37:04 UTC (rev 22433) +++ haiku/trunk/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp 2007-10-04 12:45:15 UTC (rev 22434) @@ -1574,17 +1574,19 @@ static status_t cdda_read_pages(fs_volume _volume, fs_vnode _v, fs_cookie cookie, off_t pos, - const iovec *vecs, size_t count, size_t *_numBytes, bool reenter) + const iovec *vecs, size_t count, size_t *_numBytes, bool mayBlock, + bool reenter) { - return EPERM; + return B_NOT_ALLOWED; } static status_t cdda_write_pages(fs_volume _volume, fs_vnode _v, fs_cookie cookie, off_t pos, - const iovec *vecs, size_t count, size_t *_numBytes, bool reenter) + const iovec *vecs, size_t count, size_t *_numBytes, bool mayBlock, + bool reenter) { - return EPERM; + return B_NOT_ALLOWED; } Modified: haiku/trunk/src/system/kernel/cache/file_cache.cpp =================================================================== --- haiku/trunk/src/system/kernel/cache/file_cache.cpp 2007-10-04 11:37:04 UTC (rev 22433) +++ haiku/trunk/src/system/kernel/cache/file_cache.cpp 2007-10-04 12:45:15 UTC (rev 22434) @@ -362,7 +362,7 @@ size = numBytes; status = vfs_read_pages(ref->device, ref->cookie, fileVecs[0].offset, - vecs, count, &size, false); + vecs, count, &size, true, false); if (status < B_OK) return status; @@ -459,10 +459,10 @@ size_t bytes = size; if (doWrite) { status = vfs_write_pages(ref->device, ref->cookie, - fileOffset, tempVecs, tempCount, &bytes, false); + fileOffset, tempVecs, tempCount, &bytes, true, false); } else { status = vfs_read_pages(ref->device, ref->cookie, - fileOffset, tempVecs, tempCount, &bytes, false); + fileOffset, tempVecs, tempCount, &bytes, true, false); } if (status < B_OK) return status; Modified: haiku/trunk/src/system/kernel/cache/vnode_store.cpp =================================================================== --- haiku/trunk/src/system/kernel/cache/vnode_store.cpp 2007-10-04 11:37:04 UTC (rev 22433) +++ haiku/trunk/src/system/kernel/cache/vnode_store.cpp 2007-10-04 12:45:15 UTC (rev 22434) @@ -6,13 +6,13 @@ #include "vnode_store.h" +#include +#include + #include #include -#include -#include - static void store_destroy(struct vm_store *store) { @@ -41,18 +41,19 @@ static status_t -store_read(struct vm_store *_store, off_t offset, const iovec *vecs, size_t count, - size_t *_numBytes, bool fsReenter) +store_read(struct vm_store *_store, off_t offset, const iovec *vecs, + size_t count, size_t *_numBytes, bool mayBlock, bool fsReenter) { vnode_store *store = (vnode_store *)_store; size_t bytesUntouched = *_numBytes; status_t status = vfs_read_pages(store->vnode, NULL, offset, vecs, count, - _numBytes, fsReenter); + _numBytes, mayBlock, fsReenter); bytesUntouched -= *_numBytes; - // if the request could be filled completely, or an error occured, we're done here + // If the request could be filled completely, or an error occured, + // we're done here if (status < B_OK || bytesUntouched == 0) return status; @@ -63,7 +64,8 @@ size_t length = min_c(bytesUntouched, vecs[i].iov_len); // ToDo: will have to map the pages in later (when we switch to physical pages) - memset((void *)((addr_t)vecs[i].iov_base + vecs[i].iov_len - length), 0, length); + memset((void *)((addr_t)vecs[i].iov_base + vecs[i].iov_len - length), + 0, length); bytesUntouched -= length; } @@ -72,11 +74,12 @@ static status_t -store_write(struct vm_store *_store, off_t offset, const iovec *vecs, size_t count, - size_t *_numBytes, bool fsReenter) +store_write(struct vm_store *_store, off_t offset, const iovec *vecs, + size_t count, size_t *_numBytes, bool mayBlock, bool fsReenter) { vnode_store *store = (vnode_store *)_store; - return vfs_write_pages(store->vnode, NULL, offset, vecs, count, _numBytes, fsReenter); + return vfs_write_pages(store->vnode, NULL, offset, vecs, count, _numBytes, + mayBlock, fsReenter); } Modified: haiku/trunk/src/system/kernel/fs/devfs.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/devfs.cpp 2007-10-04 11:37:04 UTC (rev 22433) +++ haiku/trunk/src/system/kernel/fs/devfs.cpp 2007-10-04 12:45:15 UTC (rev 22434) @@ -1884,7 +1884,8 @@ static status_t devfs_read_pages(fs_volume _fs, fs_vnode _vnode, fs_cookie _cookie, off_t pos, - const iovec *vecs, size_t count, size_t *_numBytes, bool reenter) + const iovec *vecs, size_t count, size_t *_numBytes, bool mayBlock, + bool reenter) { struct devfs_vnode *vnode = (devfs_vnode *)_vnode; struct devfs_cookie *cookie = (struct devfs_cookie *)_cookie; @@ -1943,7 +1944,8 @@ static status_t devfs_write_pages(fs_volume _fs, fs_vnode _vnode, fs_cookie _cookie, off_t pos, - const iovec *vecs, size_t count, size_t *_numBytes, bool reenter) + const iovec *vecs, size_t count, size_t *_numBytes, bool mayBlock, + bool reenter) { struct devfs_vnode *vnode = (devfs_vnode *)_vnode; struct devfs_cookie *cookie = (struct devfs_cookie *)_cookie; Modified: haiku/trunk/src/system/kernel/fs/pipefs.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/pipefs.cpp 2007-10-04 11:37:04 UTC (rev 22433) +++ haiku/trunk/src/system/kernel/fs/pipefs.cpp 2007-10-04 12:45:15 UTC (rev 22434) @@ -1596,17 +1596,19 @@ static status_t pipefs_read_pages(fs_volume _volume, fs_vnode _v, fs_cookie cookie, off_t pos, - const iovec *vecs, size_t count, size_t *_numBytes, bool reenter) + const iovec *vecs, size_t count, size_t *_numBytes, bool mayBlock, + bool reenter) { - return EPERM; + return B_NOT_ALLOWED; } static status_t pipefs_write_pages(fs_volume _volume, fs_vnode _v, fs_cookie cookie, off_t pos, - const iovec *vecs, size_t count, size_t *_numBytes, bool reenter) + const iovec *vecs, size_t count, size_t *_numBytes, bool mayBlock, + bool reenter) { - return EPERM; + return B_NOT_ALLOWED; } Modified: haiku/trunk/src/system/kernel/fs/rootfs.c =================================================================== --- haiku/trunk/src/system/kernel/fs/rootfs.c 2007-10-04 11:37:04 UTC (rev 22433) +++ haiku/trunk/src/system/kernel/fs/rootfs.c 2007-10-04 12:45:15 UTC (rev 22434) @@ -772,7 +772,8 @@ static status_t rootfs_read_pages(fs_volume _fs, fs_vnode _v, fs_cookie cookie, off_t pos, - const iovec *vecs, size_t count, size_t *_numBytes, bool reenter) + const iovec *vecs, size_t count, size_t *_numBytes, bool mayBlock, + bool reenter) { return B_NOT_ALLOWED; } @@ -780,7 +781,8 @@ static status_t rootfs_write_pages(fs_volume _fs, fs_vnode _v, fs_cookie cookie, off_t pos, - const iovec *vecs, size_t count, size_t *_numBytes, bool reenter) + const iovec *vecs, size_t count, size_t *_numBytes, bool mayBlock, + bool reenter) { return B_NOT_ALLOWED; } Modified: haiku/trunk/src/system/kernel/fs/vfs.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/vfs.cpp 2007-10-04 11:37:04 UTC (rev 22433) +++ haiku/trunk/src/system/kernel/fs/vfs.cpp 2007-10-04 12:45:15 UTC (rev 22434) @@ -3094,28 +3094,28 @@ extern "C" status_t -vfs_read_pages(void *_vnode, void *cookie, off_t pos, const iovec *vecs, size_t count, - size_t *_numBytes, bool fsReenter) +vfs_read_pages(void *_vnode, void *cookie, off_t pos, const iovec *vecs, + size_t count, size_t *_numBytes, bool mayBlock, bool fsReenter) { struct vnode *vnode = (struct vnode *)_vnode; FUNCTION(("vfs_read_pages: vnode %p, vecs %p, pos %Ld\n", vnode, vecs, pos)); return FS_CALL(vnode, read_pages)(vnode->mount->cookie, vnode->private_node, - cookie, pos, vecs, count, _numBytes, fsReenter); + cookie, pos, vecs, count, _numBytes, mayBlock, fsReenter); } extern "C" status_t -vfs_write_pages(void *_vnode, void *cookie, off_t pos, const iovec *vecs, size_t count, - size_t *_numBytes, bool fsReenter) +vfs_write_pages(void *_vnode, void *cookie, off_t pos, const iovec *vecs, + size_t count, size_t *_numBytes, bool mayBlock, bool fsReenter) { struct vnode *vnode = (struct vnode *)_vnode; FUNCTION(("vfs_write_pages: vnode %p, vecs %p, pos %Ld\n", vnode, vecs, pos)); return FS_CALL(vnode, write_pages)(vnode->mount->cookie, vnode->private_node, - cookie, pos, vecs, count, _numBytes, fsReenter); + cookie, pos, vecs, count, _numBytes, mayBlock, fsReenter); } Modified: haiku/trunk/src/system/kernel/vm/vm.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm.cpp 2007-10-04 11:37:04 UTC (rev 22433) +++ haiku/trunk/src/system/kernel/vm/vm.cpp 2007-10-04 12:45:15 UTC (rev 22434) @@ -3809,7 +3809,7 @@ // read it in status_t status = store->ops->read(store, cacheOffset, &vec, 1, - &bytesRead, false); + &bytesRead, true, false); map->ops->put_physical_page((addr_t)vec.iov_base); Modified: haiku/trunk/src/system/kernel/vm/vm_page.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_page.cpp 2007-10-04 11:37:04 UTC (rev 22433) +++ haiku/trunk/src/system/kernel/vm/vm_page.cpp 2007-10-04 12:45:15 UTC (rev 22434) @@ -640,7 +640,7 @@ static status_t -write_page(vm_page *page, bool fsReenter) +write_page(vm_page *page, bool mayBlock, bool fsReenter) { vm_store *store = page->cache->store; size_t length = B_PAGE_SIZE; @@ -656,7 +656,7 @@ vecs->iov_len = B_PAGE_SIZE; status = store->ops->write(store, (off_t)page->cache_offset << PAGE_SHIFT, - vecs, 1, &length, fsReenter); + vecs, 1, &length, mayBlock, fsReenter); vm_put_physical_page((addr_t)vecs[0].iov_base); @@ -728,7 +728,7 @@ // TODO: put this as requests into the I/O scheduler status_t writeStatus[kNumPages]; for (uint32 i = 0; i < numPages; i++) { - writeStatus[i] = write_page(pages[i], false); + writeStatus[i] = write_page(pages[i], false, false); } // mark pages depending on whether they could be written or not @@ -927,7 +927,7 @@ vm_clear_map_flags(page, PAGE_MODIFIED); mutex_unlock(&cache->lock); - status_t status = write_page(page, fsReenter); + status_t status = write_page(page, true, fsReenter); mutex_lock(&cache->lock); InterruptsSpinLocker locker(&sPageLock); Modified: haiku/trunk/src/system/kernel/vm/vm_store_anonymous_noswap.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_store_anonymous_noswap.cpp 2007-10-04 11:37:04 UTC (rev 22433) +++ haiku/trunk/src/system/kernel/vm/vm_store_anonymous_noswap.cpp 2007-10-04 12:45:15 UTC (rev 22434) @@ -90,7 +90,7 @@ static status_t anonymous_read(struct vm_store *store, off_t offset, const iovec *vecs, - size_t count, size_t *_numBytes, bool fsReenter) + size_t count, size_t *_numBytes, bool mayBlock, bool fsReenter) { panic("anonymous_store: read called. Invalid!\n"); return B_ERROR; @@ -99,7 +99,7 @@ static status_t anonymous_write(struct vm_store *store, off_t offset, const iovec *vecs, - size_t count, size_t *_numBytes, bool fsReenter) + size_t count, size_t *_numBytes, bool mayBlock, bool fsReenter) { // no place to write, this will cause the page daemon to skip this store return B_ERROR; Modified: haiku/trunk/src/system/kernel/vm/vm_store_device.c =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_store_device.c 2007-10-04 11:37:04 UTC (rev 22433) +++ haiku/trunk/src/system/kernel/vm/vm_store_device.c 2007-10-04 12:45:15 UTC (rev 22434) @@ -45,8 +45,8 @@ static status_t -device_read(struct vm_store *store, off_t offset, const iovec *vecs, size_t count, - size_t *_numBytes, bool fsReenter) +device_read(struct vm_store *store, off_t offset, const iovec *vecs, + size_t count, size_t *_numBytes, bool mayBlock, bool fsReenter) { panic("device_store: read called. Invalid!\n"); return B_ERROR; @@ -54,8 +54,8 @@ static status_t -device_write(struct vm_store *store, off_t offset, const iovec *vecs, size_t count, - size_t *_numBytes, bool fsReenter) +device_write(struct vm_store *store, off_t offset, const iovec *vecs, + size_t count, size_t *_numBytes, bool mayBlock, bool fsReenter) { // no place to write, this will cause the page daemon to skip this store return B_OK; Modified: haiku/trunk/src/system/kernel/vm/vm_store_null.c =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_store_null.c 2007-10-04 11:37:04 UTC (rev 22433) +++ haiku/trunk/src/system/kernel/vm/vm_store_null.c 2007-10-04 12:45:15 UTC (rev 22434) @@ -1,5 +1,5 @@ /* - * Copyright 2004-2006, Axel D?rfler, axeld at pinc-software.de. + * Copyright 2004-2007, Axel D?rfler, axeld at pinc-software.de. * Distributed under the terms of the MIT License. * * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. @@ -36,17 +36,17 @@ static status_t null_read(struct vm_store *store, off_t offset, const iovec *vecs, - size_t count, size_t *_numBytes, bool fsReenter) + size_t count, size_t *_numBytes, bool mayBlock, bool fsReenter) { - return -1; + return B_ERROR; } static status_t null_write(struct vm_store *store, off_t offset, const iovec *vecs, - size_t count, size_t *_numBytes, bool fsReenter) + size_t count, size_t *_numBytes, bool mayBlock, bool fsReenter) { - return -1; + return B_ERROR; } From stefano.ceccherini at gmail.com Thu Oct 4 14:56:35 2007 From: stefano.ceccherini at gmail.com (Stefano Ceccherini) Date: Thu, 4 Oct 2007 14:56:35 +0200 Subject: [Haiku-commits] r22434 - in haiku/trunk: headers/os/drivers headers/private/fs_shell headers/private/kernel src/add-ons/kernel/file_systems/bfs src/add-ons/kernel/file_systems/cdda src/system/kernel/cache src/system/kernel/fs src/system/kernel/vm In-Reply-To: <200710041245.l94CjJaK019731@sheep.berlios.de> References: <200710041245.l94CjJaK019731@sheep.berlios.de> Message-ID: <894b9700710040556q6b9d607eq1fb112e8c2c9ed7b@mail.gmail.com> 2007/10/4, axeld at BerliOS : > Author: axeld > Date: 2007-10-04 14:45:15 +0200 (Thu, 04 Oct 2007) > New Revision: 22434 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22434&view=rev > > * fs_{write|read}_pages() now has an additional argument "mayBlock". > * the page writer don't allow to block, while all other writers do. This fixes > bug #1509. The reason the page writer needs this is because it marks several > pages from different caches as busy. > * Fixed a warning about ASSERT being defined already in BFS, since > util/DoublyLinkedList.h now includes debug.h. > > Build is broken by this commit: C++ generated/objects/linux/x86/release/tools/fs_shell/rootfs.o src/tools/fs_shell/rootfs.cpp:1101: error: invalid conversion from 'fssh_status_t (*)(void*, void*, void*, fssh_off_t, const fssh_iovec*, fssh_size_t, fssh_size_t*, bool)' to 'fssh_status_t (*)(void*, void*, void*, fssh_off_t, const fssh_iovec*, fssh_size_t, fssh_size_t*, bool, bool)' src/tools/fs_shell/rootfs.cpp:1101: error: invalid conversion from 'fssh_status_t (*)(void*, void*, void*, fssh_off_t, const fssh_iovec*, fssh_size_t, fssh_size_t*, bool)' to 'fssh_status_t (*)(void*, void*, void*, fssh_off_t, const fssh_iovec*, fssh_size_t, fssh_size_t*, bool, bool)' cc -c "src/tools/fs_shell/rootfs.cpp" -O -Wall -Wno-ctor-dtor-privacy -Woverloaded-virtual -Wpointer-arith -Wcast-align -Wsign-compare -Wno-multichar -D_ZETA_USING_DEPRECATED_API_=1 -D_ZETA_TS_FIND_DIR_=1 -DARCH_x86 -D_NO_INLINE_ASM -D__INTEL__ -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -DHAIKU_HOST_PLATFORM_LINUX -iquote src/tools/fs_shell -iquote generated/objects/common/tools/fs_shell -iquote generated/objects/linux/x86/common/tools/fs_shell -iquote generated/objects/haiku/x86/common/tools/fs_shell -I headers/build -I headers/build/os -I headers/build/os/kernel -I headers/build/os/storage -I headers/build/os/support -I headers/private/fs_shell -I headers/private/shared -I headers/build/host/linux -o "generated/objects/linux/x86/release/tools/fs_shell/rootfs.o" ; ...failed C++ generated/objects/linux/x86/release/tools/fs_shell/rootfs.o ... ...removing generated/objects/linux/x86/release/tools/fs_shell/rootfs.o C++ generated/objects/linux/x86/release/tools/fs_shell/unistd.o C++ generated/objects/linux/x86/release/tools/fs_shell/vfs.o C++ generated/objects/linux/x86/release/tools/fs_shell/fssh.o ...skipped fs_shell.a for lack of fs_shell.a(rootfs.o)... ...skipped bfs_shell for lack of fs_shell.a... ...skipped haiku.image-init-vars for lack of bfs_shell... From bonefish at cs.tu-berlin.de Thu Oct 4 15:15:27 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Thu, 04 Oct 2007 15:15:27 +0200 Subject: [Haiku-commits] r22416 - in haiku/trunk: headers/os/drivers headers/os/kernel headers/private/kernel headers/private/kernel/fs headers/private/userlandfs/private src/add-ons/kernel/drivers/random src/add-ons/kernel/drivers/tty src/add-ons/kernel/file_systems/userlandfs/kernel_add_on src/add-ons/kernel/file_systems/userlandfs/server src/add-ons/kernel/network/stack src/system/kernel src/system/kernel/fs src/system/libroot/os In-Reply-To: <7694756459-BeMail@zon> References: <7694756459-BeMail@zon> Message-ID: <20071004151527.531.1@cs.tu-berlin.de> On 2007-10-04 at 13:31:03 [+0200], Axel D?rfler wrote: > bonefish at BerliOS wrote: > > * Removed the "ref" parameter from notify_select_events() and the > > select_sync_pool functions as well as from fd_ops::fd_[de]select(). > > It > > is no longer needed. The FS interface select() hook still has it, > > though -- the VFS will always pass 0. > > Is there any reason to keep the "ref" argument then? > If not, I would remove it now. I was only reluctant because it affects several FSs and we could as well wait until the next change to the FS interface. But feel free ... :-) The old-style driver interface could be adjusted too. Old drivers (R5 binaries) that implement the select() hook haven't been compatible anyway, since our notify_select_event() has a different signature. CU, Ingo From axeld at mail.berlios.de Thu Oct 4 15:23:01 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 4 Oct 2007 15:23:01 +0200 Subject: [Haiku-commits] r22435 - haiku/trunk/src/tools/fs_shell Message-ID: <200710041323.l94DN1jc023406@sheep.berlios.de> Author: axeld Date: 2007-10-04 15:23:00 +0200 (Thu, 04 Oct 2007) New Revision: 22435 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22435&view=rev Modified: haiku/trunk/src/tools/fs_shell/file_cache.cpp haiku/trunk/src/tools/fs_shell/rootfs.cpp Log: Forgot to commit the fs_shell with r22434, thanks for the note, Stefano! Modified: haiku/trunk/src/tools/fs_shell/file_cache.cpp =================================================================== --- haiku/trunk/src/tools/fs_shell/file_cache.cpp 2007-10-04 12:45:15 UTC (rev 22434) +++ haiku/trunk/src/tools/fs_shell/file_cache.cpp 2007-10-04 13:23:00 UTC (rev 22435) @@ -179,9 +179,9 @@ static fssh_status_t vm_cache_write_modified(file_cache_ref *ref, bool fsReenter); static fssh_status_t vfs_read_pages(int fd, fssh_off_t pos, const fssh_iovec *vecs, - fssh_size_t count, fssh_size_t *_numBytes, bool fsReenter); + fssh_size_t count, fssh_size_t *_numBytes, bool mayBlock, bool fsReenter); static fssh_status_t vfs_write_pages(int fd, fssh_off_t pos, const fssh_iovec *vecs, - fssh_size_t count, fssh_size_t *_numBytes, bool fsReenter); + fssh_size_t count, fssh_size_t *_numBytes, bool mayBlock, bool fsReenter); static fssh_status_t pages_io(file_cache_ref *ref, fssh_off_t offset, const fssh_iovec *vecs, fssh_size_t count, fssh_size_t *_numBytes, bool doWrite); @@ -741,7 +741,7 @@ fssh_status_t vfs_read_pages(int fd, fssh_off_t pos, const fssh_iovec *vecs, fssh_size_t count, - fssh_size_t *_numBytes, bool fsReenter) + fssh_size_t *_numBytes, bool mayBlock, bool fsReenter) { // check how much the iovecs allow us to read fssh_size_t toRead = 0; @@ -781,7 +781,7 @@ fssh_status_t vfs_write_pages(int fd, fssh_off_t pos, const fssh_iovec *vecs, fssh_size_t count, - fssh_size_t *_numBytes, bool fsReenter) + fssh_size_t *_numBytes, bool mayBlock, bool fsReenter) { // check how much the iovecs allow us to write fssh_size_t toWrite = 0; @@ -1122,7 +1122,7 @@ size = numBytes; status = vfs_read_pages(ref->deviceFD, fileVecs[0].offset, vecs, - count, &size, false); + count, &size, true, false); if (status < FSSH_B_OK) return status; @@ -1219,10 +1219,10 @@ fssh_size_t bytes = size; if (doWrite) { status = vfs_write_pages(ref->deviceFD, fileOffset, - tempVecs, tempCount, &bytes, false); + tempVecs, tempCount, &bytes, true, false); } else { status = vfs_read_pages(ref->deviceFD, fileOffset, - tempVecs, tempCount, &bytes, false); + tempVecs, tempCount, &bytes, true, false); } if (status < FSSH_B_OK) return status; Modified: haiku/trunk/src/tools/fs_shell/rootfs.cpp =================================================================== --- haiku/trunk/src/tools/fs_shell/rootfs.cpp 2007-10-04 12:45:15 UTC (rev 22434) +++ haiku/trunk/src/tools/fs_shell/rootfs.cpp 2007-10-04 13:23:00 UTC (rev 22435) @@ -772,16 +772,18 @@ static fssh_status_t -rootfs_read_pages(fssh_fs_volume _fs, fssh_fs_vnode _v, fssh_fs_cookie cookie, fssh_off_t pos, - const fssh_iovec *vecs, fssh_size_t count, fssh_size_t *_numBytes, bool reenter) +rootfs_read_pages(fssh_fs_volume _fs, fssh_fs_vnode _v, fssh_fs_cookie cookie, + fssh_off_t pos, const fssh_iovec *vecs, fssh_size_t count, + fssh_size_t *_numBytes, bool mayBlock, bool reenter) { return FSSH_B_NOT_ALLOWED; } static fssh_status_t -rootfs_write_pages(fssh_fs_volume _fs, fssh_fs_vnode _v, fssh_fs_cookie cookie, fssh_off_t pos, - const fssh_iovec *vecs, fssh_size_t count, fssh_size_t *_numBytes, bool reenter) +rootfs_write_pages(fssh_fs_volume _fs, fssh_fs_vnode _v, fssh_fs_cookie cookie, + fssh_off_t pos, const fssh_iovec *vecs, fssh_size_t count, + fssh_size_t *_numBytes, bool mayBlock, bool reenter) { return FSSH_B_NOT_ALLOWED; } From axeld at pinc-software.de Thu Oct 4 15:29:31 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Thu, 04 Oct 2007 15:29:31 +0200 CEST Subject: [Haiku-commits] r22416 - in haiku/trunk: headers/os/drivers headers/os/kernel headers/private/kernel headers/private/kernel/fs headers/private/userlandfs/private src/add-ons/kernel/drivers/random src/add-ons/kernel/drivers/tty src/add-ons/kernel/file_systems/userlandfs/kernel_add_on src/add-ons/kernel/file_systems/userlandfs/server src/add-ons/kernel/network/stack src/system/kernel src/system/kernel/fs src/system/libroot/os In-Reply-To: <20071004151527.531.1@cs.tu-berlin.de> Message-ID: <14802833886-BeMail@zon> Ingo Weinhold wrote: > On 2007-10-04 at 13:31:03 [+0200], Axel D?rfler > > wrote: > > bonefish at BerliOS wrote: > > > * Removed the "ref" parameter from notify_select_events() and the > > > select_sync_pool functions as well as from > > > fd_ops::fd_[de]select(). > > > It > > > is no longer needed. The FS interface select() hook still has > > > it, > > > though -- the VFS will always pass 0. > > > > Is there any reason to keep the "ref" argument then? > > If not, I would remove it now. > I was only reluctant because it affects several FSs and we could as > well > wait until the next change to the FS interface. But feel free ... :-) > > The old-style driver interface could be adjusted too. Old drivers (R5 > binaries) that implement the select() hook haven't been compatible > anyway, > since our notify_select_event() has a different signature. Okay, I'll do that together with the fs_cookie/fs_volume/fs_node -> void* change. Bye, Axel. From bonefish at mail.berlios.de Thu Oct 4 16:30:51 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Thu, 4 Oct 2007 16:30:51 +0200 Subject: [Haiku-commits] r22436 - in haiku/trunk/src: system/kernel/fs tools/fs_shell Message-ID: <200710041430.l94EUpXT028202@sheep.berlios.de> Author: bonefish Date: 2007-10-04 16:30:50 +0200 (Thu, 04 Oct 2007) New Revision: 22436 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22436&view=rev Added: haiku/trunk/src/system/kernel/fs/rootfs.cpp Removed: haiku/trunk/src/system/kernel/fs/rootfs.c haiku/trunk/src/tools/fs_shell/rootfs.cpp Modified: haiku/trunk/src/system/kernel/fs/Jamfile haiku/trunk/src/tools/fs_shell/Jamfile haiku/trunk/src/tools/fs_shell/fssh.cpp Log: * rootfs.c -> rootfs.cpp * Made the kernel rootfs reusable by the FS Shell and removed the copy in the FS Shell sources. Modified: haiku/trunk/src/system/kernel/fs/Jamfile =================================================================== --- haiku/trunk/src/system/kernel/fs/Jamfile 2007-10-04 13:23:00 UTC (rev 22435) +++ haiku/trunk/src/system/kernel/fs/Jamfile 2007-10-04 14:30:50 UTC (rev 22436) @@ -7,7 +7,7 @@ KernelMergeObject kernel_fs.o : devfs.cpp - rootfs.c + rootfs.cpp pipefs.cpp fd.cpp vfs.cpp Deleted: haiku/trunk/src/system/kernel/fs/rootfs.c Copied: haiku/trunk/src/system/kernel/fs/rootfs.cpp (from rev 22434, haiku/trunk/src/system/kernel/fs/rootfs.c) =================================================================== --- haiku/trunk/src/system/kernel/fs/rootfs.c 2007-10-04 12:45:15 UTC (rev 22434) +++ haiku/trunk/src/system/kernel/fs/rootfs.cpp 2007-10-04 14:30:50 UTC (rev 22436) @@ -0,0 +1,1118 @@ +/* + * Copyright 2002-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the NewOS License. + */ + + +#if FS_SHELL +# include "fssh_api_wrapper.h" + +# include "hash.h" +# include "list.h" +# include "lock.h" +#else +# include +# include +# include +# include +# include +# include + +# include + +# include +# include +# include +# include +#endif + + +#if FS_SHELL + using namespace FSShell; +# define user_strlcpy(to, from, len) (strlcpy(to, from, len), FSSH_B_OK) +#endif + + +//#define TRACE_ROOTFS +#ifdef TRACE_ROOTFS +# define TRACE(x) dprintf x +#else +# define TRACE(x) +#endif + + +struct rootfs_stream { + mode_t type; + struct stream_dir { + struct rootfs_vnode *dir_head; + struct list cookies; + } dir; + struct stream_symlink { + char *path; + size_t length; + } symlink; +}; + +struct rootfs_vnode { + struct rootfs_vnode *all_next; + ino_t id; + char *name; + time_t modification_time; + time_t creation_time; + uid_t uid; + gid_t gid; + struct rootfs_vnode *parent; + struct rootfs_vnode *dir_next; + struct rootfs_stream stream; +}; + +struct rootfs { + dev_t id; + mutex lock; + ino_t next_vnode_id; + hash_table *vnode_list_hash; + struct rootfs_vnode *root_vnode; +}; + +// dircookie, dirs are only types of streams supported by rootfs +struct rootfs_dir_cookie { + struct list_link link; + struct rootfs_vnode *current; + int32 state; // iteration state +}; + +// directory iteration states +enum { + ITERATION_STATE_DOT = 0, + ITERATION_STATE_DOT_DOT = 1, + ITERATION_STATE_OTHERS = 2, + ITERATION_STATE_BEGIN = ITERATION_STATE_DOT, +}; + +#define ROOTFS_HASH_SIZE 16 + + +static uint32 +rootfs_vnode_hash_func(void *_v, const void *_key, uint32 range) +{ + struct rootfs_vnode *vnode = (rootfs_vnode*)_v; + const ino_t *key = (const ino_t*)_key; + + if (vnode != NULL) + return vnode->id % range; + + return (uint64)*key % range; +} + + +static int +rootfs_vnode_compare_func(void *_v, const void *_key) +{ + struct rootfs_vnode *v = (rootfs_vnode*)_v; + const ino_t *key = (const ino_t*)_key; + + if (v->id == *key) + return 0; + + return -1; +} + + +static struct rootfs_vnode * +rootfs_create_vnode(struct rootfs *fs, struct rootfs_vnode *parent, + const char *name, int type) +{ + struct rootfs_vnode *vnode; + + vnode = (rootfs_vnode*)malloc(sizeof(struct rootfs_vnode)); + if (vnode == NULL) + return NULL; + + memset(vnode, 0, sizeof(struct rootfs_vnode)); + + vnode->name = strdup(name); + if (vnode->name == NULL) { + free(vnode); + return NULL; + } + + vnode->id = fs->next_vnode_id++; + vnode->stream.type = type; + vnode->creation_time = vnode->modification_time = time(NULL); + vnode->uid = geteuid(); + vnode->gid = parent ? parent->gid : getegid(); + // inherit group from parent if possible + + if (S_ISDIR(type)) + list_init(&vnode->stream.dir.cookies); + + return vnode; +} + + +static status_t +rootfs_delete_vnode(struct rootfs *fs, struct rootfs_vnode *v, bool force_delete) +{ + // cant delete it if it's in a directory or is a directory + // and has children + if (!force_delete && (v->stream.dir.dir_head != NULL || v->dir_next != NULL)) + return EPERM; + + // remove it from the global hash table + hash_remove(fs->vnode_list_hash, v); + + free(v->name); + free(v); + + return 0; +} + + +/* makes sure none of the dircookies point to the vnode passed in */ + +static void +update_dir_cookies(struct rootfs_vnode *dir, struct rootfs_vnode *vnode) +{ + struct rootfs_dir_cookie *cookie = NULL; + + while ((cookie = (rootfs_dir_cookie*)list_get_next_item( + &dir->stream.dir.cookies, cookie)) != NULL) { + if (cookie->current == vnode) + cookie->current = vnode->dir_next; + } +} + + +static struct rootfs_vnode * +rootfs_find_in_dir(struct rootfs_vnode *dir, const char *path) +{ + struct rootfs_vnode *vnode; + + if (!strcmp(path, ".")) + return dir; + if (!strcmp(path, "..")) + return dir->parent; + + for (vnode = dir->stream.dir.dir_head; vnode; vnode = vnode->dir_next) { + if (strcmp(vnode->name, path) == 0) + return vnode; + } + return NULL; +} + + +static status_t +rootfs_insert_in_dir(struct rootfs *fs, struct rootfs_vnode *dir, + struct rootfs_vnode *vnode) +{ + // make sure the directory stays sorted alphabetically + + struct rootfs_vnode *node = dir->stream.dir.dir_head, *last = NULL; + while (node && strcmp(node->name, vnode->name) < 0) { + last = node; + node = node->dir_next; + } + if (last == NULL) { + // the new vnode is the first entry in the list + vnode->dir_next = dir->stream.dir.dir_head; + dir->stream.dir.dir_head = vnode; + } else { + // insert after that node + vnode->dir_next = last->dir_next; + last->dir_next = vnode; + } + + vnode->parent = dir; + dir->modification_time = time(NULL); + + notify_stat_changed(fs->id, dir->id, B_STAT_MODIFICATION_TIME); + return B_OK; +} + + +static status_t +rootfs_remove_from_dir(struct rootfs *fs, struct rootfs_vnode *dir, + struct rootfs_vnode *findit) +{ + struct rootfs_vnode *v; + struct rootfs_vnode *last_v; + + for (v = dir->stream.dir.dir_head, last_v = NULL; v; last_v = v, v = v->dir_next) { + if (v == findit) { + /* make sure all dircookies dont point to this vnode */ + update_dir_cookies(dir, v); + + if (last_v) + last_v->dir_next = v->dir_next; + else + dir->stream.dir.dir_head = v->dir_next; + v->dir_next = NULL; + + dir->modification_time = time(NULL); + notify_stat_changed(fs->id, dir->id, B_STAT_MODIFICATION_TIME); + return B_OK; + } + } + return B_ENTRY_NOT_FOUND; +} + + +static bool +rootfs_is_dir_empty(struct rootfs_vnode *dir) +{ + return !dir->stream.dir.dir_head; +} + + +/** You must hold the FS lock when calling this function */ + +static status_t +remove_node(struct rootfs *fs, struct rootfs_vnode *directory, struct rootfs_vnode *vnode) +{ + // schedule this vnode to be removed when it's ref goes to zero + status_t status = remove_vnode(fs->id, vnode->id); + if (status < B_OK) + return status; + + rootfs_remove_from_dir(fs, directory, vnode); + notify_entry_removed(fs->id, directory->id, vnode->name, vnode->id); + + return B_OK; +} + + +static status_t +rootfs_remove(struct rootfs *fs, struct rootfs_vnode *dir, const char *name, bool isDirectory) +{ + struct rootfs_vnode *vnode; + status_t status = B_OK; + + mutex_lock(&fs->lock); + + vnode = rootfs_find_in_dir(dir, name); + if (!vnode) + status = B_ENTRY_NOT_FOUND; + else if (isDirectory && !S_ISDIR(vnode->stream.type)) + status = B_NOT_A_DIRECTORY; + else if (!isDirectory && S_ISDIR(vnode->stream.type)) + status = B_IS_A_DIRECTORY; + else if (isDirectory && !rootfs_is_dir_empty(vnode)) + status = B_DIRECTORY_NOT_EMPTY; + + if (status < B_OK) + goto err; + + status = remove_node(fs, dir, vnode); + +err: + mutex_unlock(&fs->lock); + + return status; +} + + +// #pragma mark - + + +static status_t +rootfs_mount(dev_t id, const char *device, uint32 flags, const char *args, + fs_volume *_fs, ino_t *root_vnid) +{ + struct rootfs *fs; + struct rootfs_vnode *vnode; + status_t err; + + TRACE(("rootfs_mount: entry\n")); + + fs = (rootfs*)malloc(sizeof(struct rootfs)); + if (fs == NULL) + return B_NO_MEMORY; + + fs->id = id; + fs->next_vnode_id = 1; + + err = mutex_init(&fs->lock, "rootfs_mutex"); + if (err < B_OK) + goto err1; + + fs->vnode_list_hash = hash_init(ROOTFS_HASH_SIZE, (addr_t)&vnode->all_next - (addr_t)vnode, + &rootfs_vnode_compare_func, &rootfs_vnode_hash_func); + if (fs->vnode_list_hash == NULL) { + err = B_NO_MEMORY; + goto err2; + } + + // create the root vnode + vnode = rootfs_create_vnode(fs, NULL, ".", S_IFDIR | 0777); + if (vnode == NULL) { + err = B_NO_MEMORY; + goto err3; + } + vnode->parent = vnode; + + fs->root_vnode = vnode; + hash_insert(fs->vnode_list_hash, vnode); + publish_vnode(id, vnode->id, vnode); + + *root_vnid = vnode->id; + *_fs = fs; + + return B_OK; + +err3: + hash_uninit(fs->vnode_list_hash); +err2: + mutex_destroy(&fs->lock); +err1: + free(fs); + + return err; +} + + +static status_t +rootfs_unmount(fs_volume _fs) +{ + struct rootfs *fs = (struct rootfs *)_fs; + struct rootfs_vnode *v; + struct hash_iterator i; + + TRACE(("rootfs_unmount: entry fs = %p\n", fs)); + + // release the reference to the root + put_vnode(fs->id, fs->root_vnode->id); + + // delete all of the vnodes + hash_open(fs->vnode_list_hash, &i); + while ((v = (struct rootfs_vnode *)hash_next(fs->vnode_list_hash, &i)) != NULL) { + rootfs_delete_vnode(fs, v, true); + } + hash_close(fs->vnode_list_hash, &i, false); + + hash_uninit(fs->vnode_list_hash); + mutex_destroy(&fs->lock); + free(fs); + + return B_OK; +} + + +static status_t +rootfs_sync(fs_volume fs) +{ + TRACE(("rootfs_sync: entry\n")); + + return B_OK; +} + + +static status_t +rootfs_lookup(fs_volume _fs, fs_vnode _dir, const char *name, ino_t *_id, int *_type) +{ + struct rootfs *fs = (struct rootfs *)_fs; + struct rootfs_vnode *dir = (struct rootfs_vnode *)_dir; + struct rootfs_vnode *vnode,*vdummy; + status_t status; + + TRACE(("rootfs_lookup: entry dir %p, name '%s'\n", dir, name)); + if (!S_ISDIR(dir->stream.type)) + return B_NOT_A_DIRECTORY; + + mutex_lock(&fs->lock); + + // look it up + vnode = rootfs_find_in_dir(dir, name); + if (!vnode) { + status = B_ENTRY_NOT_FOUND; + goto err; + } + + status = get_vnode(fs->id, vnode->id, (fs_vnode *)&vdummy); + if (status < B_OK) + goto err; + + *_id = vnode->id; + *_type = vnode->stream.type; + +err: + mutex_unlock(&fs->lock); + + return status; +} + + +static status_t +rootfs_get_vnode_name(fs_volume _fs, fs_vnode _vnode, char *buffer, size_t bufferSize) +{ + struct rootfs_vnode *vnode = (struct rootfs_vnode *)_vnode; + + TRACE(("rootfs_get_vnode_name: vnode = %p (name = %s)\n", vnode, vnode->name)); + + strlcpy(buffer, vnode->name, bufferSize); + return B_OK; +} + + +static status_t +rootfs_get_vnode(fs_volume _fs, ino_t id, fs_vnode *_vnode, bool reenter) +{ + struct rootfs *fs = (struct rootfs *)_fs; + struct rootfs_vnode *vnode; + + TRACE(("rootfs_getvnode: asking for vnode %Ld, r %d\n", id, reenter)); + + if (!reenter) + mutex_lock(&fs->lock); + + vnode = (rootfs_vnode*)hash_lookup(fs->vnode_list_hash, &id); + + if (!reenter) + mutex_unlock(&fs->lock); + + TRACE(("rootfs_getnvnode: looked it up at %p\n", *_vnode)); + + if (vnode == NULL) + return B_ENTRY_NOT_FOUND; + + *_vnode = vnode; + return B_OK; +} + + +static status_t +rootfs_put_vnode(fs_volume _fs, fs_vnode _vnode, bool reenter) +{ +#ifdef TRACE_ROOTFS + struct rootfs_vnode *vnode = (struct rootfs_vnode *)_vnode; + + TRACE(("rootfs_putvnode: entry on vnode 0x%Lx, r %d\n", vnode->id, reenter)); +#endif + return B_OK; // whatever +} + + +static status_t +rootfs_remove_vnode(fs_volume _fs, fs_vnode _vnode, bool reenter) +{ + struct rootfs *fs = (struct rootfs *)_fs; + struct rootfs_vnode *vnode = (struct rootfs_vnode *)_vnode; + + TRACE(("rootfs_remove_vnode: remove %p (0x%Lx), r %d\n", vnode, vnode->id, reenter)); + + if (!reenter) + mutex_lock(&fs->lock); + + if (vnode->dir_next) { + // can't remove node if it's linked to the dir + panic("rootfs_remove_vnode: vnode %p asked to be removed is present in dir\n", vnode); + } + + rootfs_delete_vnode(fs, vnode, false); + + if (!reenter) + mutex_unlock(&fs->lock); + + return B_OK; +} + + +static status_t +rootfs_create(fs_volume _fs, fs_vnode _dir, const char *name, int omode, + int perms, fs_cookie *_cookie, ino_t *new_vnid) +{ + return B_BAD_VALUE; +} + + +static status_t +rootfs_open(fs_volume _fs, fs_vnode _v, int oflags, fs_cookie *_cookie) +{ + // allow to open the file, but it can't be done anything with it + + *_cookie = NULL; + return B_OK; +} + + +static status_t +rootfs_close(fs_volume _fs, fs_vnode _v, fs_cookie _cookie) +{ +#ifdef TRACE_ROOTFS + struct rootfs_vnode *v = _v; + struct rootfs_cookie *cookie = _cookie; + + TRACE(("rootfs_close: entry vnode %p, cookie %p\n", v, cookie)); +#endif + return B_OK; +} + + +static status_t +rootfs_free_cookie(fs_volume _fs, fs_vnode _v, fs_cookie _cookie) +{ + return B_OK; +} + + +static status_t +rootfs_fsync(fs_volume _fs, fs_vnode _v) +{ + return B_OK; +} + + +static status_t +rootfs_read(fs_volume _fs, fs_vnode _vnode, fs_cookie _cookie, + off_t pos, void *buffer, size_t *_length) +{ + return EINVAL; +} + + +static status_t +rootfs_write(fs_volume fs, fs_vnode vnode, fs_cookie cookie, + off_t pos, const void *buffer, size_t *_length) +{ + TRACE(("rootfs_write: vnode %p, cookie %p, pos 0x%Lx , len 0x%lx\n", + vnode, cookie, pos, *_length)); + + return EPERM; +} + + +static status_t +rootfs_create_dir(fs_volume _fs, fs_vnode _dir, const char *name, int mode, + ino_t *_newID) +{ + struct rootfs *fs = (rootfs*)_fs; + struct rootfs_vnode *dir = (rootfs_vnode*)_dir; + struct rootfs_vnode *vnode; + status_t status = 0; + + TRACE(("rootfs_create_dir: dir %p, name = '%s', perms = %d, id = 0x%Lx pointer id = %p\n", + dir, name, mode,*_newID, _newID)); + + mutex_lock(&fs->lock); + + vnode = rootfs_find_in_dir(dir, name); + if (vnode != NULL) { + status = B_FILE_EXISTS; + goto err; + } + + TRACE(("rootfs_create: creating new vnode\n")); + vnode = rootfs_create_vnode(fs, dir, name, S_IFDIR | (mode & S_IUMSK)); + if (vnode == NULL) { + status = B_NO_MEMORY; + goto err; + } + + rootfs_insert_in_dir(fs, dir, vnode); + hash_insert(fs->vnode_list_hash, vnode); + + notify_entry_created(fs->id, dir->id, name, vnode->id); + + mutex_unlock(&fs->lock); + return B_OK; + +err: + mutex_unlock(&fs->lock); + + return status; +} + + +static status_t +rootfs_remove_dir(fs_volume _fs, fs_vnode _dir, const char *name) +{ + struct rootfs *fs = (rootfs*)_fs; + struct rootfs_vnode *dir = (rootfs_vnode*)_dir; + + TRACE(("rootfs_remove_dir: dir %p (0x%Lx), name '%s'\n", dir, dir->id, name)); + + return rootfs_remove(fs, dir, name, true); +} + + +static status_t +rootfs_open_dir(fs_volume _fs, fs_vnode _v, fs_cookie *_cookie) +{ + struct rootfs *fs = (struct rootfs *)_fs; + struct rootfs_vnode *vnode = (struct rootfs_vnode *)_v; + struct rootfs_dir_cookie *cookie; + + TRACE(("rootfs_open: vnode %p\n", vnode)); + + if (!S_ISDIR(vnode->stream.type)) + return B_BAD_VALUE; + + cookie = (rootfs_dir_cookie*)malloc(sizeof(struct rootfs_dir_cookie)); + if (cookie == NULL) + return B_NO_MEMORY; + + mutex_lock(&fs->lock); + + cookie->current = vnode->stream.dir.dir_head; + cookie->state = ITERATION_STATE_BEGIN; + + list_add_item(&vnode->stream.dir.cookies, cookie); + *_cookie = cookie; + + mutex_unlock(&fs->lock); + + return B_OK; +} + + +static status_t +rootfs_free_dir_cookie(fs_volume _fs, fs_vnode _vnode, fs_cookie _cookie) +{ + struct rootfs_dir_cookie *cookie = (rootfs_dir_cookie*)_cookie; + struct rootfs_vnode *vnode = (rootfs_vnode*)_vnode; + struct rootfs *fs = (rootfs*)_fs; + + mutex_lock(&fs->lock); + list_remove_item(&vnode->stream.dir.cookies, cookie); + mutex_unlock(&fs->lock); + + free(cookie); + return B_OK; +} + + +static status_t +rootfs_read_dir(fs_volume _fs, fs_vnode _vnode, fs_cookie _cookie, struct dirent *dirent, size_t bufferSize, uint32 *_num) +{ + struct rootfs_vnode *vnode = (struct rootfs_vnode *)_vnode; + struct rootfs_dir_cookie *cookie = (rootfs_dir_cookie*)_cookie; + struct rootfs *fs = (rootfs*)_fs; + status_t status = B_OK; + struct rootfs_vnode *childNode = NULL; + const char *name = NULL; + struct rootfs_vnode *nextChildNode = NULL; + int nextState = cookie->state; + + TRACE(("rootfs_read_dir: vnode %p, cookie %p, buffer = %p, bufferSize = %ld, num = %p\n", _vnode, cookie, dirent, bufferSize,_num)); + + mutex_lock(&fs->lock); + + switch (cookie->state) { + case ITERATION_STATE_DOT: + childNode = vnode; + name = "."; + nextChildNode = vnode->stream.dir.dir_head; + nextState = cookie->state + 1; + break; + case ITERATION_STATE_DOT_DOT: + childNode = vnode->parent; + name = ".."; + nextChildNode = vnode->stream.dir.dir_head; + nextState = cookie->state + 1; + break; + default: + childNode = cookie->current; + if (childNode) { + name = childNode->name; + nextChildNode = childNode->dir_next; + } + break; + } + + if (!childNode) { + // we're at the end of the directory + *_num = 0; + goto err; + } + + dirent->d_dev = fs->id; + dirent->d_ino = childNode->id; + dirent->d_reclen = strlen(name) + sizeof(struct dirent); + + if (dirent->d_reclen > bufferSize) { + status = ENOBUFS; + goto err; + } + + status = user_strlcpy(dirent->d_name, name, + bufferSize - sizeof(struct dirent)); + if (status < B_OK) + goto err; + + cookie->current = nextChildNode; + cookie->state = nextState; + status = B_OK; + +err: + mutex_unlock(&fs->lock); + + return status; +} + + +static status_t +rootfs_rewind_dir(fs_volume _fs, fs_vnode _vnode, fs_cookie _cookie) +{ + struct rootfs_dir_cookie *cookie = (rootfs_dir_cookie*)_cookie; + struct rootfs_vnode *vnode = (rootfs_vnode*)_vnode; + struct rootfs *fs = (rootfs*)_fs; + + mutex_lock(&fs->lock); + + cookie->current = vnode->stream.dir.dir_head; + cookie->state = ITERATION_STATE_BEGIN; + + mutex_unlock(&fs->lock); + return B_OK; +} + + +static status_t +rootfs_ioctl(fs_volume _fs, fs_vnode _v, fs_cookie _cookie, ulong op, void *buf, size_t len) +{ + TRACE(("rootfs_ioctl: vnode %p, cookie %p, op %ld, buf %p, len %ld\n", _v, _cookie, op, buf, len)); + + return EINVAL; +} + + +static bool +rootfs_can_page(fs_volume _fs, fs_vnode _v, fs_cookie cookie) +{ + return false; +} + + +static status_t +rootfs_read_pages(fs_volume _fs, fs_vnode _v, fs_cookie cookie, off_t pos, + const iovec *vecs, size_t count, size_t *_numBytes, bool mayBlock, + bool reenter) +{ + return B_NOT_ALLOWED; +} + + +static status_t +rootfs_write_pages(fs_volume _fs, fs_vnode _v, fs_cookie cookie, off_t pos, + const iovec *vecs, size_t count, size_t *_numBytes, bool mayBlock, + bool reenter) +{ + return B_NOT_ALLOWED; +} + + +static status_t +rootfs_read_link(fs_volume _fs, fs_vnode _link, char *buffer, size_t *_bufferSize) +{ + struct rootfs_vnode *link = (rootfs_vnode*)_link; + size_t bufferSize = *_bufferSize; + + if (!S_ISLNK(link->stream.type)) + return B_BAD_VALUE; + + *_bufferSize = link->stream.symlink.length + 1; + // we always need to return the number of bytes we intend to write! + + if (bufferSize <= link->stream.symlink.length) + return B_BUFFER_OVERFLOW; + + memcpy(buffer, link->stream.symlink.path, link->stream.symlink.length + 1); + return B_OK; +} + + +static status_t +rootfs_symlink(fs_volume _fs, fs_vnode _dir, const char *name, const char *path, int mode) +{ + struct rootfs *fs = (rootfs*)_fs; + struct rootfs_vnode *dir = (rootfs_vnode*)_dir; + struct rootfs_vnode *vnode; + status_t status = B_OK; + + TRACE(("rootfs_symlink: dir %p, name = '%s', path = %s\n", dir, name, path)); + + mutex_lock(&fs->lock); + + vnode = rootfs_find_in_dir(dir, name); + if (vnode != NULL) { + status = B_FILE_EXISTS; + goto err; + } + + TRACE(("rootfs_create: creating new symlink\n")); + vnode = rootfs_create_vnode(fs, dir, name, S_IFLNK | (mode & S_IUMSK)); + if (vnode == NULL) { + status = B_NO_MEMORY; + goto err; + } + + rootfs_insert_in_dir(fs, dir, vnode); + hash_insert(fs->vnode_list_hash, vnode); + + vnode->stream.symlink.path = strdup(path); + if (vnode->stream.symlink.path == NULL) { + status = B_NO_MEMORY; + goto err1; + } + vnode->stream.symlink.length = strlen(path); + + notify_entry_created(fs->id, dir->id, name, vnode->id); + + mutex_unlock(&fs->lock); + return B_OK; + +err1: + rootfs_delete_vnode(fs, vnode, false); +err: + mutex_unlock(&fs->lock); + return status; +} + + +static status_t +rootfs_unlink(fs_volume _fs, fs_vnode _dir, const char *name) +{ + struct rootfs *fs = (rootfs*)_fs; + struct rootfs_vnode *dir = (rootfs_vnode*)_dir; + + TRACE(("rootfs_unlink: dir %p (0x%Lx), name '%s'\n", dir, dir->id, name)); + + return rootfs_remove(fs, dir, name, false); +} + + +static status_t +rootfs_rename(fs_volume _fs, fs_vnode _fromDir, const char *fromName, fs_vnode _toDir, const char *toName) +{ + struct rootfs *fs = (rootfs*)_fs; + struct rootfs_vnode *fromDirectory = (rootfs_vnode*)_fromDir; + struct rootfs_vnode *toDirectory = (rootfs_vnode*)_toDir; + struct rootfs_vnode *vnode, *targetVnode, *parent; + status_t status; + char *nameBuffer = NULL; + + TRACE(("rootfs_rename: from %p (0x%Lx), fromName '%s', to %p (0x%Lx), toName '%s'\n", + fromDirectory, fromDirectory->id, fromName, toDirectory, toDirectory->id, toName)); + + mutex_lock(&fs->lock); + + vnode = rootfs_find_in_dir(fromDirectory, fromName); + if (vnode != NULL) { + status = B_ENTRY_NOT_FOUND; + goto err; + } + + // make sure the target not a subdirectory of us + parent = toDirectory->parent; + while (parent != NULL) { + if (parent == vnode) { + status = B_BAD_VALUE; + goto err; + } + + parent = parent->parent; + } + + // we'll reuse the name buffer if possible + if (strlen(fromName) >= strlen(toName)) { + nameBuffer = strdup(toName); + if (nameBuffer == NULL) { + status = B_NO_MEMORY; + goto err; + } + } + + targetVnode = rootfs_find_in_dir(toDirectory, toName); + if (targetVnode != NULL) { + // target node exists, let's see if it is an empty directory + if (S_ISDIR(targetVnode->stream.type) && !rootfs_is_dir_empty(targetVnode)) { + status = B_NAME_IN_USE; + goto err; + } + + // so we can cleanly remove it + remove_node(fs, toDirectory, targetVnode); + } + + // change the name on this node + if (nameBuffer == NULL) { + // we can just copy it + strcpy(vnode->name, toName); + } else { + free(vnode->name); + vnode->name = nameBuffer; + } + + // remove it from the dir + rootfs_remove_from_dir(fs, fromDirectory, vnode); + + // Add it back to the dir with the new name. + // We need to do this even in the same directory, + // so that it keeps sorted correctly. + rootfs_insert_in_dir(fs, toDirectory, vnode); + + notify_entry_moved(fs->id, fromDirectory->id, fromName, toDirectory->id, toName, vnode->id); + status = B_OK; + +err: + if (status != B_OK) + free(nameBuffer); + + mutex_unlock(&fs->lock); + + return status; +} + + +static status_t +rootfs_read_stat(fs_volume _fs, fs_vnode _v, struct stat *stat) +{ + struct rootfs *fs = (rootfs*)_fs; + struct rootfs_vnode *vnode = (rootfs_vnode*)_v; + + TRACE(("rootfs_read_stat: vnode %p (0x%Lx), stat %p\n", vnode, vnode->id, stat)); + + // stream exists, but we know to return size 0, since we can only hold directories + stat->st_dev = fs->id; + stat->st_ino = vnode->id; [... truncated: 186 lines follow ...] From bonefish at cs.tu-berlin.de Thu Oct 4 17:05:39 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Thu, 04 Oct 2007 17:05:39 +0200 Subject: [Haiku-commits] r22434 - in haiku/trunk: headers/os/drivers headers/private/fs_shell headers/private/kernel src/add-ons/kernel/file_systems/bfs src/add-ons/kernel/file_systems/cdda src/system/kernel/cache src/system/kernel/fs src/system/kernel/vm In-Reply-To: <200710041245.l94CjJaK019731@sheep.berlios.de> References: <200710041245.l94CjJaK019731@sheep.berlios.de> Message-ID: <20071004170539.1124.2@cs.tu-berlin.de> On 2007-10-04 at 14:45:19 [+0200], axeld at BerliOS wrote: [...] > if (!reenter) { > - if (inode->Lock().TryLock() < B_OK) > + if (mayBlock) > + inode->Lock().Lock(); > + else if (inode->Lock().TryLock() < B_OK) > return B_BUSY; > } I suppose B_WOULD_BLOCK would be the more appropriate error code. :-) CU, Ingo From axeld at mail.berlios.de Thu Oct 4 17:11:49 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 4 Oct 2007 17:11:49 +0200 Subject: [Haiku-commits] r22437 - haiku/trunk/src/add-ons/kernel/file_systems/bfs Message-ID: <200710041511.l94FBn1D031076@sheep.berlios.de> Author: axeld Date: 2007-10-04 17:11:48 +0200 (Thu, 04 Oct 2007) New Revision: 22437 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22437&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp Log: Forgot to replace the error code with the new "mayBlock" logic, thanks Ingo! Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp 2007-10-04 14:30:50 UTC (rev 22436) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp 2007-10-04 15:11:48 UTC (rev 22437) @@ -354,7 +354,7 @@ if (mayBlock) inode->Lock().Lock(); else if (inode->Lock().TryLock() < B_OK) - return B_BUSY; + return B_WOULD_BLOCK; } status_t status = file_cache_read_pages(inode->FileCache(), pos, vecs, @@ -381,7 +381,7 @@ if (mayBlock) inode->Lock().Lock(); else if (inode->Lock().TryLock() < B_OK) - return B_BUSY; + return B_WOULD_BLOCK; } status_t status = file_cache_write_pages(inode->FileCache(), pos, vecs, From axeld at mail.berlios.de Thu Oct 4 18:36:37 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 4 Oct 2007 18:36:37 +0200 Subject: [Haiku-commits] r22438 - in haiku/trunk: headers/private/kernel src/system/kernel/vm Message-ID: <200710041636.l94GabDX026454@sheep.berlios.de> Author: axeld Date: 2007-10-04 18:36:35 +0200 (Thu, 04 Oct 2007) New Revision: 22438 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22438&view=rev Modified: haiku/trunk/headers/private/kernel/vm.h haiku/trunk/src/system/kernel/vm/vm.cpp haiku/trunk/src/system/kernel/vm/vm_daemons.cpp haiku/trunk/src/system/kernel/vm/vm_page.cpp Log: * vm_remove_all_page_mappings() now returns an accumulation of the flags of the unmapped page. * This is needed by everyone who calls this to make sure modifications to a page aren't ignored. Namely, the page scanner and the page thief were affected. * Cleaned up locking the page's cache a bit in page_thief(); there is now a helper class that takes care of everything. Modified: haiku/trunk/headers/private/kernel/vm.h =================================================================== --- haiku/trunk/headers/private/kernel/vm.h 2007-10-04 15:11:48 UTC (rev 22437) +++ haiku/trunk/headers/private/kernel/vm.h 2007-10-04 16:36:35 UTC (rev 22438) @@ -130,7 +130,7 @@ bool vm_test_map_modification(struct vm_page *page); int32 vm_test_map_activation(struct vm_page *page, bool *_modified); void vm_clear_map_flags(struct vm_page *page, uint32 flags); -void vm_remove_all_page_mappings(struct vm_page *page); +void vm_remove_all_page_mappings(struct vm_page *page, uint32 *_flags); status_t vm_unmap_pages(struct vm_area *area, addr_t base, size_t length); status_t vm_map_page(struct vm_area *area, struct vm_page *page, addr_t address, uint32 protection); Modified: haiku/trunk/src/system/kernel/vm/vm.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm.cpp 2007-10-04 15:11:48 UTC (rev 22437) +++ haiku/trunk/src/system/kernel/vm/vm.cpp 2007-10-04 16:36:35 UTC (rev 22438) @@ -2433,9 +2433,14 @@ } +/*! Removes all mappings from a page. + After you've called this function, the page is unmapped from memory. + The accumulated page flags of all mappings can be found in \a _flags. +*/ void -vm_remove_all_page_mappings(vm_page *page) +vm_remove_all_page_mappings(vm_page *page, uint32 *_flags) { + uint32 accumulatedFlags = 0; MutexLocker locker(sMappingLock); vm_page_mappings queue; @@ -2446,13 +2451,19 @@ while ((mapping = iterator.Next()) != NULL) { vm_area *area = mapping->area; vm_translation_map *map = &area->address_space->translation_map; + addr_t physicalAddress; + uint32 flags; map->ops->lock(map); addr_t base = area->base + (page->cache_offset << PAGE_SHIFT); map->ops->unmap(map, base, base + (B_PAGE_SIZE - 1)); + map->ops->flush(map); + map->ops->query(map, base, &physicalAddress, &flags); map->ops->unlock(map); area->mappings.Remove(mapping); + + accumulatedFlags |= flags; } locker.Unlock(); @@ -2462,6 +2473,9 @@ while ((mapping = queue.RemoveHead()) != NULL) { free(mapping); } + + if (_flags != NULL) + *_flags = accumulatedFlags; } Modified: haiku/trunk/src/system/kernel/vm/vm_daemons.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_daemons.cpp 2007-10-04 15:11:48 UTC (rev 22437) +++ haiku/trunk/src/system/kernel/vm/vm_daemons.cpp 2007-10-04 16:36:35 UTC (rev 22438) @@ -139,7 +139,15 @@ page->usage_count--; if (page->usage_count < 0) { - vm_remove_all_page_mappings(page); + uint32 flags; + vm_remove_all_page_mappings(page, &flags); + + // recheck eventual last minute changes + if ((flags & PAGE_MODIFIED) != 0 && page->state != PAGE_STATE_MODIFIED) + vm_page_set_state(page, PAGE_STATE_MODIFIED); + if ((flags & PAGE_ACCESSED) != 0 && ++page->usage_count >= 0) + return false; + if (page->state == PAGE_STATE_MODIFIED) vm_page_schedule_write_page(page); else Modified: haiku/trunk/src/system/kernel/vm/vm_page.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_page.cpp 2007-10-04 15:11:48 UTC (rev 22437) +++ haiku/trunk/src/system/kernel/vm/vm_page.cpp 2007-10-04 16:36:35 UTC (rev 22438) @@ -842,34 +842,67 @@ // try to lock the page's cache - vm_cache* cache = vm_cache_acquire_page_cache_ref(page); - if (cache == NULL) + class PageCacheTryLocker { + public: + PageCacheTryLocker(vm_page *page) + : fIsLocked(false) + { + fCache = vm_cache_acquire_page_cache_ref(page); + if (fCache != NULL + && mutex_trylock(&fCache->lock) == B_OK) { + if (fCache == page->cache) + fIsLocked = true; + else + mutex_unlock(&fCache->lock); + } + } + + ~PageCacheTryLocker() + { + if (fIsLocked) + mutex_unlock(&fCache->lock); + + vm_cache_release_ref(fCache); + } + + bool IsLocked() { return fIsLocked; } + + private: + vm_cache *fCache; + bool fIsLocked; + } cacheLocker(page); + + if (!cacheLocker.IsLocked()) continue; - if (mutex_trylock(&cache->lock) != B_OK) { - vm_cache_release_ref(cache); - continue; - } if (page->state != PAGE_STATE_INACTIVE) { // TODO: if this is an active page (as in stealActive), we need // to unmap it and check if it's modified in an atomic operation. // For now, we'll just ignore it, even though this might let // vm_page_allocate_page() wait forever... - mutex_unlock(&cache->lock); - vm_cache_release_ref(cache); continue; } + // recheck eventual last minute changes + uint32 flags; + vm_remove_all_page_mappings(page, &flags); + if ((flags & PAGE_MODIFIED) != 0) { + // page was modified, don't steal it + vm_page_set_state(page, PAGE_STATE_MODIFIED); + continue; + } else if ((flags & PAGE_ACCESSED) != 0) { + // page is in active use, don't steal it + vm_page_set_state(page, PAGE_STATE_ACTIVE); + continue; + } + // we can now steal this page //dprintf(" steal page %p from cache %p\n", page, cache); - vm_remove_all_page_mappings(page); - vm_cache_remove_page(cache, page); + + vm_cache_remove_page(page->cache, page); vm_page_set_state(page, PAGE_STATE_FREE); steal--; - - mutex_unlock(&cache->lock); - vm_cache_release_ref(cache); } } From axeld at mail.berlios.de Thu Oct 4 18:53:03 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 4 Oct 2007 18:53:03 +0200 Subject: [Haiku-commits] r22439 - haiku/trunk/src/system/kernel/vm Message-ID: <200710041653.l94Gr3r1013811@sheep.berlios.de> Author: axeld Date: 2007-10-04 18:53:02 +0200 (Thu, 04 Oct 2007) New Revision: 22439 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22439&view=rev Modified: haiku/trunk/src/system/kernel/vm/vm_page.cpp Log: * Added some docs. * Removed dead code. Modified: haiku/trunk/src/system/kernel/vm/vm_page.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_page.cpp 2007-10-04 16:36:35 UTC (rev 22438) +++ haiku/trunk/src/system/kernel/vm/vm_page.cpp 2007-10-04 16:53:02 UTC (rev 22439) @@ -175,6 +175,9 @@ } +/*! Moves a page to the tail of the given queue, but only does so if + the page is currently in another queue. +*/ static void move_page_to_queue(page_queue *fromQueue, page_queue *toQueue, vm_page *page) { @@ -422,56 +425,6 @@ } -#if 0 -static int dump_free_page_table(int argc, char **argv) -{ - unsigned int i = 0; - unsigned int free_start = END_OF_LIST; - unsigned int inuse_start = PAGE_INUSE; - - dprintf("dump_free_page_table():\n"); - dprintf("first_free_page_index = %d\n", first_free_page_index); - - while(i < free_page_table_size) { - if (free_page_table[i] == PAGE_INUSE) { - if (inuse_start != PAGE_INUSE) { - i++; - continue; - } - if (free_start != END_OF_LIST) { - dprintf("free from %d -> %d\n", free_start + free_page_table_base, i-1 + free_page_table_base); - free_start = END_OF_LIST; - } - inuse_start = i; - } else { - if (free_start != END_OF_LIST) { - i++; - continue; - } - if (inuse_start != PAGE_INUSE) { - dprintf("inuse from %d -> %d\n", inuse_start + free_page_table_base, i-1 + free_page_table_base); - inuse_start = PAGE_INUSE; - } - free_start = i; - } - i++; - } - if (inuse_start != PAGE_INUSE) { - dprintf("inuse from %d -> %d\n", inuse_start + free_page_table_base, i-1 + free_page_table_base); - } - if (free_start != END_OF_LIST) { - dprintf("free from %d -> %d\n", free_start + free_page_table_base, i-1 + free_page_table_base); - } -/* - for (i = 0; i < free_page_table_size; i++) { - dprintf("%d->%d ", i, free_page_table[i]); - } -*/ - return 0; -} -#endif - - static status_t set_page_state_nolock(vm_page *page, int pageState) { @@ -669,6 +622,12 @@ } +/*! The page writer continuously takes some pages from the modified + queue, writes them back, and moves them back to the active queue. + It runs in its own thread, and is only there to keep the number + of modified pages low, so that more pages can be reused with + fewer costs. +*/ status_t page_writer(void* /*unused*/) { @@ -760,6 +719,12 @@ } +/*! The page thief is a "service" that runs in its own thread, and only + gets active in low memory situations. + Its job is to remove unused pages from caches and recycle it. When + low memory is critical, this is potentially the only source of free + pages for the system, so it cannot block on an external service. +*/ static status_t page_thief(void* /*unused*/) { @@ -910,6 +875,10 @@ } +/*! This triggers a run of the page thief - depending on the memory + pressure, it might not actually do anything, though. + This function is registered as a low memory handler. +*/ static void schedule_page_thief(void* /*unused*/, int32 level) { @@ -920,8 +889,7 @@ // #pragma mark - private kernel API -/*! - You need to hold the vm_cache lock when calling this function. +/*! You need to hold the vm_cache lock when calling this function. Note that the cache lock is released in this function. */ status_t @@ -1109,16 +1077,17 @@ status_t vm_page_init_post_thread(kernel_args *args) { - thread_id thread; - // create a kernel thread to clear out pages - thread = spawn_kernel_thread(&page_scrubber, "page scrubber", + + thread_id thread = spawn_kernel_thread(&page_scrubber, "page scrubber", B_LOWEST_ACTIVE_PRIORITY, NULL); send_signal_etc(thread, SIGCONT, B_DO_NOT_RESCHEDULE); new (&sFreePageCondition) ConditionVariable; sFreePageCondition.Publish(&sFreePageQueue, "free page"); + // start page writer and page thief + sWriterWaitSem = create_sem(0, "page writer"); sThiefWaitSem = create_sem(0, "page thief"); @@ -1191,6 +1160,11 @@ } +/*! Unreserve pages previously reserved with vm_page_reserve_pages(). + Note, you specify the same \a count here that you specified when + reserving the pages - you don't need to keep track how many pages + you actually needed of that upfront allocation. +*/ void vm_page_unreserve_pages(uint32 count) { @@ -1204,6 +1178,11 @@ } +/*! With this call, you can reserve a number of free pages in the system. + They will only be handed out to someone who has actually reserved them. + This call returns as soon as the number of requested pages has been + reached. +*/ void vm_page_reserve_pages(uint32 count) { @@ -1305,8 +1284,7 @@ } -/*! - Allocates a number of pages and puts their pointers into the provided +/*! Allocates a number of pages and puts their pointers into the provided array. All pages are marked busy. Returns B_OK on success, and B_NO_MEMORY when there aren't any free pages left to allocate. @@ -1334,6 +1312,7 @@ vm_page * vm_page_allocate_page_run(int pageState, addr_t length) { + // TODO: make sure this one doesn't steal reserved pages! vm_page *firstPage = NULL; uint32 start = 0; @@ -1414,6 +1393,9 @@ } +/*! Moves a page to either the tail of the head of its current queue, + depending on \a tail. +*/ void vm_page_requeue(struct vm_page *page, bool tail) { From bonefish at mail.berlios.de Thu Oct 4 19:59:30 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Thu, 4 Oct 2007 19:59:30 +0200 Subject: [Haiku-commits] r22440 - haiku/trunk/src/system/kernel/disk_device_manager/jobs Message-ID: <200710041759.l94HxU5S028565@sheep.berlios.de> Author: bonefish Date: 2007-10-04 19:59:29 +0200 (Thu, 04 Oct 2007) New Revision: 22440 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22440&view=rev Modified: haiku/trunk/src/system/kernel/disk_device_manager/jobs/KScanPartitionJob.cpp Log: gcc 4 warned unnecessarily. Modified: haiku/trunk/src/system/kernel/disk_device_manager/jobs/KScanPartitionJob.cpp =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/jobs/KScanPartitionJob.cpp 2007-10-04 16:53:02 UTC (rev 22439) +++ haiku/trunk/src/system/kernel/disk_device_manager/jobs/KScanPartitionJob.cpp 2007-10-04 17:59:29 UTC (rev 22440) @@ -88,7 +88,7 @@ ) // publish the partition - status_t error; + status_t error = B_OK; if (!partition->IsPublished()) { error = partition->PublishDevice(); if (error != B_OK) From bonefish at mail.berlios.de Thu Oct 4 20:03:25 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Thu, 4 Oct 2007 20:03:25 +0200 Subject: [Haiku-commits] r22441 - in haiku/trunk: headers/os/drivers headers/private/fs_shell headers/private/kernel/disk_device_manager src/system/kernel/disk_device_manager src/tools/fs_shell Message-ID: <200710041803.l94I3P5s028920@sheep.berlios.de> Author: bonefish Date: 2007-10-04 20:03:24 +0200 (Thu, 04 Oct 2007) New Revision: 22441 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22441&view=rev Added: haiku/trunk/src/tools/fs_shell/disk_device_manager.cpp Modified: haiku/trunk/headers/os/drivers/disk_device_manager.h haiku/trunk/headers/private/fs_shell/fssh_api_wrapper.h haiku/trunk/headers/private/fs_shell/fssh_disk_device_manager.h haiku/trunk/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h haiku/trunk/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp haiku/trunk/src/system/kernel/disk_device_manager/disk_device_manager.cpp haiku/trunk/src/tools/fs_shell/Jamfile Log: Added scan_partition() function which can be used by disk systems (e.g. in *_initialize()) to save some work. Modified: haiku/trunk/headers/os/drivers/disk_device_manager.h =================================================================== --- haiku/trunk/headers/os/drivers/disk_device_manager.h 2007-10-04 17:59:29 UTC (rev 22440) +++ haiku/trunk/headers/os/drivers/disk_device_manager.h 2007-10-04 18:03:24 UTC (rev 22441) @@ -102,22 +102,25 @@ // partition write access // (write lock required) partition_data *create_child_partition(partition_id partitionID, int32 index, - partition_id childID); + partition_id childID); // childID is an optional input parameter -- -1 to be ignored bool delete_partition(partition_id partitionID); void partition_modified(partition_id partitionID); // tells the disk device manager, that the parition has been modified +status_t scan_partition(partition_id partitionID); + // Service method for disks systems: Synchronously scans the partition. + // Device must not be locked. + // disk systems disk_system_id find_disk_system(const char *name); // jobs bool update_disk_device_job_progress(disk_job_id jobID, float progress); -bool update_disk_device_job_extra_progress(disk_job_id jobID, - const char *info); +bool update_disk_device_job_extra_progress(disk_job_id jobID, const char *info); bool set_disk_device_job_error_message(disk_job_id jobID, const char *message); uint32 update_disk_device_job_interrupt_properties(disk_job_id jobID, - uint32 interruptProperties); + uint32 interruptProperties); // returns one of B_DISK_DEVICE_JOB_{CONTINUE,CANCEL,REVERSE} #ifdef __cplusplus Modified: haiku/trunk/headers/private/fs_shell/fssh_api_wrapper.h =================================================================== --- haiku/trunk/headers/private/fs_shell/fssh_api_wrapper.h 2007-10-04 17:59:29 UTC (rev 22440) +++ haiku/trunk/headers/private/fs_shell/fssh_api_wrapper.h 2007-10-04 18:03:24 UTC (rev 22441) @@ -343,6 +343,8 @@ #define delete_partition fssh_delete_partition #define partition_modified fssh_partition_modified +#define scan_partition fssh_scan_partition + // disk systems #define find_disk_system fssh_find_disk_system Modified: haiku/trunk/headers/private/fs_shell/fssh_disk_device_manager.h =================================================================== --- haiku/trunk/headers/private/fs_shell/fssh_disk_device_manager.h 2007-10-04 17:59:29 UTC (rev 22440) +++ haiku/trunk/headers/private/fs_shell/fssh_disk_device_manager.h 2007-10-04 18:03:24 UTC (rev 22441) @@ -113,6 +113,10 @@ void fssh_partition_modified(fssh_partition_id partitionID); // tells the disk device manager, that the parition has been modified +fssh_status_t fssh_scan_partition(fssh_partition_id partitionID); + // Service method for disks systems: Synchronously scans the partition. + // Device must not be locked. + // disk systems fssh_disk_system_id fssh_find_disk_system(const char *name); Modified: haiku/trunk/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h =================================================================== --- haiku/trunk/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h 2007-10-04 17:59:29 UTC (rev 22440) +++ haiku/trunk/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h 2007-10-04 18:03:24 UTC (rev 22441) @@ -66,6 +66,8 @@ // Both the device and the partition is also registered and must be // unregistered by the caller. + status_t ScanPartition(KPartition* partition, bool async); + partition_id CreateFileDevice(const char *filePath, bool *newlyCreated = NULL, bool async = true); status_t DeleteFileDevice(const char *filePath); Modified: haiku/trunk/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp 2007-10-04 17:59:29 UTC (rev 22440) +++ haiku/trunk/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp 2007-10-04 18:03:24 UTC (rev 22441) @@ -488,9 +488,28 @@ return NULL; } + +// ScanPartition +status_t +KDiskDeviceManager::ScanPartition(KPartition* partition, bool async) +{ +// TODO: This won't do. Locking the DDM while scanning the partition is not a +// good idea. Even locking the device doesn't feels right. Marking the partition +// busy and passing the disk system a temporary clone of the partition_data +// should work as well. + if (DeviceWriteLocker deviceLocker = partition->Device()) { + if (ManagerLocker locker = this) + return _ScanPartition(partition, async); + } + + return B_ERROR; +} + + // CreateFileDevice partition_id -KDiskDeviceManager::CreateFileDevice(const char *filePath, bool *newlyCreated, bool async) +KDiskDeviceManager::CreateFileDevice(const char *filePath, bool *newlyCreated, + bool async) { if (!filePath) return B_BAD_VALUE; @@ -716,7 +735,8 @@ return jobQueue->InitCheck(); if (jobQueue->IsExecuting()) return B_BAD_VALUE; - return (_RemoveJobQueue(jobQueue) ? B_OK : B_ENTRY_NOT_FOUND); + return (_RemoveJobQueue(jobQueue) + ? (status_t)B_OK : (status_t)B_ENTRY_NOT_FOUND); } // DeleteJobQueue Modified: haiku/trunk/src/system/kernel/disk_device_manager/disk_device_manager.cpp =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/disk_device_manager.cpp 2007-10-04 17:59:29 UTC (rev 22440) +++ haiku/trunk/src/system/kernel/disk_device_manager/disk_device_manager.cpp 2007-10-04 18:03:24 UTC (rev 22441) @@ -178,9 +178,26 @@ void partition_modified(partition_id partitionID) { - // not implemented + // TODO: implemented } + +// scan_partition +status_t +scan_partition(partition_id partitionID) +{ + // get the partition + KDiskDeviceManager* manager = KDiskDeviceManager::Default(); + KPartition* partition = manager->RegisterPartition(partitionID); + if (partition == NULL) + return B_ENTRY_NOT_FOUND; + PartitionRegistrar _(partition, true); + + // scan it + return manager->ScanPartition(partition, false); +} + + // find_disk_system disk_system_id find_disk_system(const char *name) Modified: haiku/trunk/src/tools/fs_shell/Jamfile =================================================================== --- haiku/trunk/src/tools/fs_shell/Jamfile 2007-10-04 17:59:29 UTC (rev 22440) +++ haiku/trunk/src/tools/fs_shell/Jamfile 2007-10-04 18:03:24 UTC (rev 22441) @@ -33,6 +33,7 @@ atomic.cpp block_cache.cpp command_cp.cpp + disk_device_manager.cpp driver_settings.cpp errno.cpp fcntl.cpp Added: haiku/trunk/src/tools/fs_shell/disk_device_manager.cpp =================================================================== --- haiku/trunk/src/tools/fs_shell/disk_device_manager.cpp 2007-10-04 17:59:29 UTC (rev 22440) +++ haiku/trunk/src/tools/fs_shell/disk_device_manager.cpp 2007-10-04 18:03:24 UTC (rev 22441) @@ -0,0 +1,22 @@ +/* + * Copyright 2007, Ingo Weinhold, bonefish at cs.tu-berlin.de. + * Distributed under the terms of the MIT License. + */ + +#include "fssh_disk_device_manager.h" + +#include "fssh_errors.h" + + +fssh_status_t +fssh_scan_partition(fssh_partition_id partitionID) +{ + return FSSH_B_OK; +} + + +bool +fssh_update_disk_device_job_progress(fssh_disk_job_id jobID, float progress) +{ + return true; +} From bonefish at mail.berlios.de Thu Oct 4 20:11:00 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Thu, 4 Oct 2007 20:11:00 +0200 Subject: [Haiku-commits] r22442 - haiku/trunk/src/add-ons/kernel/file_systems/bfs Message-ID: <200710041811.l94IB0NN029548@sheep.berlios.de> Author: bonefish Date: 2007-10-04 20:11:00 +0200 (Thu, 04 Oct 2007) New Revision: 22442 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22442&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp Log: * Implemented bfs_validate_initialize(). It should probably do more checks (e.g. if the partition is big enough), though. * bfs_initialize(): - Report job progress. - Rescan the partition after it has been initialized, so that all partition_data fields are properly initialized. Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp 2007-10-04 18:03:24 UTC (rev 22441) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp 2007-10-04 18:11:00 UTC (rev 22442) @@ -196,19 +196,7 @@ return status; } -#if 0 -static status_t -bfs_initialize(const char *deviceName, void *parms, size_t len) -{ - FUNCTION_START(("deviceName = %s, parameter len = %ld\n", deviceName, len)); - // The backend (to create the file system) is already done; just - // call Volume::Initialize(). - - return B_ERROR; -} -#endif - static status_t bfs_sync(void *_ns) { @@ -2026,6 +2014,49 @@ // #pragma mark - +struct initialize_parameters { + uint32 blockSize; + uint32 flags; + bool verbose; +}; + + +static status_t +parse_initialize_parameters(const char* parameterString, + initialize_parameters& parameters) +{ + parameters.flags = 0; + parameters.verbose = false; + + void *handle = parse_driver_settings_string(parameterString); + if (handle == NULL) + return B_ERROR; + + if (get_driver_boolean_parameter(handle, "noindex", false, true)) + parameters.flags |= VOLUME_NO_INDICES; + if (get_driver_boolean_parameter(handle, "verbose", false, true)) + parameters.verbose = true; + + const char *string = get_driver_parameter(handle, "block_size", + NULL, NULL); + uint32 blockSize = 1024; + if (string != NULL) + blockSize = strtoul(string, NULL, 0); + + delete_driver_settings(handle); + + if (blockSize != 1024 && blockSize != 2048 && blockSize != 4096 + && blockSize != 8192) { + INFORM(("valid block sizes are: 1024, 2048, 4096, and 8192\n")); + return B_BAD_VALUE; + } + + parameters.blockSize = blockSize; + + return B_OK; +} + + static uint32 bfs_get_supported_operations(partition_data* partition, uint32 mask) { @@ -2037,50 +2068,58 @@ static bool bfs_validate_initialize(partition_data *partition, char *name, - const char *parameters) + const char *parameterString) { - // TODO: Actual checks. - return true; + if (name == NULL) + return B_BAD_VALUE; + + // truncate the name, if it is too long + size_t nameLen = strlen(name); + if (nameLen >= BFS_DISK_NAME_LENGTH) { + nameLen = BFS_DISK_NAME_LENGTH - 1; + name[nameLen] = '\0'; + } + + // replace '/' by '-' + while ((name = strchr(name, '/')) != NULL) + *name = '-'; + + // parse parameters + initialize_parameters parameters; + return (parse_initialize_parameters(parameterString, parameters) == B_OK); } static status_t -bfs_initialize(int fd, partition_id partition, const char *name, - const char *parameters, disk_job_id job) +bfs_initialize(int fd, partition_id partitionID, const char *name, + const char *parameterString, disk_job_id job) { - uint32 blockSize = 1024; - uint32 flags = 0; - bool verbose = false; + // parse parameters + initialize_parameters parameters; + status_t status = parse_initialize_parameters(parameterString, parameters); + if (status != B_OK) + return status; - void *handle = parse_driver_settings_string(parameters); - if (handle != NULL) { - if (get_driver_boolean_parameter(handle, "noindex", false, true)) - flags |= VOLUME_NO_INDICES; - if (get_driver_boolean_parameter(handle, "verbose", false, true)) - verbose = true; + update_disk_device_job_progress(job, 0); - const char *string = get_driver_parameter(handle, "block_size", - NULL, NULL); - if (string != NULL) - blockSize = strtoul(string, NULL, 0); - - delete_driver_settings(handle); - } - - if (blockSize != 1024 && blockSize != 2048 && blockSize != 4096 - && blockSize != 8192) { - INFORM(("valid block sizes are: 1024, 2048, 4096, and 8192\n")); - return B_BAD_VALUE; - } - + // initialize the volume Volume volume(-1); - status_t status = volume.Initialize(fd, name, blockSize, flags); + status = volume.Initialize(fd, name, parameters.blockSize, + parameters.flags); if (status < B_OK) { INFORM(("Initializing volume failed: %s\n", strerror(status))); return status; } - if (verbose) { + // rescan partition + status = scan_partition(partitionID); + if (status != B_OK) + return status; + + update_disk_device_job_progress(job, 1); + + // print some info, if desired + if (parameters.verbose) { disk_super_block super = volume.SuperBlock(); INFORM(("Disk was initialized successfully.\n")); From bonefish at mail.berlios.de Thu Oct 4 20:27:25 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Thu, 4 Oct 2007 20:27:25 +0200 Subject: [Haiku-commits] r22443 - haiku/trunk/src/add-ons/kernel/partitioning_systems/intel Message-ID: <200710041827.l94IRPGN030694@sheep.berlios.de> Author: bonefish Date: 2007-10-04 20:27:25 +0200 (Thu, 04 Oct 2007) New Revision: 22443 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22443&view=rev Added: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/intel.h haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/write_support.cpp haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/write_support.h Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/Jamfile haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/intel.cpp Log: Moved the write support code into a separate source file. Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/Jamfile 2007-10-04 18:11:00 UTC (rev 22442) +++ haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/Jamfile 2007-10-04 18:27:25 UTC (rev 22443) @@ -11,7 +11,8 @@ PartitionMap.cpp PartitionMapParser.cpp PartitionMapWriter.cpp - ; + write_support.cpp +; # Also build a userland version # ToDo: it's probably not a good idea to build them into the same directory Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/intel.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/intel.cpp 2007-10-04 18:11:00 UTC (rev 22442) +++ haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/intel.cpp 2007-10-04 18:27:25 UTC (rev 22443) @@ -9,7 +9,7 @@ /*! \file intel.cpp - \brief disk_scanner partition module for "intel" style partitions. + \brief partitioning system module for "intel" style partitions. */ // TODO: The implementation is very strict right now. It rejects a partition @@ -22,29 +22,39 @@ #include #include -#include +#include + +#include + #include #include + +#include "intel.h" +#include "PartitionLocker.h" +#include "PartitionMap.h" +#include "PartitionMapParser.h" + #ifndef _BOOT_MODE # include +# include "write_support.h" #else # include -//# include "DiskDeviceUtils.h" +# include #endif -#include -#include "PartitionLocker.h" -#include "PartitionMap.h" -#include "PartitionMapParser.h" -#include "PartitionMapWriter.h" //#define TRACE(x) ; #define TRACE(x) dprintf x // module names #define INTEL_PARTITION_MODULE_NAME "partitioning_systems/intel/map/v1" -#define INTEL_EXTENDED_PARTITION_MODULE_NAME "partitioning_systems/intel/extended/v1" +#define INTEL_EXTENDED_PARTITION_MODULE_NAME \ + "partitioning_systems/intel/extended/v1" + +using std::nothrow; + +// TODO: This doesn't belong here! // no atomic_add() in the boot loader #ifdef _BOOT_MODE @@ -59,42 +69,30 @@ #endif -// A PartitionMap with reference count. -struct PartitionMapCookie : PartitionMap { - int32 ref_count; -}; +#ifndef _BOOT_MODE +// get_type_for_content_type (for both pm_* and ep_*) +static status_t +get_type_for_content_type(const char *contentType, char *type) +{ + TRACE(("intel: get_type_for_content_type(%s)\n", + contentType)); + + if (!contentType || !type) + return B_BAD_VALUE; -// Maximal size of move buffer (in sectors). -static const int32 MAX_MOVE_BUFFER = 2 * 1024 * 4; + PartitionType ptype; + ptype.SetContentType(contentType); + if (!ptype.IsValid()) + return B_NAME_NOT_FOUND; -// for logical partitions in Intel Extended Partition -// Count of free sectors after Partition Table Sector (at logical partition). -static const uint32 FREE_SECTORS_AFTER_PTS = 0; -// Count of free sectors after Master Boot Record. -static const uint32 FREE_SECTORS_AFTER_MBR = 0; -// size of logical partition header in blocks -static const uint32 PTS_OFFSET = FREE_SECTORS_AFTER_PTS + 1; -static const uint32 MBR_OFFSET = FREE_SECTORS_AFTER_MBR + 1; + ptype.GetTypeString(type); + return B_OK; +} +#endif -typedef partitionable_space_data PartitionPosition; -typedef void (*fc_get_sibling_partitions)(partition_data *partition, - partition_data *child, off_t childOffset, partition_data **prec, - partition_data **follow, off_t *prec_offset, off_t *prec_size, - off_t *follow_offset, off_t *follow_size); - -typedef int32 (*fc_fill_partitionable_spaces_buffer)(partition_data *partition, - PartitionPosition *positions); - - -static status_t pm_get_partitionable_spaces(partition_data *partition, - partitionable_space_data *buffer, int32 count, int32 *actualCount); -static status_t ep_get_partitionable_spaces(partition_data *partition, - partitionable_space_data *buffer, int32 count, int32 *actualCount); - - // #pragma mark - Intel Partition Map Module @@ -258,1220 +256,6 @@ } } -#ifndef _BOOT_MODE - - -// #pragma mark - Intel Partition Map - support functions - - -// pm_get_supported_operations -static uint32 -pm_get_supported_operations(partition_data* partition, uint32 mask = ~0) -{ - uint32 flags = B_DISK_SYSTEM_SUPPORTS_RESIZING - | B_DISK_SYSTEM_SUPPORTS_MOVING - | B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS - | B_DISK_SYSTEM_SUPPORTS_INITIALIZING; - - // creating child - int32 countSpaces = 0; - if (partition->child_count < 4 - // free space check - && pm_get_partitionable_spaces(partition, NULL, 0, &countSpaces) == B_OK - && countSpaces > 0) { - flags |= B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD; - } - - return flags; -} - - -// pm_get_supported_child_operations -static uint32 -pm_get_supported_child_operations(partition_data* partition, - partition_data* child, uint32 mask = ~0) -{ - return B_DISK_SYSTEM_SUPPORTS_RESIZING_CHILD - | B_DISK_SYSTEM_SUPPORTS_MOVING_CHILD - | B_DISK_SYSTEM_SUPPORTS_SETTING_TYPE - | B_DISK_SYSTEM_SUPPORTS_DELETING_CHILD; -} - - -// pm_is_sub_system_for -static bool -pm_is_sub_system_for(partition_data *partition) -{ - // primary partition map doesn't naturally live in any other child partition - return false; -} - - -// #pragma mark - Intel Partition Map - validate functions - - -// block_align (auxiliary function) -static inline -off_t -block_align(off_t offset, uint32 block_size) -{ - return offset / block_size * block_size; -} - -// block_align_up (auxiliary function) -static inline -off_t -block_align_up(off_t offset, uint32 block_size) -{ - return (offset + block_size - 1) / block_size * block_size; -} - -// validate_resize (auxiliary function) -static bool -validate_resize(partition_data *partition, off_t *size) -{ - off_t new_size = *size; - // size remains the same? - if (new_size == partition->size) - return true; - - if (new_size < 0) - new_size = 0; - else - new_size = block_align(new_size, partition->block_size); - - // grow partition? - if (new_size > partition->size) { - *size = new_size; - return true; - } - - // shrink partition - // no child has to be over the new size of the parent partition - // TODO: shouldn't be just: off_t current_end = new_size; ??? probably not - off_t current_end = partition->offset + new_size; - for (int32 i = 0; i < partition->child_count; i++) { - partition_data *child = get_child_partition(partition->id, i); - if (child && child->offset + child->size > current_end) - current_end = child->offset + child->size; - } - new_size = current_end - partition->offset; - // make the size a multiple of the block size (greater one) - new_size = block_align_up(new_size, partition->block_size); - *size = new_size; - return true; -} - -// pm_validate_resize -static bool -pm_validate_resize(partition_data *partition, off_t *size) -{ - TRACE(("intel: pm_validate_resize\n")); - - if (!partition || !size) - return false; - - return validate_resize(partition, size); -} - -// get_offset_ep (auxiliary function) -static inline off_t -get_offset_ep(const partition_data *partition) -{ - LogicalPartition *logical = (LogicalPartition *)partition->cookie; - off_t diff_offset = logical->Offset() - logical->PTSOffset(); - return partition->offset - diff_offset; -} - -// get_size_ep (auxiliary function) -static inline off_t -get_size_ep(const partition_data *partition) -{ - LogicalPartition *logical = (LogicalPartition *)partition->cookie; - off_t diff_offset = logical->Offset() - logical->PTSOffset(); - return partition->size + diff_offset; -} - - -// get_sibling_partitions_pm (auxiliary function) -/*! - according to childOffset returns previous and next sibling or NULL - precious, next output parameters - partition - Intel Partition Map -*/ -static void -get_sibling_partitions_pm(partition_data *partition, - partition_data *child, off_t childOffset, partition_data **previous, - partition_data **next, off_t *previousOffset, off_t *previousSize, - off_t *nextOffset, off_t *nextSize) -{ - // finding out sibling partitions - partition_data *previousSibling = NULL; - partition_data *nextSibling = NULL; - for (int32 i = 0; i < partition->child_count; i++) { - partition_data *sibling = get_child_partition(partition->id, i); - if (sibling && sibling != child) - if (sibling->offset <= childOffset) { - if (!previousSibling || previousSibling->offset < sibling->offset) - previousSibling = sibling; - } else { - // sibling->offset > childOffset - if (!nextSibling || nextSibling->offset > sibling->offset) - nextSibling = sibling; - } - } - *previous = previousSibling; - *next = nextSibling; - if (previousSibling) { - *previousOffset = previousSibling->offset; - *previousSize = previousSibling->size; - } - if (nextSibling) { - *nextOffset = nextSibling->offset; - *nextSize = nextSibling->size; - } -} - -// get_sibling_partitions_ep (auxiliary function) -/*! - according to childOffset returns previous and next sibling or NULL - previous, next output parameters - partition - Intel Extended Partition -*/ -static void -get_sibling_partitions_ep(partition_data *partition, - partition_data *child, off_t childOffset, partition_data **previous, - partition_data **next, off_t *previousOffset, off_t *previousSize, - off_t *nextOffset, off_t *nextSize) -{ - // finding out sibling partitions - partition_data *previousSibling = NULL; - partition_data *nextSibling = NULL; - for (int32 i = 0; i < partition->child_count; i++) { - partition_data *sibling = get_child_partition(partition->id, i); - if (sibling && sibling != child) - if (get_offset_ep(sibling) <= childOffset) { - if (!previousSibling || previousSibling->offset < sibling->offset) - previousSibling = sibling; - } else { - // get_offset_ep(sibling) > childOffset - if (!nextSibling || nextSibling->offset > sibling->offset) - nextSibling = sibling; - } - } - *previous = previousSibling; - *next = nextSibling; - if (previousSibling) { - *previousOffset = get_offset_ep(previousSibling); - *previousSize = get_size_ep(previousSibling); - } - if (nextSibling) { - *nextOffset = get_offset_ep(nextSibling); - *nextSize = get_size_ep(nextSibling); - } -} - -// validate_resize_child (auxiliary function) -static bool -validate_resize_child(partition_data *partition, partition_data *child, - off_t childOffset, off_t childSize, off_t *size, - fc_get_sibling_partitions getSiblingPartitions) -{ - // size remains the same? - if (*size == childSize) - return true; - // shrink partition? - if (*size < childSize) { - if (*size < 0) - *size = 0; - // make the size a multiple of the block size - *size = block_align(*size, partition->block_size); - return true; - } - // grow partition - // child must completely lie within the parent partition - if (childOffset + *size > partition->offset + partition->size) - *size = partition->offset + partition->size - childOffset; - - // child must not intersect with sibling partitions - // finding out sibling partitions - partition_data *previousSibling = NULL; - partition_data *nextSibling = NULL; - off_t previousOffset = 0, previousSize = 0, nextOffset = 0, nextSize = 0; - - getSiblingPartitions(partition, child, childOffset, &previousSibling, - &nextSibling, &previousOffset, &previousSize, &nextOffset, &nextSize); - - if (nextSibling && (nextOffset < childOffset + *size)) - *size = nextOffset - childOffset; - *size = block_align(*size, partition->block_size); - return true; -} - -// pm_validate_resize_child -static bool -pm_validate_resize_child(partition_data *partition, partition_data *child, - off_t *size) -{ - TRACE(("intel: pm_validate_resize_child\n")); - - if (!partition || !child || !size) - return false; - - return validate_resize_child(partition, child, child->offset, - child->size, size, get_sibling_partitions_pm); -} - -// pm_validate_move -static bool -pm_validate_move(partition_data *partition, off_t *start) -{ - TRACE(("intel: pm_validate_move\n")); - - if (!partition || !start) - return false; - // nothing to do here - return true; -} - -// validate_move_child (auxiliary function) -static bool -validate_move_child(partition_data *partition, partition_data *child, - off_t childOffset, off_t childSize, off_t *_start, - fc_get_sibling_partitions getSiblingPartitions) -{ - off_t start = *_start; - - if (start < 0) - start = 0; - else if (start + childSize > partition->size) - start = partition->size - childSize; - - start = block_align(start, partition->block_size); - - // finding out sibling partitions - partition_data *previousSibling = NULL; - partition_data *nextSibling = NULL; - off_t previousOffset = 0, previousSize = 0, nextOffset = 0, nextSize = 0; - - getSiblingPartitions(partition, child, childOffset, &previousSibling, - &nextSibling, &previousOffset, &previousSize, &nextOffset, &nextSize); - - // we cannot move child over sibling partition - if (start < childOffset) { - // moving left - if (previousSibling && previousOffset + previousSize > start) { - start = previousOffset + previousSize; - start = block_align_up(start, partition->block_size); - } - } else { - // moving right - if (nextSibling && nextOffset < start + childSize) { - start = nextOffset - childSize; - start = block_align(start, partition->block_size); - } - } - *_start = start; - return true; -} - - -// pm_validate_move_child -static bool -pm_validate_move_child(partition_data *partition, partition_data *child, - off_t *start) -{ - TRACE(("intel: pm_validate_move_child\n")); - - if (!partition || !child || !start) - return false; - if (*start == child->offset) - return true; - - return validate_move_child(partition, child, child->offset, - child->size, start, get_sibling_partitions_pm); -} - -// is_type_valid_pm (auxiliary function) -/*! - type has to be known, only one extended partition is allowed - partition - intel partition map - child can be NULL -*/ -static bool -is_type_valid_pm(const char *type, partition_data *partition, - PrimaryPartition *child = NULL) -{ - // validity check of the type - PartitionType ptype; - ptype.SetType(type); - if (!ptype.IsValid() || ptype.IsEmpty()) - return false; - - // only one extended partition is allowed - if (ptype.IsExtended()) { - PartitionMap *map = (PartitionMap*)partition->content_cookie; - if (!map) - return false; - for (int32 i = 0; i < partition->child_count; i++) { - PrimaryPartition *primary = map->PrimaryPartitionAt(i); - if (primary && primary->IsExtended() && primary != child) - return false; - } - } - return true; -} - -// pm_validate_set_type -static bool -pm_validate_set_type(partition_data *partition, const char *type) -{ - TRACE(("intel: pm_validate_set_type\n")); - - if (!partition || !type) - return false; - - partition_data *father = get_parent_partition(partition->id); - if (!father) - return false; - PrimaryPartition *child = (PrimaryPartition*)partition->cookie; - if (!child) - return false; - - // validity check of the type - return is_type_valid_pm(type, father, child); -} - -// pm_validate_initialize -static bool -pm_validate_initialize(partition_data *partition, char *name, - const char *parameters) -{ - TRACE(("intel: pm_validate_initialize\n")); - - if (!partition || !(pm_get_supported_operations(partition) - & B_DISK_SYSTEM_SUPPORTS_INITIALIZING)) { - return false; - } - // name is ignored - we cannot set it to the intel partitioning map - // TODO: check parameters - don't know whether any parameters could be set - // to the intel partition map - return true; -} - -// validate_create_child_partition (auxiliary function) -static bool -validate_create_child_partition(partition_data *partition, off_t *start, - off_t *size, fc_get_sibling_partitions getSiblingPartitions) -{ - // make the start and size a multiple of the block size - *start = block_align(*start, partition->block_size); - if (*size < 0) - *size = 0; - else - *size = block_align(*size, partition->block_size); - - // child must completely lie within the parent partition - if (*start >= partition->offset + partition->size) - return false; - if (*start + *size > partition->offset + partition->size) - *size = partition->offset + partition->size - *start; - - // new child must not intersect with sibling partitions - // finding out sibling partitions - partition_data *previousSibling = NULL; - partition_data *nextSibling = NULL; - off_t previousOffset = 0, previousSize = 0, nextOffset = 0, nextSize = 0; - - getSiblingPartitions(partition, NULL, *start, &previousSibling, - &nextSibling, &previousOffset, &previousSize, &nextOffset, &nextSize); - - // position check of the new partition - if (previousSibling && (previousOffset + previousSize > *start)) { - *start = previousOffset + previousSize; - *start = block_align_up(*start, partition->block_size); - } - - if (nextSibling && (nextOffset < *start + *size)) - *size = nextOffset - *start; - *size = block_align(*size, partition->block_size); - if (*size == 0) - return false; - - return true; -} - -// pm_validate_create_child -/*! - index - returns position of the new partition (first free record in MBR) -*/ -static bool -pm_validate_create_child(partition_data *partition, off_t *start, off_t *size, - const char *type, const char *parameters, int32 *index) -{ - TRACE(("intel: pm_validate_create_child\n")); - - if (!partition || !(pm_get_supported_operations(partition) - & B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD) - || !start || !size || !type || !index) { - return false; - } - - // TODO: check parameters - // type check - if (!is_type_valid_pm(type, partition)) - return false; - - // finding out index of the new partition (first free record in MBR) - // at least one record has to be free - PartitionMap *map = (PartitionMap*)partition->content_cookie; - if (!map) - return false; - int32 newIndex = -1; - for (int32 i = 0; i < 4; i++) { - PrimaryPartition *primary = map->PrimaryPartitionAt(i); - if (primary->IsEmpty()) { - newIndex = i; - break; - } - } - // this cannot happen - if (newIndex < 0) - return false; - *index = newIndex; - - if (*start < partition->offset + MBR_OFFSET * partition->block_size) { - *start = partition->offset + MBR_OFFSET * partition->block_size; - *start = block_align_up(*start, partition->block_size); - } - - return validate_create_child_partition(partition, start, size, - get_sibling_partitions_pm); -} - -// cmp_partition_position -static int -cmp_partition_position(const void *o1, const void *o2) { - off_t offset1 = ((PartitionPosition*)o1)->offset; - off_t offset2 = ((PartitionPosition*)o2)->offset; - if (offset1 < offset2) - return -1; - else if (offset1 > offset2) - return 1; - return 0; -} - -// fill_partitionable_spaces_buffer_pm -/*! - positions - output buffer with sufficient size - returns partition count -*/ -static int32 -fill_partitionable_spaces_buffer_pm(partition_data *partition, - PartitionPosition *positions) -{ - int32 partition_count = 0; - for (int32 i = 0; i < partition->child_count; i++) { - const partition_data *child = get_child_partition(partition->id, i); - if (child) { - positions[partition_count].offset = child->offset; - positions[partition_count].size = child->size; - partition_count++; - } - } - return partition_count; -} - -// fill_partitionable_spaces_buffer_ep -/*! - positions - output buffer with sufficient size - returns partition count -*/ -static int32 -fill_partitionable_spaces_buffer_ep(partition_data *partition, - PartitionPosition *positions) -{ - int32 partition_count = 0; - for (int32 i = 0; i < partition->child_count; i++) { - const partition_data *child = get_child_partition(partition->id, i); - if (child) { - positions[partition_count].offset = get_offset_ep(child); - positions[partition_count].size = get_size_ep(child); - partition_count++; - } - } - return partition_count; -} - -// get_partitionable_spaces (auxiliary function) -static status_t -get_partitionable_spaces(partition_data *partition, - partitionable_space_data *buffer, int32 count, int32 *_actualCount, - fc_fill_partitionable_spaces_buffer fillBuffer, off_t startOffset, - off_t limitSize = 0, off_t headerSize = 0) -{ - PartitionPosition *positions - = new(nothrow) PartitionPosition[partition->child_count]; - if (!positions) - return B_NO_MEMORY; - // fill the array - int32 partition_count = fillBuffer(partition, positions); - // sort the array - qsort(positions, partition_count, sizeof(PartitionPosition), - cmp_partition_position); - - // first sektor is MBR or EBR - off_t offset = startOffset + headerSize; - off_t size = 0; - int32 actualCount = 0; - - // offset alignment (to upper bound) - offset = block_align_up(offset, partition->block_size); - - // finding out all partitionable spaces - for (int32 i = 0; i < partition_count; i++) { - size = positions[i].offset - offset; - size = block_align(size, partition->block_size); - if (size > limitSize) { - if (actualCount < count) { - buffer[actualCount].offset = offset; - buffer[actualCount].size = size; - } - actualCount++; - } - offset = positions[i].offset + positions[i].size + headerSize; - offset = block_align_up(offset, partition->block_size); - } - // space in the end of partition - size = partition->offset + partition->size - offset; - size = block_align(size, partition->block_size); - if (size > 0) { - if (actualCount < count) { - buffer[actualCount].offset = offset; - buffer[actualCount].size = size; - } - actualCount++; - } - - // cleanup - if (positions) - delete[] positions; - - *_actualCount = actualCount; - TRACE(("intel: get_partitionable_spaces - found: %ld\n", actualCount)); - return B_OK; -} - -// pm_get_partitionable_spaces -static status_t -pm_get_partitionable_spaces(partition_data *partition, - partitionable_space_data *buffer, int32 count, int32 *actualCount) -{ - TRACE(("intel: pm_get_partitionable_spaces\n")); - - if (!partition || !partition->content_type - || strcmp(partition->content_type, kPartitionTypeIntel) - || !actualCount) { - return B_BAD_VALUE; - } - if (count > 0 && !buffer) - return B_BAD_VALUE; - - return get_partitionable_spaces(partition, buffer, count, actualCount, - fill_partitionable_spaces_buffer_pm, MBR_OFFSET * partition->block_size, - 0, 0); -} - -// pm_get_next_supported_type -static status_t -pm_get_next_supported_type(partition_data *partition, int32 *cookie, - char *_type) -{ - TRACE(("intel: pm_get_next_supported_type\n")); - - if (!partition || !partition->content_type - || strcmp(partition->content_type, kPartitionTypeIntel) - || !cookie || !_type) { - return B_BAD_VALUE; - } - - if (*cookie > 255) - return B_ENTRY_NOT_FOUND; - if (*cookie < 1) - *cookie = 1; - - uint8 type = *cookie; - - // get type - PartitionType ptype; - ptype.SetType(type); - if (!ptype.IsValid()) - return B_ENTRY_NOT_FOUND; - - ptype.GetTypeString(_type); - - // find next type - if (ptype.FindNext()) - *cookie = ptype.Type(); - else - *cookie = 256; - - return B_OK; -} - -// get_type_for_content_type (for both pm_* and ep_*) -static status_t -get_type_for_content_type(const char *contentType, char *type) -{ - TRACE(("intel: get_type_for_content_type(%s)\n", - contentType)); - - if (!contentType || !type) - return B_BAD_VALUE; - - PartitionType ptype; - ptype.SetContentType(contentType); - if (!ptype.IsValid()) - return B_NAME_NOT_FOUND; - - ptype.GetTypeString(type); - return B_OK; -} - -// pm_shadow_changed -static status_t -pm_shadow_changed(partition_data *partition, uint32 operation) -{ - TRACE(("intel: pm_shadow_changed\n")); - - if (!partition) - return B_BAD_VALUE; - - // nothing to do here - return B_OK; -} - - -// #pragma mark - Intel Partition Map - writing functions - - -// pm_resize -static status_t -pm_resize(int fd, partition_id partitionID, off_t size, disk_job_id job) -{ - TRACE(("intel: pm_resize\n")); - - if (fd < 0) - return B_ERROR; - - PartitionWriteLocker locker(partitionID); - if (!locker.IsLocked()) - return B_ERROR; - - // get out partition - partition_data *partition = get_partition(partitionID); - if (!partition) - return B_BAD_VALUE; - - // validate the new size -// TODO: The parameter has already been checked and must not be altered! - off_t validatedSize = size; - if (!pm_validate_resize(partition, &validatedSize)) - return B_BAD_VALUE; - - // update data stuctures - update_disk_device_job_progress(job, 0.0); - -// TODO: partition->size is not supposed to be touched. - partition->size = validatedSize; - partition->content_size = validatedSize; - - // all changes applied - update_disk_device_job_progress(job, 1.0); - partition_modified(partitionID); - return B_OK; -} - -// pm_resize_child -static status_t -pm_resize_child(int fd, partition_id partitionID, off_t size, disk_job_id job) -{ - TRACE(("intel: pm_resize_child\n")); - - if (fd < 0) - return B_ERROR; - - PartitionWriteLocker locker(partitionID); - if (!locker.IsLocked()) - return B_ERROR; - - // get out partition, child and partition map structure - partition_data *partition = get_parent_partition(partitionID); - partition_data *child = get_partition(partitionID); - if (!partition || !child) - return B_BAD_VALUE; - PartitionMap *map = (PartitionMap*)partition->content_cookie; - PrimaryPartition *primary = (PrimaryPartition*)child->cookie; - if (!map || !primary) - return B_BAD_VALUE; - - // validate the new size -// TODO: The parameter has already been checked and must not be altered! - off_t validatedSize = size; - if (!pm_validate_resize_child(partition, child, &validatedSize)) - return B_BAD_VALUE; - if (child->size == validatedSize) - return B_OK; - - // update data stuctures and write changes - update_disk_device_job_progress(job, 0.0); - primary->SetSize(validatedSize); - -// TODO: The partition is not supposed to be locked here! - PartitionMapWriter writer(fd, 0, partition->size, partition->block_size); - status_t error = writer.WriteMBR(NULL, map); - if (error != B_OK) { - // putting into previous state - primary->SetSize(child->size); - return error; - } - - child->size = validatedSize; - - // all changes applied - update_disk_device_job_progress(job, 1.0); - partition_modified(partitionID); - return B_OK; -} - -// pm_move -static status_t -pm_move(int fd, partition_id partitionID, off_t offset, disk_job_id job) -{ - TRACE(("intel: pm_move\n")); - - if (fd < 0) - return B_ERROR; - -// TODO: Should be a no-op! - - PartitionWriteLocker locker(partitionID); - if (!locker.IsLocked()) - return B_ERROR; - - // get out partition - partition_data *partition = get_partition(partitionID); - if (!partition) - return B_BAD_VALUE; - - // validate the new start - if (!pm_validate_move(partition, &offset)) - return B_BAD_VALUE; - - // nothing to do here - return B_OK; -} - -// allocate_buffer (auxiliary function) -/*! - tries to allocate buffer with the size: blockSize * tryAlloc - if it's not possible, tries smaller buffer (until the size: blockSize * 1) - returns pointer to the buffer (it's size is: blockSize * allocated) - or returns NULL - B_NO_MEMORY -*/ -static uint8* -allocate_buffer(uint32 blockSize, int32 tryAlloc, int32 *allocated) -{ - uint8* buffer = NULL; - for (int32 i = tryAlloc; i > 1; i /= 2) { - buffer = new(nothrow) uint8[i * blockSize]; - if (buffer) { - *allocated = i; - return buffer; - } - } - *allocated = 0; - return NULL; -} - -// move_block (auxiliary function) -static status_t -move_block(int fd, off_t fromOffset, off_t toOffset, uint8 *buffer, int32 size) -{ - status_t error = B_OK; - // read block to buffer - if (read_pos(fd, fromOffset, buffer, size) != size) { - error = errno; - if (error == B_OK) - error = B_IO_ERROR; - TRACE(("intel: move_block(): reading failed: %lx\n", error)); - return error; - } - - // write block from buffer - if (write_pos(fd, toOffset, buffer, size) != size) { - error = errno; - if (error == B_OK) - error = B_IO_ERROR; - TRACE(("intel: move_block(): writing failed: %lx\n", error)); - } - - return error; [... truncated: 3277 lines follow ...] From jackburton at mail.berlios.de Thu Oct 4 21:57:27 2007 From: jackburton at mail.berlios.de (jackburton at BerliOS) Date: Thu, 4 Oct 2007 21:57:27 +0200 Subject: [Haiku-commits] r22444 - haiku/trunk/src/kits/interface Message-ID: <200710041957.l94JvRW8007500@sheep.berlios.de> Author: jackburton Date: 2007-10-04 21:57:27 +0200 (Thu, 04 Oct 2007) New Revision: 22444 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22444&view=rev Modified: haiku/trunk/src/kits/interface/TextView.cpp Log: Mail's inherited InsertText() calls CancelInputMethod() indirectly, and since InsertText() is called inside BTextView::HandleInputMethodChanged(), this method would see fInline slip away from under its feet.. Now we call the BTextView version explicitly. Fixes bug #1022, although I'm not sure if this is completely correct. Modified: haiku/trunk/src/kits/interface/TextView.cpp =================================================================== --- haiku/trunk/src/kits/interface/TextView.cpp 2007-10-04 18:27:25 UTC (rev 22443) +++ haiku/trunk/src/kits/interface/TextView.cpp 2007-10-04 19:57:27 UTC (rev 22444) @@ -806,7 +806,6 @@ switch (opcode) { case B_INPUT_METHOD_STARTED: { - PRINT(("B_INPUT_METHOD_STARTED\n")); BMessenger messenger; if (message->FindMessenger("be:reply_to", &messenger) == B_OK) { ASSERT(fInline == NULL); @@ -816,19 +815,16 @@ } case B_INPUT_METHOD_STOPPED: - PRINT(("B_INPUT_METHOD_STOPPED\n")); delete fInline; fInline = NULL; break; case B_INPUT_METHOD_CHANGED: - PRINT(("B_INPUT_METHOD_CHANGED\n")); if (fInline != NULL) HandleInputMethodChanged(message); break; case B_INPUT_METHOD_LOCATION_REQUEST: - PRINT(("B_INPUT_METHOD_LOCATION_REQUEST\n")); if (fInline != NULL) HandleInputMethodLocationRequest(); break; @@ -3102,8 +3098,6 @@ void BTextView::Refresh(int32 fromOffset, int32 toOffset, bool erase, bool scroll) { - PRINT(("Refresh(fromOffset: %ld, toOffset: %ld, erase: %d, scroll: %d\n", - fromOffset, toOffset, erase, scroll)); // TODO: Cleanup float saveHeight = fTextRect.Height(); int32 fromLine = LineAt(fromOffset); @@ -3644,9 +3638,6 @@ if (!Window()) return; - PRINT(("DrawLines(startLine: %ld, endLine: %ld, startOffset: %ld, erase: %d\n", - startLine, endLine, startOffset, erase)); - // clip the text BRect clipRect = Bounds() & fTextRect; clipRect.InsetBy(-1, -1); @@ -4438,7 +4429,7 @@ // Delete the previously inserted text (if any) if (fInline->IsActive()) { int32 oldOffset = fInline->Offset(); - DeleteText(oldOffset, oldOffset + fInline->Length()); + BTextView::DeleteText(oldOffset, oldOffset + fInline->Length()); fClickOffset = fSelStart = fSelEnd = oldOffset; if (confirmed) @@ -4474,7 +4465,13 @@ fInline->SetSelectionLength(selectionEnd - selectionStart); // Insert the new text - InsertText(string, stringLen, fSelStart, NULL); + // We call the base InsertText(), because inherited method could do bad things: + // Mail, for example, does call InsertText() with a runarray parameter + // (even if we pass NULL here). That causes SetRunArray() to be called, + // which in turn calls CancelInputMethod(), which would destroy fInline + // (and we call some of its functions later). Bug #1022. + // TODO: Check if R5 really does this + BTextView::InsertText(string, stringLen, fSelStart, NULL); fSelStart += stringLen; fClickOffset = fSelEnd = fSelStart; @@ -4522,22 +4519,24 @@ if (!fInline) return; - BMessage message(B_INPUT_METHOD_EVENT); - message.AddInt32("be:opcode", B_INPUT_METHOD_STOPPED); - fInline->Method()->SendMessage(&message); + _BInlineInput_ *inlineInput = fInline; + fInline = NULL; // Delete the previously inserted text (if any) - if (fInline->IsActive()) { - int32 oldOffset = fInline->Offset(); - DeleteText(oldOffset, oldOffset + fInline->Length()); + if (inlineInput->IsActive()) { + int32 oldOffset = inlineInput->Offset(); + DeleteText(oldOffset, oldOffset + inlineInput->Length()); fClickOffset = fSelStart = fSelEnd = oldOffset; } - delete fInline; - fInline = NULL; - if (Window()) Refresh(0, fText->Length(), true, false); + + BMessage message(B_INPUT_METHOD_EVENT); + message.AddInt32("be:opcode", B_INPUT_METHOD_STOPPED); + inlineInput->Method()->SendMessage(&message); + + delete inlineInput; } From korli at mail.berlios.de Fri Oct 5 00:15:58 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Fri, 5 Oct 2007 00:15:58 +0200 Subject: [Haiku-commits] r22445 - in haiku/trunk/src: documentation tools/docbook Message-ID: <200710042215.l94MFw2J016829@sheep.berlios.de> Author: korli Date: 2007-10-05 00:15:58 +0200 (Fri, 05 Oct 2007) New Revision: 22445 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22445&view=rev Removed: haiku/trunk/src/documentation/haiku_book/ haiku/trunk/src/tools/docbook/headersampler/ Modified: haiku/trunk/src/documentation/Jamfile Log: removed former haiku_book and headersampler tool Modified: haiku/trunk/src/documentation/Jamfile =================================================================== --- haiku/trunk/src/documentation/Jamfile 2007-10-04 19:57:27 UTC (rev 22444) +++ haiku/trunk/src/documentation/Jamfile 2007-10-04 22:15:58 UTC (rev 22445) @@ -2,6 +2,5 @@ SEARCH on license.xml = [ FDirName $(HAIKU_TOP) src documentation ] ; -SubInclude HAIKU_TOP src documentation haiku_book ; SubInclude HAIKU_TOP src documentation uiguidelines ; SubInclude HAIKU_TOP src documentation shell_tools ; From bonefish at mail.berlios.de Fri Oct 5 01:16:32 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Fri, 5 Oct 2007 01:16:32 +0200 Subject: [Haiku-commits] r22446 - in haiku/trunk: headers/private/kernel/boot src/system/boot/loader src/system/boot/loader/file_systems/amiga_ffs src/system/boot/loader/file_systems/bfs src/system/boot/loader/file_systems/hfs_plus src/system/boot/loader/file_systems/tarfs Message-ID: <200710042316.l94NGWum032694@sheep.berlios.de> Author: bonefish Date: 2007-10-05 01:16:31 +0200 (Fri, 05 Oct 2007) New Revision: 22446 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22446&view=rev Modified: haiku/trunk/headers/private/kernel/boot/partitions.h haiku/trunk/src/system/boot/loader/file_systems/amiga_ffs/Volume.cpp haiku/trunk/src/system/boot/loader/file_systems/bfs/bfs.cpp haiku/trunk/src/system/boot/loader/file_systems/hfs_plus/hfs_plus.cpp haiku/trunk/src/system/boot/loader/file_systems/tarfs/tarfs.cpp haiku/trunk/src/system/boot/loader/partitions.cpp Log: Added an identify_file_system() hook to the FS modules. The boot loader does no longer give partitioning systems precedence over file systems. The one with the greater identification priority wins. ATM, if a file system wins, we still mount the first file system that recognized the partition at all, though. Modified: haiku/trunk/headers/private/kernel/boot/partitions.h =================================================================== --- haiku/trunk/headers/private/kernel/boot/partitions.h 2007-10-04 22:15:58 UTC (rev 22445) +++ haiku/trunk/headers/private/kernel/boot/partitions.h 2007-10-04 23:16:31 UTC (rev 22446) @@ -88,6 +88,7 @@ struct file_system_module_info { const char *module_name; const char *pretty_name; + float (*identify_file_system)(boot::Partition *device); status_t (*get_file_system)(boot::Partition *device, Directory **_root); }; Modified: haiku/trunk/src/system/boot/loader/file_systems/amiga_ffs/Volume.cpp =================================================================== --- haiku/trunk/src/system/boot/loader/file_systems/amiga_ffs/Volume.cpp 2007-10-04 22:15:58 UTC (rev 22445) +++ haiku/trunk/src/system/boot/loader/file_systems/amiga_ffs/Volume.cpp 2007-10-04 23:16:31 UTC (rev 22446) @@ -100,6 +100,15 @@ // #pragma mark - +float +amiga_ffs_identify_file_system(boot::Partition *partition) +{ + Volume volume(partition); + + return volume.InitCheck() < B_OK ? 0 : 0.8; +} + + static status_t amiga_ffs_get_file_system(boot::Partition *partition, ::Directory **_root) { @@ -120,6 +129,7 @@ file_system_module_info gAmigaFFSFileSystemModule = { "file_systems/amiga_ffs/v1", kPartitionTypeAmigaFFS, + amiga_ffs_identify_file_system, amiga_ffs_get_file_system }; Modified: haiku/trunk/src/system/boot/loader/file_systems/bfs/bfs.cpp =================================================================== --- haiku/trunk/src/system/boot/loader/file_systems/bfs/bfs.cpp 2007-10-04 22:15:58 UTC (rev 22445) +++ haiku/trunk/src/system/boot/loader/file_systems/bfs/bfs.cpp 2007-10-04 23:16:31 UTC (rev 22446) @@ -132,6 +132,15 @@ // #pragma mark - +float +bfs_identify_file_system(boot::Partition *partition) +{ + Volume volume(partition); + + return volume.InitCheck() < B_OK ? 0 : 0.8; +} + + static status_t bfs_get_file_system(boot::Partition *partition, ::Directory **_root) { @@ -152,6 +161,7 @@ file_system_module_info gBFSFileSystemModule = { "file_systems/bfs/v1", kPartitionTypeBFS, + bfs_identify_file_system, bfs_get_file_system }; Modified: haiku/trunk/src/system/boot/loader/file_systems/hfs_plus/hfs_plus.cpp =================================================================== --- haiku/trunk/src/system/boot/loader/file_systems/hfs_plus/hfs_plus.cpp 2007-10-04 22:15:58 UTC (rev 22445) +++ haiku/trunk/src/system/boot/loader/file_systems/hfs_plus/hfs_plus.cpp 2007-10-04 23:16:31 UTC (rev 22446) @@ -55,6 +55,7 @@ file_system_module_info gAmigaFFSFileSystemModule = { "file_systems/hfs_plus/v1", kPartitionTypeHFSPlus, + NULL, hfs_plus_get_file_system }; Modified: haiku/trunk/src/system/boot/loader/file_systems/tarfs/tarfs.cpp =================================================================== --- haiku/trunk/src/system/boot/loader/file_systems/tarfs/tarfs.cpp 2007-10-04 22:15:58 UTC (rev 22445) +++ haiku/trunk/src/system/boot/loader/file_systems/tarfs/tarfs.cpp 2007-10-04 23:16:31 UTC (rev 22446) @@ -813,6 +813,7 @@ file_system_module_info gTarFileSystemModule = { "file_systems/tarfs/v1", kPartitionTypeTarFS, + NULL, // identify_file_system tarfs_get_file_system }; Modified: haiku/trunk/src/system/boot/loader/partitions.cpp =================================================================== --- haiku/trunk/src/system/boot/loader/partitions.cpp 2007-10-04 22:15:58 UTC (rev 22445) +++ haiku/trunk/src/system/boot/loader/partitions.cpp 2007-10-04 23:16:31 UTC (rev 22446) @@ -271,8 +271,26 @@ bestPriority = priority; } + + // find the best FS module + const file_system_module_info *bestFSModule = NULL; + float bestFSPriority = -1; + for (int32 i = 0; i < sNumFileSystemModules; i++) { + if (sFileSystemModules[i]->identify_file_system == NULL) + continue; + + float priority = sFileSystemModules[i]->identify_file_system(this); + if (priority <= 0) + continue; + + if (priority > bestFSPriority) { + bestFSModule = sFileSystemModules[i]; + bestFSPriority = priority; + } + } + // now let the best matching disk system scan the partition - if (bestModule) { + if (bestModule && bestPriority >= bestFSPriority) { NodeOpener opener(this, O_RDONLY); status_t status = bestModule->scan_partition(opener.Descriptor(), this, bestCookie); @@ -323,8 +341,11 @@ // scan for file systems - if (mountFileSystems) + if (mountFileSystems) { + // TODO: Use the FS module we've got, if any. Requires to implement the + // identify_file_system() hook in every FS. return Mount(); + } return B_ENTRY_NOT_FOUND; } From bonefish at mail.berlios.de Fri Oct 5 01:48:19 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Fri, 5 Oct 2007 01:48:19 +0200 Subject: [Haiku-commits] r22447 - in haiku/trunk: headers/os/drivers headers/private/fs_shell headers/private/kernel/disk_device_manager src/add-ons/kernel/file_systems/bfs src/add-ons/kernel/partitioning_systems/intel src/bin/makebootable/platform/bios_ia32 src/system/kernel/disk_device_manager src/tools/fs_shell Message-ID: <200710042348.l94NmJ7r007351@sheep.berlios.de> Author: bonefish Date: 2007-10-05 01:48:18 +0200 (Fri, 05 Oct 2007) New Revision: 22447 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22447&view=rev Modified: haiku/trunk/headers/os/drivers/fs_interface.h haiku/trunk/headers/private/fs_shell/fssh_fs_interface.h haiku/trunk/headers/private/kernel/disk_device_manager/ddm_modules.h haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMap.cpp haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMap.h haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMapParser.cpp haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMapParser.h haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMapWriter.cpp haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMapWriter.h haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/intel.cpp haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/write_support.cpp haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/write_support.h haiku/trunk/src/bin/makebootable/platform/bios_ia32/makebootable.cpp haiku/trunk/src/system/kernel/disk_device_manager/KFileSystem.cpp haiku/trunk/src/system/kernel/disk_device_manager/KPartitioningSystem.cpp haiku/trunk/src/tools/fs_shell/vfs.cpp Log: * Added the partition size as parameter to the file and partitioning system initialize() hooks. It's often the only info about the partition one needs and thus locking the partition just to get it is no longer necessary. * intel partitioning system: - Removed passing around block sizes. We require 512 byte sectors anyway. In fact using the parent partition's block size was even wrong. - Simplified writing the partition map sector. - Simplified and corrected the partition map initialization. - We don't fail identifying a partition anymore, if the partition map contains no partitions. We would never identify a freshly initialized partition map before. - Made pm_identify() more intelligent: It determines the priority to return depending on whether the partition is the device itself and whether we have recognized child partitions. Modified: haiku/trunk/headers/os/drivers/fs_interface.h =================================================================== --- haiku/trunk/headers/os/drivers/fs_interface.h 2007-10-04 23:16:31 UTC (rev 22446) +++ haiku/trunk/headers/os/drivers/fs_interface.h 2007-10-04 23:48:18 UTC (rev 22447) @@ -235,7 +235,7 @@ status_t (*set_content_parameters)(int fd, partition_id partition, const char *parameters, disk_job_id job); status_t (*initialize)(int fd, partition_id partition, const char *name, - const char *parameters, disk_job_id job); + const char *parameters, off_t partitionSize, disk_job_id job); } file_system_module_info; Modified: haiku/trunk/headers/private/fs_shell/fssh_fs_interface.h =================================================================== --- haiku/trunk/headers/private/fs_shell/fssh_fs_interface.h 2007-10-04 23:16:31 UTC (rev 22446) +++ haiku/trunk/headers/private/fs_shell/fssh_fs_interface.h 2007-10-04 23:48:18 UTC (rev 22447) @@ -273,7 +273,8 @@ fssh_status_t (*set_content_parameters)(int fd, fssh_partition_id partition, const char *parameters, fssh_disk_job_id job); fssh_status_t (*initialize)(int fd, fssh_partition_id partition, - const char *name, const char *parameters, fssh_disk_job_id job); + const char *name, const char *parameters, + fssh_off_t partitionSize, fssh_disk_job_id job); } fssh_file_system_module_info; Modified: haiku/trunk/headers/private/kernel/disk_device_manager/ddm_modules.h =================================================================== --- haiku/trunk/headers/private/kernel/disk_device_manager/ddm_modules.h 2007-10-04 23:16:31 UTC (rev 22446) +++ haiku/trunk/headers/private/kernel/disk_device_manager/ddm_modules.h 2007-10-04 23:48:18 UTC (rev 22447) @@ -94,7 +94,7 @@ status_t (*set_content_parameters)(int fd, partition_id partition, const char* parameters, disk_job_id job); status_t (*initialize)(int fd, partition_id partition, const char* name, - const char *parameters, disk_job_id job); + const char *parameters, off_t partitionSize, disk_job_id job); status_t (*create_child)(int fd, partition_id partition, off_t offset, off_t size, const char* type, const char* parameters, disk_job_id job, partition_id* childID); Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp 2007-10-04 23:16:31 UTC (rev 22446) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp 2007-10-04 23:48:18 UTC (rev 22447) @@ -2092,7 +2092,7 @@ static status_t bfs_initialize(int fd, partition_id partitionID, const char *name, - const char *parameterString, disk_job_id job) + const char *parameterString, off_t /*partitionSize*/, disk_job_id job) { // parse parameters initialize_parameters parameters; Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMap.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMap.cpp 2007-10-04 23:16:31 UTC (rev 22446) +++ haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMap.cpp 2007-10-04 23:48:18 UTC (rev 22447) @@ -298,25 +298,25 @@ // constructor Partition::Partition(const partition_descriptor *descriptor,off_t ptsOffset, - off_t baseOffset, int32 blockSize) + off_t baseOffset) : fPTSOffset(0), fOffset(0), fSize(0), fType(0), fActive(false) { - SetTo(descriptor, ptsOffset, baseOffset, blockSize); + SetTo(descriptor, ptsOffset, baseOffset); } // SetTo void Partition::SetTo(const partition_descriptor *descriptor, off_t ptsOffset, - off_t baseOffset, int32 blockSize) + off_t baseOffset) { TRACE(("Partition::SetTo(): active: %x\n", descriptor->active)); fPTSOffset = ptsOffset; - fOffset = baseOffset + (off_t)descriptor->start * blockSize; - fSize = (off_t)descriptor->size * blockSize; + fOffset = baseOffset + (off_t)descriptor->start * SECTOR_SIZE; + fSize = (off_t)descriptor->size * SECTOR_SIZE; fType = descriptor->type; fActive = descriptor->active; if (fSize == 0) @@ -337,10 +337,10 @@ // GetPartitionDescriptor void Partition::GetPartitionDescriptor(partition_descriptor *descriptor, - off_t baseOffset, int32 blockSize) const + off_t baseOffset) const { - descriptor->start = (fOffset - baseOffset) / blockSize; - descriptor->size = fSize / blockSize; + descriptor->start = (fOffset - baseOffset) / SECTOR_SIZE; + descriptor->size = fSize / SECTOR_SIZE; descriptor->type = fType; descriptor->active = fActive ? 0x80 : 0x00; descriptor->begin.Unset(); @@ -362,13 +362,13 @@ bool -Partition::CheckLocation(off_t sessionSize, int32 blockSize) const +Partition::CheckLocation(off_t sessionSize) const { // offsets and size must be block aligned, PTS and partition must lie // within the session - return fPTSOffset % blockSize == 0 - && fOffset % blockSize == 0 - && fSize % blockSize == 0 + return fPTSOffset % SECTOR_SIZE == 0 + && fOffset % SECTOR_SIZE == 0 + && fSize % SECTOR_SIZE == 0 && fPTSOffset >= 0 && fPTSOffset < sessionSize && fOffset >= 0 && fOffset + fSize <= sessionSize; } @@ -388,22 +388,21 @@ // constructor PrimaryPartition::PrimaryPartition(const partition_descriptor *descriptor, - off_t ptsOffset, int32 blockSize) + off_t ptsOffset) : Partition(), fHead(NULL), fTail(NULL), fLogicalPartitionCount(0) { - SetTo(descriptor, ptsOffset, blockSize); + SetTo(descriptor, ptsOffset); } // SetTo void -PrimaryPartition::SetTo(const partition_descriptor *descriptor, - off_t ptsOffset, int32 blockSize) +PrimaryPartition::SetTo(const partition_descriptor *descriptor, off_t ptsOffset) { Unset(); - Partition::SetTo(descriptor, ptsOffset, 0, blockSize); + Partition::SetTo(descriptor, ptsOffset, 0); } // Unset @@ -488,27 +487,25 @@ // constructor LogicalPartition::LogicalPartition(const partition_descriptor *descriptor, - off_t ptsOffset, int32 blockSize, - PrimaryPartition *primary) + off_t ptsOffset, PrimaryPartition *primary) : Partition(), fPrimary(NULL), fNext(NULL), fPrevious(NULL) { - SetTo(descriptor, ptsOffset, blockSize, primary); + SetTo(descriptor, ptsOffset, primary); } // SetTo void LogicalPartition::SetTo(const partition_descriptor *descriptor, - off_t ptsOffset, int32 blockSize, - PrimaryPartition *primary) + off_t ptsOffset, PrimaryPartition *primary) { Unset(); if (descriptor && primary) { off_t baseOffset = (descriptor->is_extended() ? primary->Offset() : ptsOffset); - Partition::SetTo(descriptor, ptsOffset, baseOffset, blockSize); + Partition::SetTo(descriptor, ptsOffset, baseOffset); fPrimary = primary; } } @@ -619,12 +616,12 @@ // Check bool -PartitionMap::Check(off_t sessionSize, int32 blockSize) const +PartitionMap::Check(off_t sessionSize) const { int32 partitionCount = CountPartitions(); // 1. check partition locations for (int32 i = 0; i < partitionCount; i++) { - if (!PartitionAt(i)->CheckLocation(sessionSize, blockSize)) + if (!PartitionAt(i)->CheckLocation(sessionSize)) return false; } // 2. check overlapping of partitions and location of PTSs Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMap.h =================================================================== --- haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMap.h 2007-10-04 23:16:31 UTC (rev 22446) +++ haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMap.h 2007-10-04 23:48:18 UTC (rev 22447) @@ -1,9 +1,6 @@ /* - * Copyright 2003-2006, Haiku, Inc. All Rights Reserved. + * Copyright 2003-2007, Ingo Weinhold, bonefish at cs.tu-berlin.de. * Distributed under the terms of the MIT License. - * - * Authors: - * Ingo Weinhold, bonefish at cs.tu-berlin.de */ /*! @@ -29,6 +26,9 @@ #define INTEL_EXTENDED_PARTITION_NAME "Intel Extended Partition" #define BFS_NAME "BFS Filesystem" +enum { + SECTOR_SIZE = 512 +}; // is_empty_type static inline bool @@ -123,10 +123,10 @@ public: Partition(); Partition(const partition_descriptor *descriptor, off_t ptsOffset, - off_t baseOffset, int32 blockSize); + off_t baseOffset); void SetTo(const partition_descriptor *descriptor, off_t ptsOffset, - off_t baseOffset, int32 blockSize); + off_t baseOffset); void Unset(); bool IsEmpty() const { return is_empty_type(fType); } @@ -140,7 +140,7 @@ void GetTypeString(char *buffer) const { get_partition_type_string(fType, buffer); } void GetPartitionDescriptor(partition_descriptor *descriptor, - off_t baseOffset, int32 blockSize) const; + off_t baseOffset) const; void SetPTSOffset(off_t offset) { fPTSOffset = offset; } void SetOffset(off_t offset) { fOffset = offset; } @@ -148,7 +148,7 @@ void SetType(uint8 type) { fType = type; } void SetActive(bool active) { fActive = active; } - bool CheckLocation(off_t sessionSize, int32 blockSize) const; + bool CheckLocation(off_t sessionSize) const; #ifdef _BOOT_MODE void AdjustSize(off_t sessionSize); #endif @@ -165,11 +165,9 @@ class PrimaryPartition : public Partition { public: PrimaryPartition(); - PrimaryPartition(const partition_descriptor *descriptor, off_t ptsOffset, - int32 blockSize); + PrimaryPartition(const partition_descriptor *descriptor, off_t ptsOffset); - void SetTo(const partition_descriptor *descriptor, off_t ptsOffset, - int32 blockSize); + void SetTo(const partition_descriptor *descriptor, off_t ptsOffset); void Unset(); // only if extended @@ -189,10 +187,10 @@ public: LogicalPartition(); LogicalPartition(const partition_descriptor *descriptor, off_t ptsOffset, - int32 blockSize, PrimaryPartition *primary); + PrimaryPartition *primary); void SetTo(const partition_descriptor *descriptor, off_t ptsOffset, - int32 blockSize, PrimaryPartition *primary); + PrimaryPartition *primary); void Unset(); void SetPrimaryPartition(PrimaryPartition *primary) { fPrimary = primary; } @@ -226,7 +224,7 @@ Partition *PartitionAt(int32 index); const Partition *PartitionAt(int32 index) const; - bool Check(off_t sessionSize, int32 blockSize) const; + bool Check(off_t sessionSize) const; private: PrimaryPartition fPrimaries[4]; Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMapParser.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMapParser.cpp 2007-10-04 23:16:31 UTC (rev 22446) +++ haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMapParser.cpp 2007-10-04 23:48:18 UTC (rev 22447) @@ -38,11 +38,10 @@ // constructor PartitionMapParser::PartitionMapParser(int deviceFD, off_t sessionOffset, - off_t sessionSize, int32 blockSize) + off_t sessionSize) : fDeviceFD(deviceFD), fSessionOffset(sessionOffset), fSessionSize(sessionSize), - fBlockSize(blockSize), fPTS(NULL), fMap(NULL) { @@ -72,13 +71,9 @@ error = _ParsePrimary(&pts); } - // If we don't have any partitions it might also just be an - // empty partition map, but we still can't do much with it - if (error == B_OK - && (fMap->CountNonEmptyPartitions() == 0 - || !fMap->Check(fSessionSize, fBlockSize))) { + if (error == B_OK && !fMap->Check(fSessionSize)) error = B_BAD_DATA; - } + fMap = NULL; } return error; @@ -101,14 +96,14 @@ for (int32 i = 0; i < 4; i++) { const partition_descriptor *descriptor = &pts->table[i]; PrimaryPartition *partition = fMap->PrimaryPartitionAt(i); - partition->SetTo(descriptor, 0, fBlockSize); + partition->SetTo(descriptor, 0); #ifdef _BOOT_MODE // work-around potential BIOS problems partition->AdjustSize(fSessionSize); #endif // ignore, if location is bad - if (!partition->CheckLocation(fSessionSize, fBlockSize)) { + if (!partition->CheckLocation(fSessionSize)) { TRACE(("intel: _ParsePrimary(): partition %ld: bad location, " "ignoring\n", i)); partition->Unset(); @@ -177,8 +172,7 @@ if (!descriptor->is_empty()) { if (descriptor->is_extended()) { if (extended.IsEmpty()) { - extended.SetTo(descriptor, offset, fBlockSize, - primary); + extended.SetTo(descriptor, offset, primary); partition = &extended; } else { // only one extended partition allowed @@ -188,8 +182,7 @@ } } else { if (nonExtended.IsEmpty()) { - nonExtended.SetTo(descriptor, offset, fBlockSize, - primary); + nonExtended.SetTo(descriptor, offset, primary); partition = &nonExtended; } else { // only one non-extended partition allowed @@ -204,8 +197,7 @@ partition->AdjustSize(fSessionSize); #endif // check the partition's location - if (partition && !partition->CheckLocation(fSessionSize, - fBlockSize)) { + if (partition && !partition->CheckLocation(fSessionSize)) { error = B_BAD_DATA; TRACE(("intel: _ParseExtended(): Invalid partition " "location: pts: %lld, offset: %lld, size: %lld\n", Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMapParser.h =================================================================== --- haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMapParser.h 2007-10-04 23:16:31 UTC (rev 22446) +++ haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMapParser.h 2007-10-04 23:48:18 UTC (rev 22447) @@ -28,8 +28,8 @@ class PartitionMapParser { public: - PartitionMapParser(int deviceFD, off_t sessionOffset, off_t sessionSize, - int32 blockSize); + PartitionMapParser(int deviceFD, off_t sessionOffset, + off_t sessionSize); ~PartitionMapParser(); status_t Parse(const uint8 *block, PartitionMap *map); @@ -46,7 +46,6 @@ int fDeviceFD; off_t fSessionOffset; off_t fSessionSize; - int32 fBlockSize; partition_table_sector *fPTS; // while parsing PartitionMap *fMap; }; Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMapWriter.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMapWriter.cpp 2007-10-04 23:16:31 UTC (rev 22446) +++ haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMapWriter.cpp 2007-10-04 23:48:18 UTC (rev 22447) @@ -39,14 +39,12 @@ \param deviceFD File descriptor. \param sessionOffset Disk offset of the partition with partitioning system. \param sessionSize Size of the partition with partitioning system. - \param blockSize Size of the sector on given disk. */ PartitionMapWriter::PartitionMapWriter(int deviceFD, off_t sessionOffset, - off_t sessionSize, int32 blockSize) + off_t sessionSize) : fDeviceFD(deviceFD), fSessionOffset(sessionOffset), fSessionSize(sessionSize), - fBlockSize(blockSize), fPTS(NULL), fMap(NULL) { @@ -64,33 +62,43 @@ If a \a block is not specified, the sector is firstly read from the disk and after changing relevant items it is written back to the disk. This allows to keep code area in MBR intact. - \param block Pointer to \c partition_table_sector. + \param pts Pointer to \c partition_table_sector. \param map Pointer to the PartitionMap structure describing disk partitions. */ status_t -PartitionMapWriter::WriteMBR(uint8 *block, const PartitionMap *map) +PartitionMapWriter::WriteMBR(const PartitionMap *map, bool clearSectors) { - status_t error = (map ? B_OK : B_BAD_VALUE); + if (!map) + return B_BAD_VALUE; + + fMap = map; + + uint8 sector[SECTOR_SIZE]; + partition_table_sector* pts = (partition_table_sector*)sector; + + // If we shall not clear the first two sectors, we need to read the first + // sector in, first. + status_t error = B_OK; + if (clearSectors) + memset(sector, 0, SECTOR_SIZE); + else + error = _ReadPTS(0, pts); + if (error == B_OK) { - fMap = map; - if (block) { - partition_table_sector *pts - = (partition_table_sector*)block; - error = _WritePrimary(pts); - if (error == B_OK) - error = _WritePTS(0, pts); - } else { - partition_table_sector pts; - error = _ReadPTS(0, &pts); - if (error == B_OK) { - error = _WritePrimary(&pts); - if (error == B_OK) - error = _WritePTS(0, &pts); - } - } + error = _WritePrimary(pts); + if (error == B_OK) + error = _WriteSector(0, sector); + } - fMap = NULL; + // Clear the second sector, if desired. We do that to make the partition + // unrecognizable by BFS. + if (error == B_OK && clearSectors) { + memset(sector, 0, SECTOR_SIZE); + error = _WriteSector(SECTOR_SIZE, sector); } + + fMap = NULL; + return error; } @@ -104,28 +112,27 @@ previous logical partitions (call this function on previous logical partition to ensure it). - \param block Pointer to \c partition_table_sector. + \param pts Pointer to \c partition_table_sector. \param partition Pointer to the logical partition. */ status_t -PartitionMapWriter::WriteLogical(uint8 *block, +PartitionMapWriter::WriteLogical(partition_table_sector *pts, const LogicalPartition *partition) { status_t error = (partition ? B_OK : B_BAD_VALUE); if (error == B_OK) { - if (block) { - partition_table_sector *pts - = (partition_table_sector*)block; + if (pts) { error = _WriteExtended(pts, partition, partition->Next()); if (error == B_OK) - error = _WritePTS(partition->PTSOffset(), pts); + error = _WriteSector(partition->PTSOffset(), pts); } else { - partition_table_sector pts; - error = _ReadPTS(partition->PTSOffset(), &pts); + partition_table_sector _pts; + pts = &_pts; + error = _ReadPTS(partition->PTSOffset(), pts); if (error == B_OK) { - error = _WriteExtended(&pts, partition, partition->Next()); + error = _WriteExtended(pts, partition, partition->Next()); if (error == B_OK) - error = _WritePTS(partition->PTSOffset(), &pts); + error = _WriteSector(partition->PTSOffset(), pts); } } } @@ -142,30 +149,29 @@ If the \a first_partition is not specified, it only initializes EBR and the linked list contains no logical partitions. - \param block Pointer to \c partition_table_sector. + \param pts Pointer to \c partition_table_sector. \param first_partition Pointer to the first logical partition. */ status_t -PartitionMapWriter::WriteExtendedHead(uint8 *block, +PartitionMapWriter::WriteExtendedHead(partition_table_sector *pts, const LogicalPartition *first_partition) { LogicalPartition partition; if (first_partition) partition.SetPrimaryPartition(first_partition->GetPrimaryPartition()); status_t error = B_OK; - if (block) { - partition_table_sector *pts - = (partition_table_sector*)block; + if (pts) { error = _WriteExtended(pts, &partition, first_partition); if (error == B_OK) - error = _WritePTS(0, pts); + error = _WriteSector(0, pts); } else { - partition_table_sector pts; - error = _ReadPTS(0, &pts); + partition_table_sector _pts; + pts = &_pts; + error = _ReadPTS(0, pts); if (error == B_OK) { - error = _WriteExtended(&pts, &partition, first_partition); + error = _WriteExtended(pts, &partition, first_partition); if (error == B_OK) - error = _WritePTS(0, &pts); + error = _WriteSector(0, pts); } } return error; @@ -187,13 +193,13 @@ const PrimaryPartition *partition = fMap->PrimaryPartitionAt(i); // ignore, if location is bad - if (!partition->CheckLocation(fSessionSize, fBlockSize)) { + if (!partition->CheckLocation(fSessionSize)) { TRACE(("intel: _WritePrimary(): partition %ld: bad location, " "ignoring\n", i)); return B_BAD_DATA; } - partition->GetPartitionDescriptor(descriptor, 0, fBlockSize); + partition->GetPartitionDescriptor(descriptor, 0); } return B_OK; @@ -211,7 +217,7 @@ pts->signature = kPartitionTableSectorSignature; // check the partition's location - if (!partition->CheckLocation(fSessionSize, fBlockSize)) { + if (!partition->CheckLocation(fSessionSize)) { TRACE(("intel: _WriteExtended(): Invalid partition " "location: pts: %lld, offset: %lld, size: %lld, " "fSessionSize: %lld\n", @@ -222,8 +228,7 @@ // write the table partition_descriptor *descriptor = &(pts->table[0]); - partition->GetPartitionDescriptor(descriptor, partition->PTSOffset(), - fBlockSize); + partition->GetPartitionDescriptor(descriptor, partition->PTSOffset()); // setting offset and size of the next partition in the linked list descriptor = &(pts->table[1]); @@ -233,15 +238,15 @@ extended.SetOffset(next->PTSOffset()); extended.SetSize(next->Size() + next->Offset() - next->PTSOffset()); extended.SetType(partition->GetPrimaryPartition()->Type()); - extended.GetPartitionDescriptor(descriptor, 0, fBlockSize); + extended.GetPartitionDescriptor(descriptor, 0); extended.Unset(); } else - extended.GetPartitionDescriptor(descriptor, 0, fBlockSize); + extended.GetPartitionDescriptor(descriptor, 0); // last two descriptors are empty for (int32 i = 2; i < 4; i++) { descriptor = &(pts->table[i]); - extended.GetPartitionDescriptor(descriptor, 0, fBlockSize); + extended.GetPartitionDescriptor(descriptor, 0); } return B_OK; @@ -276,31 +281,28 @@ return error; } -// _WritePTS +// _WriteSector /*! \brief Writes the sector to the disk. */ status_t -PartitionMapWriter::_WritePTS(off_t offset, const partition_table_sector *pts) +PartitionMapWriter::_WriteSector(off_t offset, const void* pts) { status_t error = B_OK; - if (!pts) - pts = fPTS; - int32 toWrite = sizeof(partition_table_sector); + + int32 toWrite = SECTOR_SIZE; + // check the offset if (offset < 0 || offset + toWrite > fSessionSize) { error = B_BAD_VALUE; - TRACE(("intel: _WritePTS(): bad offset: %Ld\n", offset)); + TRACE(("intel: _WriteSector(): bad offset: %Ld\n", offset)); // write } else if (write_pos(fDeviceFD, fSessionOffset + offset, pts, toWrite) != toWrite) { -#ifndef _BOOT_MODE error = errno; if (error == B_OK) error = B_IO_ERROR; -#else - error = B_IO_ERROR; -#endif - TRACE(("intel: _WritePTS(): writing the PTS failed: %lx\n", error)); + + TRACE(("intel: _WriteSector(): writing the PTS failed: %lx\n", error)); } return error; } Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMapWriter.h =================================================================== --- haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMapWriter.h 2007-10-04 23:16:31 UTC (rev 22446) +++ haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMapWriter.h 2007-10-04 23:48:18 UTC (rev 22447) @@ -35,13 +35,13 @@ */ class PartitionMapWriter { public: - PartitionMapWriter(int deviceFD, off_t sessionOffset, off_t sessionSize, - int32 blockSize); + PartitionMapWriter(int deviceFD, off_t sessionOffset, off_t sessionSize); ~PartitionMapWriter(); - status_t WriteMBR(uint8 *block, const PartitionMap *map); - status_t WriteLogical(uint8 *block, const LogicalPartition *partition); - status_t WriteExtendedHead(uint8 *block, + status_t WriteMBR(const PartitionMap *map, bool clearSectors); + status_t WriteLogical(partition_table_sector *pts, + const LogicalPartition *partition); + status_t WriteExtendedHead(partition_table_sector *pts, const LogicalPartition *first_partition); private: @@ -49,13 +49,12 @@ status_t _WriteExtended(partition_table_sector *pts, const LogicalPartition *partition, const LogicalPartition *next); status_t _ReadPTS(off_t offset, partition_table_sector *pts = NULL); - status_t _WritePTS(off_t offset, const partition_table_sector *pts = NULL); + status_t _WriteSector(off_t offset, const void* pts = NULL); private: int fDeviceFD; off_t fSessionOffset; off_t fSessionSize; - int32 fBlockSize; partition_table_sector *fPTS; // while writing const PartitionMap *fMap; }; Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/intel.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/intel.cpp 2007-10-04 23:16:31 UTC (rev 22446) +++ haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/intel.cpp 2007-10-04 23:48:18 UTC (rev 22447) @@ -127,14 +127,6 @@ return -1; } - // check block size - uint32 blockSize = partition->block_size; - if (blockSize < sizeof(partition_table_sector)) { - TRACE(("intel: read_partition_map: bad block size: %ld, should be " - ">= %ld\n", blockSize, sizeof(partition_table_sector))); - return -1; - } - // allocate a PartitionMap PartitionMapCookie *map = new(nothrow) PartitionMapCookie; if (!map) @@ -142,16 +134,40 @@ map->ref_count = 1; // read the partition structure - PartitionMapParser parser(fd, 0, partition->size, blockSize); + PartitionMapParser parser(fd, 0, partition->size); status_t error = parser.Parse(NULL, map); - if (error == B_OK) { - *cookie = map; + if (error != B_OK) { + // cleanup, if not detected + delete map; + return -1; + } + + *cookie = map; + + // Depending on whether we actually have recognized child partitions and + // whether we are installed directly on a device (the by far most common + // setup), we determine the priority. + bool hasChildren = (map->CountNonEmptyPartitions() > 0); + bool hasParent = (get_parent_partition(partition->id) != NULL); + + if (!hasParent) { + if (hasChildren) { + // This value overrides BFS. + return 0.81; + } + + // No children -- might be a freshly initialized disk. But it could + // also be an image file. So we give BFS a chance to override us. return 0.5; } - // cleanup, if not detected - delete map; - return -1; + // We have a parent. That's a very unlikely setup. + if (hasChildren) + return 0.4; + + // No children. Extremely unlikely, that this is a desired. But if no one + // else claims the partition, we take it anyway. + return 0.1; } // pm_scan_partition @@ -173,6 +189,7 @@ partition->content_size = partition->size; // (no content_name and content_parameters) // (content_type is set by the system) + partition->block_size = SECTOR_SIZE; partition->content_cookie = map; // children @@ -192,7 +209,7 @@ child->offset = partition->offset + primary->Offset(); child->size = primary->Size(); - child->block_size = partition->block_size; + child->block_size = SECTOR_SIZE; // (no name) char type[B_FILE_NAME_LENGTH]; primary->GetTypeString(type); @@ -320,6 +337,7 @@ partition->content_size = partition->size; // (no content_name and content_parameters) // (content_type is set by the system) + partition->block_size = SECTOR_SIZE; partition->content_cookie = primary; // children @@ -339,7 +357,7 @@ } child->offset = parent->offset + logical->Offset(); child->size = logical->Size(); - child->block_size = partition->block_size; + child->block_size = SECTOR_SIZE; // (no name) char type[B_FILE_NAME_LENGTH]; logical->GetTypeString(type); Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/write_support.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/write_support.cpp 2007-10-04 23:16:31 UTC (rev 22446) +++ haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/write_support.cpp 2007-10-04 23:48:18 UTC (rev 22447) @@ -110,20 +110,20 @@ // #pragma mark - Intel Partition Map - validate functions -// block_align (auxiliary function) +// sector_align (auxiliary function) static inline off_t -block_align(off_t offset, uint32 block_size) +sector_align(off_t offset) { - return offset / block_size * block_size; + return offset / SECTOR_SIZE * SECTOR_SIZE; } -// block_align_up (auxiliary function) +// sector_align_up (auxiliary function) static inline off_t -block_align_up(off_t offset, uint32 block_size) +sector_align_up(off_t offset) { - return (offset + block_size - 1) / block_size * block_size; + return (offset + SECTOR_SIZE - 1) / SECTOR_SIZE * SECTOR_SIZE; } // validate_resize (auxiliary function) @@ -138,7 +138,7 @@ if (new_size < 0) new_size = 0; else - new_size = block_align(new_size, partition->block_size); + new_size = sector_align(new_size); // grow partition? if (new_size > partition->size) { @@ -157,7 +157,7 @@ } new_size = current_end - partition->offset; // make the size a multiple of the block size (greater one) - new_size = block_align_up(new_size, partition->block_size); + new_size = sector_align_up(new_size); *size = new_size; return true; } @@ -285,7 +285,7 @@ if (*size < 0) *size = 0; // make the size a multiple of the block size - *size = block_align(*size, partition->block_size); + *size = sector_align(*size); return true; } // grow partition @@ -304,7 +304,7 @@ if (nextSibling && (nextOffset < childOffset + *size)) *size = nextOffset - childOffset; - *size = block_align(*size, partition->block_size); + *size = sector_align(*size); return true; } @@ -347,7 +347,7 @@ else if (start + childSize > partition->size) start = partition->size - childSize; - start = block_align(start, partition->block_size); + start = sector_align(start); // finding out sibling partitions partition_data *previousSibling = NULL; @@ -362,13 +362,13 @@ // moving left if (previousSibling && previousOffset + previousSize > start) { start = previousOffset + previousSize; - start = block_align_up(start, partition->block_size); + start = sector_align_up(start); } } else { // moving right if (nextSibling && nextOffset < start + childSize) { start = nextOffset - childSize; - start = block_align(start, partition->block_size); + start = sector_align(start); } } *_start = start; @@ -453,9 +453,13 @@ & B_DISK_SYSTEM_SUPPORTS_INITIALIZING)) { return false; } - // name is ignored - we cannot set it to the intel partitioning map - // TODO: check parameters - don't know whether any parameters could be set - // to the intel partition map + + // name is ignored + if (name) + name[0] = '\0'; + + // parameters are ignored, too + return true; } @@ -465,11 +469,11 @@ off_t *size, fc_get_sibling_partitions getSiblingPartitions) { // make the start and size a multiple of the block size - *start = block_align(*start, partition->block_size); + *start = sector_align(*start); if (*size < 0) *size = 0; else - *size = block_align(*size, partition->block_size); + *size = sector_align(*size); // child must completely lie within the parent partition if (*start >= partition->offset + partition->size) @@ -489,12 +493,12 @@ // position check of the new partition if (previousSibling && (previousOffset + previousSize > *start)) { *start = previousOffset + previousSize; - *start = block_align_up(*start, partition->block_size); + *start = sector_align_up(*start); } if (nextSibling && (nextOffset < *start + *size)) *size = nextOffset - *start; - *size = block_align(*size, partition->block_size); + *size = sector_align(*size); if (*size == 0) return false; @@ -540,9 +544,9 @@ return false; *index = newIndex; - if (*start < partition->offset + MBR_OFFSET * partition->block_size) { - *start = partition->offset + MBR_OFFSET * partition->block_size; - *start = block_align_up(*start, partition->block_size); + if (*start < partition->offset + MBR_OFFSET * SECTOR_SIZE) { + *start = partition->offset + MBR_OFFSET * SECTOR_SIZE; + *start = sector_align_up(*start); } return validate_create_child_partition(partition, start, size, @@ -626,12 +630,12 @@ int32 actualCount = 0; // offset alignment (to upper bound) - offset = block_align_up(offset, partition->block_size); + offset = sector_align_up(offset); // finding out all partitionable spaces for (int32 i = 0; i < partition_count; i++) { size = positions[i].offset - offset; - size = block_align(size, partition->block_size); + size = sector_align(size); if (size > limitSize) { if (actualCount < count) { buffer[actualCount].offset = offset; @@ -640,11 +644,11 @@ actualCount++; } offset = positions[i].offset + positions[i].size + headerSize; - offset = block_align_up(offset, partition->block_size); + offset = sector_align_up(offset); } // space in the end of partition size = partition->offset + partition->size - offset; - size = block_align(size, partition->block_size); + size = sector_align(size); if (size > 0) { if (actualCount < count) { buffer[actualCount].offset = offset; @@ -678,7 +682,7 @@ return B_BAD_VALUE; return get_partitionable_spaces(partition, buffer, count, actualCount, - fill_partitionable_spaces_buffer_pm, MBR_OFFSET * partition->block_size, + fill_partitionable_spaces_buffer_pm, MBR_OFFSET * SECTOR_SIZE, 0, 0); } @@ -809,8 +813,8 @@ primary->SetSize(validatedSize); // TODO: The partition is not supposed to be locked here! - PartitionMapWriter writer(fd, 0, partition->size, partition->block_size); - status_t error = writer.WriteMBR(NULL, map); + PartitionMapWriter writer(fd, 0, partition->size); + status_t error = writer.WriteMBR(map, false); if (error != B_OK) { // putting into previous state primary->SetSize(child->size); @@ -959,7 +963,7 @@ // buffer allocation int32 allocated; - uint8 *buffer = allocate_buffer(partition->block_size, MAX_MOVE_BUFFER, + uint8 *buffer = allocate_buffer(SECTOR_SIZE, MAX_MOVE_BUFFER, [... truncated: 387 lines follow ...] From bonefish at mail.berlios.de Fri Oct 5 01:52:22 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Fri, 5 Oct 2007 01:52:22 +0200 Subject: [Haiku-commits] r22448 - haiku/trunk/src/system/kernel/disk_device_manager/jobs Message-ID: <200710042352.l94NqMVt007449@sheep.berlios.de> Author: bonefish Date: 2007-10-05 01:52:21 +0200 (Fri, 05 Oct 2007) New Revision: 22448 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22448&view=rev Modified: haiku/trunk/src/system/kernel/disk_device_manager/jobs/KInitializeJob.cpp Log: * Cleanup. * Corrected checking of parameters (name). * Gracefully deals with disk systems that rescan after initialization, now. Modified: haiku/trunk/src/system/kernel/disk_device_manager/jobs/KInitializeJob.cpp =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/jobs/KInitializeJob.cpp 2007-10-04 23:48:18 UTC (rev 22447) +++ haiku/trunk/src/system/kernel/disk_device_manager/jobs/KInitializeJob.cpp 2007-10-04 23:52:21 UTC (rev 22448) @@ -8,6 +8,7 @@ */ #include +#include #include #include @@ -59,66 +60,79 @@ DBG(OUT("KInitializeJob::Do(%ld)\n", PartitionID())); KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KPartition *partition = manager->WriteLockPartition(PartitionID()); - if (partition) { - PartitionRegistrar registrar(partition, true); - PartitionRegistrar deviceRegistrar(partition->Device(), true); + if (!partition) { + SetErrorMessage("Couldn't find partition."); + return B_ENTRY_NOT_FOUND; + } - DeviceWriteLocker locker(partition->Device(), true); - // basic checks + PartitionRegistrar registrar(partition, true); + PartitionRegistrar deviceRegistrar(partition->Device(), true); -// if (!partition->ParentDiskSystem()) { -// SetErrorMessage("Partition has no parent disk system!"); -// return B_BAD_VALUE; -// } + DeviceWriteLocker locker(partition->Device(), true); - // all descendants should be marked busy/descendant busy - if (IsPartitionNotBusy(partition)) { - SetErrorMessage("Can't initialize non-busy partition!"); - return B_ERROR; - } + // basic checks -/* if (!fParameters) { - //no parameters for the operation - SetErrorMessage( "No parameters for partition initialization." ); - return B_ERROR; - }*/ + // all descendants should be marked busy/descendant busy + if (IsPartitionNotBusy(partition)) { + SetErrorMessage("Can't initialize non-busy partition!"); + return B_ERROR; + } - // TODO shouldn't we load the disk system AFTER the validation? - KDiskSystem *diskSystemToInit = manager->LoadDiskSystem(fDiskSystemID); - if (!diskSystemToInit) { - SetErrorMessage("Given DiskSystemID doesn't correspond to any " - "known DiskSystem."); - return B_BAD_VALUE; - } - DiskSystemLoader loader2(diskSystemToInit); + if (partition->DiskSystem()) { + SetErrorMessage("Partition is already initialized."); + return B_BAD_VALUE; + } -// TODO: The parameters are already validated and should not be changed again! - status_t validationResult = validate_initialize_partition(partition, - partition->ChangeCounter(), diskSystemToInit->Name(), fName, - fParameters, false); + // get the disk system + KDiskSystem *diskSystemToInit = manager->LoadDiskSystem(fDiskSystemID); + if (!diskSystemToInit) { + SetErrorMessage("Given DiskSystemID doesn't correspond to any " + "known DiskSystem."); + return B_BAD_VALUE; + } + DiskSystemLoader loader(diskSystemToInit, true); - if (validationResult != B_OK) { - SetErrorMessage("Validation of initializing partition failed!"); - return validationResult; - } + // check the parameters + char name[B_DISK_DEVICE_NAME_LENGTH]; + if (fName) + strlcpy(name, fName, sizeof(name)); - // everything seems OK -> let's do the job - locker.Unlock(); + status_t error = validate_initialize_partition(partition, + partition->ChangeCounter(), diskSystemToInit->Name(), + fName ? name : NULL, fParameters, false); - status_t initResult = diskSystemToInit->Initialize(partition, fName, - fParameters, this); + if (error != B_OK) { + SetErrorMessage("Validation of initializing partition failed."); + return error; + } - if (initResult != B_OK) { - SetErrorMessage("Initialization of partition failed!"); - return initResult; + if (fName != NULL && strcmp(fName, name) != 0) { + SetErrorMessage("Requested name not valid."); + return B_BAD_VALUE; + } + + // everything seems OK -> let's do the job + locker.Unlock(); + + error = diskSystemToInit->Initialize(partition, fName, fParameters, this); + if (error != B_OK) { + SetErrorMessage("Initialization of partition failed!"); + return error; + } + + locker.Lock(); + + if (partition->DiskSystem()) { + // The disk system might have triggered a rescan after initializing, in + // which case the disk system is already set. Just check, if it is the + // right one. + if (partition->DiskSystem() != diskSystemToInit) { + SetErrorMessage("Partition has wrong disk system after " + "initialization."); + return B_ERROR; } - + } else partition->SetDiskSystem(diskSystemToInit); - return B_OK; - - } else { - SetErrorMessage("Couldn't find partition."); - return B_ENTRY_NOT_FOUND; - } + return B_OK; } From axeld at mail.berlios.de Fri Oct 5 18:54:51 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Fri, 5 Oct 2007 18:54:51 +0200 Subject: [Haiku-commits] r22449 - haiku/trunk/src/system/kernel/vm Message-ID: <200710051654.l95Gspvl013874@sheep.berlios.de> Author: axeld Date: 2007-10-05 18:54:50 +0200 (Fri, 05 Oct 2007) New Revision: 22449 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22449&view=rev Modified: haiku/trunk/src/system/kernel/vm/vm_daemons.cpp Log: The page scanner must not turn pages inactive that are actually wired (currently, wired pages don't always have the PAGE_STATE_WIRED, but a wired_count). Modified: haiku/trunk/src/system/kernel/vm/vm_daemons.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_daemons.cpp 2007-10-04 23:52:21 UTC (rev 22448) +++ haiku/trunk/src/system/kernel/vm/vm_daemons.cpp 2007-10-05 16:54:50 UTC (rev 22449) @@ -46,7 +46,8 @@ { if (page->state == PAGE_STATE_WIRED || page->state == PAGE_STATE_BUSY || page->state == PAGE_STATE_FREE || page->state == PAGE_STATE_CLEAR - || page->state == PAGE_STATE_UNUSED || page->cache == NULL) + || page->state == PAGE_STATE_UNUSED || page->wired_count > 0 + || page->cache == NULL) return true; return false; From bonefish at mail.berlios.de Fri Oct 5 18:56:49 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Fri, 5 Oct 2007 18:56:49 +0200 Subject: [Haiku-commits] r22450 - haiku/trunk/headers/private/kernel/util Message-ID: <200710051656.l95Guns3014796@sheep.berlios.de> Author: bonefish Date: 2007-10-05 18:56:48 +0200 (Fri, 05 Oct 2007) New Revision: 22450 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22450&view=rev Modified: haiku/trunk/headers/private/kernel/util/DoublyLinkedList.h Log: MoveFrom() was broken. Fixes bug #1534. Modified: haiku/trunk/headers/private/kernel/util/DoublyLinkedList.h =================================================================== --- haiku/trunk/headers/private/kernel/util/DoublyLinkedList.h 2007-10-05 16:54:50 UTC (rev 22449) +++ haiku/trunk/headers/private/kernel/util/DoublyLinkedList.h 2007-10-05 16:56:48 UTC (rev 22450) @@ -523,7 +523,7 @@ if (fromList && fromList->fFirst) { if (fFirst) { sGetLink(fLast)->next = fromList->fFirst; - sGetLink(fFirst)->previous = fLast; + sGetLink(fromList->fFirst)->previous = fLast; fLast = fromList->fLast; } else { fFirst = fromList->fFirst; From bonefish at mail.berlios.de Fri Oct 5 20:42:51 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Fri, 5 Oct 2007 20:42:51 +0200 Subject: [Haiku-commits] r22451 - haiku/trunk/src/system/kernel/fs Message-ID: <200710051842.l95Igp1j027164@sheep.berlios.de> Author: bonefish Date: 2007-10-05 20:42:50 +0200 (Fri, 05 Oct 2007) New Revision: 22451 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22451&view=rev Modified: haiku/trunk/src/system/kernel/fs/vfs.cpp Log: * Reviewed checking of empty paths and fixed some occurrences. Thanks to mjw for the hint. Fixes bug #1516. * Changed _{kern,user}_create_symlink() to no longer check the supplied link string. BeOS seems to do that, but this is not standard conforming. The previous implementation even used the path processed by check_path(), which would potentially have appended a ".". * Some style cleanup. Modified: haiku/trunk/src/system/kernel/fs/vfs.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/vfs.cpp 2007-10-05 16:56:48 UTC (rev 22450) +++ haiku/trunk/src/system/kernel/fs/vfs.cpp 2007-10-05 18:42:50 UTC (rev 22451) @@ -1487,25 +1487,28 @@ } -/** \brief Gets the directory path and leaf name for a given path. - * - * The supplied \a path is transformed to refer to the directory part of - * the entry identified by the original path, and into the buffer \a filename - * the leaf name of the original entry is written. - * Neither the returned path nor the leaf name can be expected to be - * canonical. - * - * \param path The path to be analyzed. Must be able to store at least one - * additional character. - * \param filename The buffer into which the leaf name will be written. - * Must be of size B_FILE_NAME_LENGTH at least. - * \return \c B_OK, if everything went fine, \c B_NAME_TOO_LONG, if the leaf - * name is longer than \c B_FILE_NAME_LENGTH. - */ +/*! \brief Gets the directory path and leaf name for a given path. + The supplied \a path is transformed to refer to the directory part of + the entry identified by the original path, and into the buffer \a filename + the leaf name of the original entry is written. + Neither the returned path nor the leaf name can be expected to be + canonical. + + \param path The path to be analyzed. Must be able to store at least one + additional character. + \param filename The buffer into which the leaf name will be written. + Must be of size B_FILE_NAME_LENGTH at least. + \return \c B_OK, if everything went fine, \c B_NAME_TOO_LONG, if the leaf + name is longer than \c B_FILE_NAME_LENGTH, or \c B_ENTRY_NOT_FOUND, + if the given path name is empty. +*/ static status_t get_dir_path_and_leaf(char *path, char *filename) { + if (*path == '\0') + return B_ENTRY_NOT_FOUND; + char *p = strrchr(path, '/'); // '/' are not allowed in file names! @@ -1537,7 +1540,8 @@ static status_t -entry_ref_to_vnode(dev_t mountID, ino_t directoryID, const char *name, struct vnode **_vnode) +entry_ref_to_vnode(dev_t mountID, ino_t directoryID, const char *name, + struct vnode **_vnode) { char clonedName[B_FILE_NAME_LENGTH + 1]; if (strlcpy(clonedName, name, B_FILE_NAME_LENGTH) >= B_FILE_NAME_LENGTH) @@ -1550,18 +1554,18 @@ if (status < 0) return status; - return vnode_path_to_vnode(directory, clonedName, false, 0, _vnode, NULL, NULL); + return vnode_path_to_vnode(directory, clonedName, false, 0, _vnode, NULL, + NULL); } -/** Returns the vnode for the relative path starting at the specified \a vnode. - * \a path must not be NULL. - * If it returns successfully, \a path contains the name of the last path - * component. - * Note, this reduces the ref_count of the starting \a vnode, no matter if - * it is successful or not! - */ - +/*! Returns the vnode for the relative path starting at the specified \a vnode. + \a path must not be NULL. + If it returns successfully, \a path contains the name of the last path + component. + Note, this reduces the ref_count of the starting \a vnode, no matter if + it is successful or not! +*/ static status_t vnode_path_to_vnode(struct vnode *vnode, char *path, bool traverseLeafLink, int count, struct vnode **_vnode, ino_t *_parentID, int *_type) @@ -1577,6 +1581,11 @@ return B_BAD_VALUE; } + if (*path == '\0') { + put_vnode(vnode); + return B_ENTRY_NOT_FOUND; + } + while (true) { struct vnode *nextVnode; ino_t vnodeID; @@ -1683,6 +1692,7 @@ // directory ("vnode" still points to that one). // Cut off all leading slashes if it's the root directory path = buffer; + bool absoluteSymlink = false; if (path[0] == '/') { // we don't need the old directory anymore put_vnode(vnode); @@ -1691,13 +1701,21 @@ ; vnode = sRoot; inc_vnode_ref_count(vnode); + + absoluteSymlink = true; } + inc_vnode_ref_count(vnode); - // balance the next recursion - we will decrement the ref_count - // of the vnode, no matter if we succeeded or not + // balance the next recursion - we will decrement the + // ref_count of the vnode, no matter if we succeeded or not - status = vnode_path_to_vnode(vnode, path, traverseLeafLink, count + 1, - &nextVnode, &lastParentID, _type); + if (absoluteSymlink && *path == '\0') { + // symlink was just "/" + nextVnode = vnode; + } else { + status = vnode_path_to_vnode(vnode, path, traverseLeafLink, + count + 1, &nextVnode, &lastParentID, _type); + } free(buffer); @@ -1743,6 +1761,9 @@ if (!path) return B_BAD_VALUE; + if (*path == '\0') + return B_ENTRY_NOT_FOUND; + // figure out if we need to start at root or at cwd if (*path == '/') { if (sRoot == NULL) { @@ -1754,6 +1775,12 @@ ; start = sRoot; inc_vnode_ref_count(start); + + if (*path == '\0') { + *_vnode = start; + return B_OK; + } + } else { struct io_context *context = get_current_io_context(kernel); @@ -1771,11 +1798,10 @@ } -/** Returns the vnode in the next to last segment of the path, and returns - * the last portion in filename. - * The path buffer must be able to store at least one additional character. - */ - +/*! Returns the vnode in the next to last segment of the path, and returns + the last portion in filename. + The path buffer must be able to store at least one additional character. +*/ static status_t path_to_dir_vnode(char *path, struct vnode **_vnode, char *filename, bool kernel) { @@ -1787,37 +1813,38 @@ } -/** \brief Retrieves the directory vnode and the leaf name of an entry referred - * to by a FD + path pair. - * - * \a path must be given in either case. \a fd might be omitted, in which - * case \a path is either an absolute path or one relative to the current - * directory. If both a supplied and \a path is relative it is reckoned off - * of the directory referred to by \a fd. If \a path is absolute \a fd is - * ignored. - * - * The caller has the responsibility to call put_vnode() on the returned - * directory vnode. - * - * \param fd The FD. May be < 0. - * \param path The absolute or relative path. Must not be \c NULL. The buffer - * is modified by this function. It must have at least room for a - * string one character longer than the path it contains. - * \param _vnode A pointer to a variable the directory vnode shall be written - * into. - * \param filename A buffer of size B_FILE_NAME_LENGTH or larger into which - * the leaf name of the specified entry will be written. - * \param kernel \c true, if invoked from inside the kernel, \c false if - * invoked from userland. - * \return \c B_OK, if everything went fine, another error code otherwise. - */ +/*! \brief Retrieves the directory vnode and the leaf name of an entry referred + to by a FD + path pair. + \a path must be given in either case. \a fd might be omitted, in which + case \a path is either an absolute path or one relative to the current + directory. If both a supplied and \a path is relative it is reckoned off + of the directory referred to by \a fd. If \a path is absolute \a fd is + ignored. + + The caller has the responsibility to call put_vnode() on the returned + directory vnode. + + \param fd The FD. May be < 0. + \param path The absolute or relative path. Must not be \c NULL. The buffer + is modified by this function. It must have at least room for a + string one character longer than the path it contains. + \param _vnode A pointer to a variable the directory vnode shall be written + into. + \param filename A buffer of size B_FILE_NAME_LENGTH or larger into which + the leaf name of the specified entry will be written. + \param kernel \c true, if invoked from inside the kernel, \c false if + invoked from userland. + \return \c B_OK, if everything went fine, another error code otherwise. +*/ static status_t fd_and_path_to_dir_vnode(int fd, char *path, struct vnode **_vnode, char *filename, bool kernel) { if (!path) return B_BAD_VALUE; + if (*path == '\0') + return B_ENTRY_NOT_FOUND; if (fd < 0) return path_to_dir_vnode(path, _vnode, filename, kernel); @@ -1829,9 +1856,8 @@ } -/** Returns a vnode's name in the d_name field of a supplied dirent buffer. - */ - +/*! Returns a vnode's name in the d_name field of a supplied dirent buffer. +*/ static status_t get_vnode_name(struct vnode *vnode, struct vnode *parent, struct dirent *buffer, size_t bufferSize) @@ -2049,12 +2075,11 @@ } -/** Checks the length of every path component, and adds a '.' - * if the path ends in a slash. - * The given path buffer must be able to store at least one - * additional character. - */ - +/*! Checks the length of every path component, and adds a '.' + if the path ends in a slash. + The given path buffer must be able to store at least one + additional character. +*/ static status_t check_path(char *to) { @@ -2131,13 +2156,12 @@ } -/** Gets the vnode from an FD + path combination. If \a fd is lower than zero, - * only the path will be considered. In this case, the \a path must not be - * NULL. - * If \a fd is a valid file descriptor, \a path may be NULL for directories, - * and should be NULL for files. - */ - +/*! Gets the vnode from an FD + path combination. If \a fd is lower than zero, + only the path will be considered. In this case, the \a path must not be + NULL. + If \a fd is a valid file descriptor, \a path may be NULL for directories, + and should be NULL for files. +*/ static status_t fd_and_path_to_vnode(int fd, char *path, bool traverseLeafLink, struct vnode **_vnode, ino_t *_parentID, bool kernel) @@ -2145,6 +2169,9 @@ if (fd < 0 && !path) return B_BAD_VALUE; + if (path != NULL && *path == '\0') + return B_ENTRY_NOT_FOUND; + if (fd < 0 || (path != NULL && path[0] == '/')) { // no FD or absolute path return path_to_vnode(path, traverseLeafLink, _vnode, _parentID, kernel); @@ -6256,18 +6283,11 @@ _kern_create_symlink(int fd, const char *path, const char *toPath, int mode) { KPath pathBuffer(path, false, B_PATH_NAME_LENGTH + 1); - KPath toPathBuffer(toPath, false, B_PATH_NAME_LENGTH + 1); - if (pathBuffer.InitCheck() != B_OK || toPathBuffer.InitCheck() != B_OK) + if (pathBuffer.InitCheck() != B_OK) return B_NO_MEMORY; - char *toBuffer = toPathBuffer.LockBuffer(); - - status_t status = check_path(toBuffer); - if (status < B_OK) - return status; - return common_create_symlink(fd, pathBuffer.LockBuffer(), - toBuffer, mode, true); + toPath, mode, true); } @@ -7097,10 +7117,6 @@ || user_strlcpy(toPath, userToPath, B_PATH_NAME_LENGTH) < B_OK) return B_BAD_ADDRESS; - status_t status = check_path(toPath); - if (status < B_OK) - return status; - return common_create_symlink(fd, path, toPath, mode, false); } From bonefish at mail.berlios.de Fri Oct 5 21:01:19 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Fri, 5 Oct 2007 21:01:19 +0200 Subject: [Haiku-commits] r22452 - haiku/trunk/src/system/runtime_loader Message-ID: <200710051901.l95J1JRq027960@sheep.berlios.de> Author: bonefish Date: 2007-10-05 21:01:18 +0200 (Fri, 05 Oct 2007) New Revision: 22452 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22452&view=rev Modified: haiku/trunk/src/system/runtime_loader/runtime_loader.c Log: Don't overwrite the last read byte with the null-terminator. Fixes bug #1536. Modified: haiku/trunk/src/system/runtime_loader/runtime_loader.c =================================================================== --- haiku/trunk/src/system/runtime_loader/runtime_loader.c 2007-10-05 18:42:50 UTC (rev 22451) +++ haiku/trunk/src/system/runtime_loader/runtime_loader.c 2007-10-05 19:01:18 UTC (rev 22452) @@ -310,7 +310,7 @@ // test for shell scripts if (!strncmp(buffer, "#!", 2)) { char *end; - buffer[length - 1] = '\0'; + buffer[min_c((size_t)length, sizeof(buffer) - 1)] = '\0'; end = strchr(buffer, '\n'); if (end == NULL) { From bonefish at mail.berlios.de Sat Oct 6 00:39:54 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sat, 6 Oct 2007 00:39:54 +0200 Subject: [Haiku-commits] r22453 - haiku/trunk/src/system/kernel/disk_device_manager Message-ID: <200710052239.l95MdsgE000192@sheep.berlios.de> Author: bonefish Date: 2007-10-06 00:39:52 +0200 (Sat, 06 Oct 2007) New Revision: 22453 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22453&view=rev Modified: haiku/trunk/src/system/kernel/disk_device_manager/ddm_userland_interface.cpp Log: * Fixed gcc 4 warnings. * Style cleanup. Modified: haiku/trunk/src/system/kernel/disk_device_manager/ddm_userland_interface.cpp =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/ddm_userland_interface.cpp 2007-10-05 19:01:18 UTC (rev 22452) +++ haiku/trunk/src/system/kernel/disk_device_manager/ddm_userland_interface.cpp 2007-10-05 22:39:52 UTC (rev 22453) @@ -1,4 +1,4 @@ -/** \file ddm_userland_interface.cpp +/** \file ddm_userland_interface.cpp * * \brief Interface for userspace calls. */ @@ -34,18 +34,21 @@ \a from is longer than \to. If \c false, returns \c B_NAME_TOO_LONG if \a from is longer than \to. */ -static -status_t -ddm_strlcpy(char *to, const char *from, size_t size, bool allowTruncation = false) { - int error = user_strlcpy(to, from, size); - error = (0 <= error && size_t(error) < size) ? B_OK - : (error < B_OK ? error : (allowTruncation ? B_OK : B_NAME_TOO_LONG)); - return status_t(error); +static status_t +ddm_strlcpy(char *to, const char *from, size_t size, + bool allowTruncation = false) +{ + ssize_t fromLen = user_strlcpy(to, from, size); + if (fromLen < 0) + return fromLen; + if ((size_t)fromLen >= size && !allowTruncation) + return B_NAME_TOO_LONG; + return B_OK; } + // move_descendants -static -void +static void move_descendants(KPartition *partition, off_t moveBy) { if (!partition) @@ -56,9 +59,9 @@ move_descendants(child, moveBy); } + // move_descendants_contents -static -status_t +static status_t move_descendants_contents(KPartition *partition) { if (!partition) @@ -80,6 +83,7 @@ return B_OK; } + // _user_get_next_disk_device_id partition_id _user_get_next_disk_device_id(int32 *_cookie, size_t *neededSize) @@ -110,6 +114,7 @@ return id; } + // _user_find_disk_device partition_id _user_find_disk_device(const char *_filename, size_t *neededSize) @@ -141,6 +146,7 @@ return id; } + // _user_find_partition partition_id _user_find_partition(const char *_filename, size_t *neededSize) @@ -177,6 +183,7 @@ return id; } + // _user_get_disk_device_data /*! \brief Writes data describing the disk device identified by ID and all its partitions into the supplied buffer. @@ -221,8 +228,7 @@ */ status_t _user_get_disk_device_data(partition_id id, bool deviceOnly, bool shadow, - user_disk_device_data *buffer, size_t bufferSize, - size_t *_neededSize) + user_disk_device_data *buffer, size_t bufferSize, size_t *_neededSize) { if (!buffer && bufferSize > 0) return B_BAD_VALUE; @@ -272,42 +278,45 @@ return B_ENTRY_NOT_FOUND; } + // _user_get_partitionable_spaces status_t _user_get_partitionable_spaces(partition_id partitionID, int32 changeCounter, - partitionable_space_data *_buffer, - int32 count, int32 *_actualCount) + partitionable_space_data *_buffer, int32 count, int32 *_actualCount) { if (!_buffer && count > 0) return B_BAD_VALUE; // copy in int32 bufferSize = count * sizeof(partitionable_space_data); partitionable_space_data *buffer = count > 0 - ? reinterpret_cast(malloc(bufferSize)) - : NULL; + ? reinterpret_cast(malloc(bufferSize)) + : NULL; if (buffer) user_memcpy(buffer, _buffer, bufferSize); status_t error = B_OK; // get the partition KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KPartition *partition = manager->ReadLockPartition(partitionID); - error = partition ? B_OK : B_ENTRY_NOT_FOUND; + error = partition ? (status_t)B_OK : (status_t)B_ENTRY_NOT_FOUND; if (!error) { PartitionRegistrar registrar1(partition, true); PartitionRegistrar registrar2(partition->Device(), true); DeviceReadLocker locker(partition->Device(), true); - error = check_shadow_partition(partition, changeCounter) ? B_OK : B_BAD_VALUE; + error = check_shadow_partition(partition, changeCounter) + ? B_OK : B_BAD_VALUE; if (!error) { // get the disk system KDiskSystem *diskSystem = partition->DiskSystem(); - error = diskSystem ? B_OK : B_ENTRY_NOT_FOUND; + error = diskSystem ? (status_t)B_OK : (status_t)B_ENTRY_NOT_FOUND; if (!error) { // get the info int32 actualCount; error = diskSystem->GetPartitionableSpaces(partition, buffer, count, &actualCount); - if (!error && _actualCount) - user_memcpy(_actualCount, &actualCount, sizeof(actualCount)); + if (!error && _actualCount) { + user_memcpy(_actualCount, &actualCount, + sizeof(actualCount)); + } } } } @@ -318,6 +327,7 @@ return error; } + // _user_register_file_device partition_id _user_register_file_device(const char *_filename) @@ -337,6 +347,7 @@ return B_ERROR; } + // _user_unregister_file_device status_t _user_unregister_file_device(partition_id deviceID, const char *_filename) @@ -355,6 +366,7 @@ } } + // _user_get_disk_system_info status_t _user_get_disk_system_info(disk_system_id id, user_disk_system_info *_info) @@ -374,6 +386,7 @@ return B_ENTRY_NOT_FOUND; } + // _user_get_next_disk_system_info status_t _user_get_next_disk_system_info(int32 *_cookie, user_disk_system_info *_info) @@ -397,6 +410,7 @@ return result; } + // _user_find_disk_system status_t _user_find_disk_system(const char *_name, user_disk_system_info *_info) @@ -420,10 +434,11 @@ return B_ENTRY_NOT_FOUND; } + // _user_supports_defragmenting_partition bool _user_supports_defragmenting_partition(partition_id partitionID, - int32 changeCounter, bool *_whileMounted) + int32 changeCounter, bool *_whileMounted) { KDiskDeviceManager *manager = KDiskDeviceManager::Default(); // get the partition @@ -435,17 +450,17 @@ DeviceReadLocker locker(partition->Device(), true); bool whileMounted; bool result = validate_defragment_partition(partition, changeCounter, - &whileMounted) == B_OK; + &whileMounted) == B_OK; if (result && _whileMounted) user_memcpy(_whileMounted, &whileMounted, sizeof(whileMounted)); return result; } + // _user_supports_repairing_partition bool _user_supports_repairing_partition(partition_id partitionID, - int32 changeCounter, bool checkOnly, - bool *_whileMounted) + int32 changeCounter, bool checkOnly, bool *_whileMounted) { KDiskDeviceManager *manager = KDiskDeviceManager::Default(); // get the partition @@ -457,17 +472,17 @@ DeviceReadLocker locker(partition->Device(), true); bool whileMounted; bool result = validate_repair_partition(partition, changeCounter, checkOnly, - &whileMounted) == B_OK; + &whileMounted) == B_OK; if (result && _whileMounted) user_memcpy(_whileMounted, &whileMounted, sizeof(whileMounted)); return result; } + // _user_supports_resizing_partition bool -_user_supports_resizing_partition(partition_id partitionID, - int32 changeCounter, bool *_canResizeContents, - bool *_whileMounted) +_user_supports_resizing_partition(partition_id partitionID, int32 changeCounter, + bool *_canResizeContents, bool *_whileMounted) { KDiskDeviceManager *manager = KDiskDeviceManager::Default(); @@ -523,12 +538,11 @@ return result; } + // _user_supports_moving_partition bool _user_supports_moving_partition(partition_id partitionID, int32 changeCounter, - partition_id *_unmovable, - partition_id *_needUnmounting, - size_t bufferSize) + partition_id *_unmovable, partition_id *_needUnmounting, size_t bufferSize) { if ((!_unmovable || !_needUnmounting) && bufferSize > 0) return false; @@ -555,10 +569,10 @@ PartitionRegistrar registrar2(partition->Device(), true); DeviceReadLocker locker(partition->Device(), true); result = check_shadow_partition(partition, changeCounter) - && partition->Parent(); + && partition->Parent(); if (result) { result = !partition->Parent()->IsBusy() - && !partition->Parent()->IsDescendantBusy(); + && !partition->Parent()->IsDescendantBusy(); } if (result) { // get the parent disk system @@ -574,8 +588,7 @@ size_t unmovableSize = bufferSize; size_t needUnmountingSize = bufferSize; result = get_unmovable_descendants(partition, unmovable, - unmovableSize, needUnmounting, - needUnmountingSize); + unmovableSize, needUnmounting, needUnmountingSize); } } } @@ -588,10 +601,11 @@ return result; } + // _user_supports_setting_partition_name bool _user_supports_setting_partition_name(partition_id partitionID, - int32 changeCounter) + int32 changeCounter) { KDiskDeviceManager *manager = KDiskDeviceManager::Default(); // get the partition @@ -623,8 +637,7 @@ // _user_supports_setting_partition_content_name bool _user_supports_setting_partition_content_name(partition_id partitionID, - int32 changeCounter, - bool *_whileMounted) + int32 changeCounter, bool *_whileMounted) { KDiskDeviceManager *manager = KDiskDeviceManager::Default(); // get the partition @@ -658,10 +671,11 @@ return result; } + // _user_supports_setting_partition_type bool _user_supports_setting_partition_type(partition_id partitionID, - int32 changeCounter) + int32 changeCounter) { KDiskDeviceManager *manager = KDiskDeviceManager::Default(); // get the partition @@ -688,10 +702,11 @@ B_DISK_SYSTEM_SUPPORTS_SETTING_TYPE); } + // _user_supports_setting_partition_parameters bool _user_supports_setting_partition_parameters(partition_id partitionID, - int32 changeCounter) + int32 changeCounter) { KDiskDeviceManager *manager = KDiskDeviceManager::Default(); // get the partition @@ -718,11 +733,11 @@ B_DISK_SYSTEM_SUPPORTS_SETTING_PARAMETERS); } + // _user_supports_setting_partition_content_parameters bool _user_supports_setting_partition_content_parameters(partition_id partitionID, - int32 changeCounter, - bool *_whileMounted) + int32 changeCounter, bool *_whileMounted) { KDiskDeviceManager *manager = KDiskDeviceManager::Default(); // get the partition @@ -754,11 +769,11 @@ return result; } + // _user_supports_initializing_partition bool _user_supports_initializing_partition(partition_id partitionID, - int32 changeCounter, - const char *_diskSystemName) + int32 changeCounter, const char *_diskSystemName) { if (!_diskSystemName) return false; @@ -806,10 +821,11 @@ diskSystemName); } + // _user_supports_creating_child_partition bool _user_supports_creating_child_partition(partition_id partitionID, - int32 changeCounter) + int32 changeCounter) { KDiskDeviceManager *manager = KDiskDeviceManager::Default(); // get the partition @@ -832,10 +848,11 @@ B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD); } + // _user_supports_deleting_child_partition bool _user_supports_deleting_child_partition(partition_id partitionID, - int32 changeCounter) + int32 changeCounter) { KDiskDeviceManager *manager = KDiskDeviceManager::Default(); // get the partition @@ -848,10 +865,11 @@ return (validate_delete_child_partition(partition, changeCounter) == B_OK); } + // _user_is_sub_disk_system_for bool _user_is_sub_disk_system_for(disk_system_id diskSystemID, - partition_id partitionID, int32 changeCounter) + partition_id partitionID, int32 changeCounter) { KDiskDeviceManager *manager = KDiskDeviceManager::Default(); // get the partition @@ -871,10 +889,11 @@ return diskSystem->IsSubSystemFor(partition); } + // _user_validate_resize_partition status_t _user_validate_resize_partition(partition_id partitionID, int32 changeCounter, - off_t *_size) + off_t *_size) { if (!_size) return B_BAD_VALUE; @@ -890,16 +909,17 @@ DeviceReadLocker locker(partition->Device(), true); off_t contentSize = 0; bool result = validate_resize_partition(partition, changeCounter, &size, - &contentSize); + &contentSize); if (result) user_memcpy(_size, &size, sizeof(size)); return result; } + // _user_validate_move_partition status_t _user_validate_move_partition(partition_id partitionID, int32 changeCounter, - off_t *_newOffset) + off_t *_newOffset) { if (!_newOffset) return B_BAD_VALUE; @@ -913,16 +933,18 @@ PartitionRegistrar registrar1(partition, true); PartitionRegistrar registrar2(partition->Device(), true); DeviceReadLocker locker(partition->Device(), true); - status_t result = validate_move_partition(partition, changeCounter, &newOffset); + status_t result = validate_move_partition(partition, changeCounter, + &newOffset); if (result) user_memcpy(_newOffset, &newOffset, sizeof(newOffset)); return result; } + // _user_validate_set_partition_name status_t _user_validate_set_partition_name(partition_id partitionID, - int32 changeCounter, char *_name) + int32 changeCounter, char *_name) { if (!_name) return B_BAD_VALUE; @@ -944,6 +966,7 @@ return error; } + // _user_validate_set_partition_content_name status_t _user_validate_set_partition_content_name(partition_id partitionID, @@ -969,10 +992,11 @@ return error; } + // _user_validate_set_partition_type status_t _user_validate_set_partition_type(partition_id partitionID, - int32 changeCounter, const char *_type) + int32 changeCounter, const char *_type) { if (!_type) return B_BAD_VALUE; @@ -991,20 +1015,22 @@ return validate_set_partition_type(partition, changeCounter, type); } + // _user_validate_initialize_partition status_t _user_validate_initialize_partition(partition_id partitionID, - int32 changeCounter, - const char *_diskSystemName, char *_name, - const char *_parameters, - size_t parametersSize) + int32 changeCounter, const char *_diskSystemName, char *_name, + const char *_parameters, size_t parametersSize) { - if (!_diskSystemName || !_name || parametersSize > B_DISK_DEVICE_MAX_PARAMETER_SIZE) + if (!_diskSystemName || !_name + || parametersSize > B_DISK_DEVICE_MAX_PARAMETER_SIZE) { return B_BAD_VALUE; + } char diskSystemName[B_DISK_SYSTEM_NAME_LENGTH]; char name[B_DISK_DEVICE_NAME_LENGTH]; char *parameters = NULL; - status_t error = ddm_strlcpy(diskSystemName, _diskSystemName, B_DISK_SYSTEM_NAME_LENGTH); + status_t error = ddm_strlcpy(diskSystemName, _diskSystemName, + B_DISK_SYSTEM_NAME_LENGTH); if (!error) error = ddm_strlcpy(name, _name, B_DISK_DEVICE_NAME_LENGTH, true); if (error) @@ -1019,13 +1045,13 @@ KDiskDeviceManager *manager = KDiskDeviceManager::Default(); // get the partition KPartition *partition = manager->ReadLockPartition(partitionID); - error = partition ? B_OK : B_ENTRY_NOT_FOUND; + error = partition ? (status_t)B_OK : (status_t)B_ENTRY_NOT_FOUND; if (!error) { PartitionRegistrar registrar1(partition, true); PartitionRegistrar registrar2(partition->Device(), true); DeviceReadLocker locker(partition->Device(), true); error = validate_initialize_partition(partition, changeCounter, - diskSystemName, name, parameters); + diskSystemName, name, parameters); } if (!error) error = ddm_strlcpy(_name, name, B_DISK_DEVICE_NAME_LENGTH); @@ -1033,17 +1059,15 @@ return error; } + // _user_validate_create_child_partition status_t _user_validate_create_child_partition(partition_id partitionID, - int32 changeCounter, off_t *_offset, - off_t *_size, const char *_type, - const char *_parameters, - size_t parametersSize) + int32 changeCounter, off_t *_offset, off_t *_size, const char *_type, + const char *_parameters, size_t parametersSize) { if (!_offset || !_size || !_type - || parametersSize > B_DISK_DEVICE_MAX_PARAMETER_SIZE) - { + || parametersSize > B_DISK_DEVICE_MAX_PARAMETER_SIZE) { return B_BAD_VALUE; } off_t offset; @@ -1065,13 +1089,13 @@ KDiskDeviceManager *manager = KDiskDeviceManager::Default(); // get the partition KPartition *partition = manager->ReadLockPartition(partitionID); - error = partition ? B_OK : B_ENTRY_NOT_FOUND; + error = partition ? (status_t)B_OK : (status_t)B_ENTRY_NOT_FOUND; if (!error) { PartitionRegistrar registrar1(partition, true); PartitionRegistrar registrar2(partition->Device(), true); DeviceReadLocker locker(partition->Device(), true); - error = validate_create_child_partition(partition, changeCounter, &offset, - &size, type, parameters); + error = validate_create_child_partition(partition, changeCounter, + &offset, &size, type, parameters); } if (!error) { user_memcpy(_offset, &offset, sizeof(offset)); @@ -1081,11 +1105,11 @@ return error; } + // _user_get_next_supported_partition_type status_t _user_get_next_supported_partition_type(partition_id partitionID, - int32 changeCounter, int32 *_cookie, - char *_type) + int32 changeCounter, int32 *_cookie, char *_type) { if (!_cookie || !_type) return B_BAD_VALUE; @@ -1094,20 +1118,22 @@ KDiskDeviceManager *manager = KDiskDeviceManager::Default(); // get the partition KPartition *partition = manager->ReadLockPartition(partitionID); - status_t error = partition ? B_OK : B_ENTRY_NOT_FOUND; + status_t error = partition ? (status_t)B_OK : (status_t)B_ENTRY_NOT_FOUND; if (!error) { PartitionRegistrar registrar1(partition, true); PartitionRegistrar registrar2(partition->Device(), true); DeviceReadLocker locker(partition->Device(), true); - error = check_shadow_partition(partition, changeCounter) ? B_OK : B_BAD_VALUE; + error = check_shadow_partition(partition, changeCounter) + ? B_OK : B_BAD_VALUE; if (!error) { // get the disk system KDiskSystem *diskSystem = partition->DiskSystem(); - error = diskSystem ? B_OK : B_ENTRY_NOT_FOUND; + error = diskSystem ? (status_t)B_OK : (status_t)B_ENTRY_NOT_FOUND; if (!error) { // get the info char type[B_DISK_DEVICE_TYPE_LENGTH]; - error = diskSystem->GetNextSupportedType(partition, &cookie, type); + error = diskSystem->GetNextSupportedType(partition, &cookie, + type); if (!error) { error = ddm_strlcpy(_type, type, B_DISK_DEVICE_TYPE_LENGTH); } @@ -1119,15 +1145,17 @@ return error; } + // _user_get_partition_type_for_content_type status_t _user_get_partition_type_for_content_type(disk_system_id diskSystemID, - const char *_contentType, char *_type) + const char *_contentType, char *_type) { if (!_contentType || !_type) return B_BAD_VALUE; char contentType[B_DISK_DEVICE_TYPE_LENGTH]; - status_t error = ddm_strlcpy(contentType, _contentType, B_DISK_DEVICE_TYPE_LENGTH); + status_t error = ddm_strlcpy(contentType, _contentType, + B_DISK_DEVICE_TYPE_LENGTH); if (error) return error; KDiskDeviceManager *manager = KDiskDeviceManager::Default(); @@ -1138,12 +1166,12 @@ DiskSystemLoader loader(diskSystem, true); // get the info char type[B_DISK_DEVICE_TYPE_LENGTH]; - if (diskSystem->GetTypeForContentType(contentType, type)) { + if (diskSystem->GetTypeForContentType(contentType, type)) return ddm_strlcpy(_type, type, B_DISK_DEVICE_TYPE_LENGTH); - } return B_ERROR; } + // _user_prepare_disk_device_modifications status_t _user_prepare_disk_device_modifications(partition_id deviceID) @@ -1165,7 +1193,7 @@ // _user_commit_disk_device_modifications status_t _user_commit_disk_device_modifications(partition_id deviceID, port_id port, - int32 token, bool completeProgress) + int32 token, bool completeProgress) { KDiskDeviceManager *manager = KDiskDeviceManager::Default(); // get the device @@ -1195,6 +1223,7 @@ return B_ENTRY_NOT_FOUND; } + // _user_cancel_disk_device_modifications status_t _user_cancel_disk_device_modifications(partition_id deviceID) @@ -1213,6 +1242,7 @@ return B_ENTRY_NOT_FOUND; } + // _user_is_disk_device_modified bool _user_is_disk_device_modified(partition_id deviceID) @@ -1224,13 +1254,14 @@ if (DeviceReadLocker locker = device) { // check whether there's a shadow device and whether it's changed return (device->ShadowOwner() == get_current_team() - && device->ShadowPartition() - && device->ShadowPartition()->ChangeFlags() != 0); + && device->ShadowPartition() + && device->ShadowPartition()->ChangeFlags() != 0); } } return B_ENTRY_NOT_FOUND; } + // _user_defragment_partition status_t _user_defragment_partition(partition_id partitionID, int32 changeCounter) @@ -1252,10 +1283,11 @@ return B_OK; } + // _user_repair_partition status_t _user_repair_partition(partition_id partitionID, int32 changeCounter, - bool checkOnly) + bool checkOnly) { KDiskDeviceManager *manager = KDiskDeviceManager::Default(); // get the partition @@ -1267,7 +1299,7 @@ DeviceWriteLocker locker(partition->Device(), true); // check whether the disk system supports defragmenting status_t error = validate_repair_partition(partition, changeCounter, - checkOnly); + checkOnly); if (error != B_OK) return error; // set the respective flag @@ -1278,10 +1310,11 @@ return B_OK; } + // _user_resize_partition status_t _user_resize_partition(partition_id partitionID, int32 changeCounter, - off_t size) + off_t size) { KDiskDeviceManager *manager = KDiskDeviceManager::Default(); // get the partition @@ -1297,7 +1330,7 @@ off_t proposedSize = size; off_t contentSize = 0; status_t error = validate_resize_partition(partition, changeCounter, - &proposedSize, &contentSize); + &proposedSize, &contentSize); if (error != B_OK) return error; if (proposedSize != size) @@ -1318,10 +1351,11 @@ return error; } + // _user_move_partition status_t _user_move_partition(partition_id partitionID, int32 changeCounter, - off_t newOffset) + off_t newOffset) { KDiskDeviceManager *manager = KDiskDeviceManager::Default(); // get the partition @@ -1336,7 +1370,7 @@ return B_OK; off_t proposedOffset = newOffset; status_t error = validate_move_partition(partition, changeCounter, - &proposedOffset, true); + &proposedOffset, true); if (error != B_OK) return error; if (proposedOffset != newOffset) @@ -1354,10 +1388,11 @@ return move_descendants_contents(partition); } + // _user_set_partition_name status_t _user_set_partition_name(partition_id partitionID, int32 changeCounter, - const char *_name) + const char *_name) { if (!_name) return B_BAD_VALUE; @@ -1376,8 +1411,7 @@ // check name char proposedName[B_DISK_DEVICE_NAME_LENGTH]; strcpy(proposedName, name); - error = validate_set_partition_name(partition, changeCounter, - proposedName); + error = validate_set_partition_name(partition, changeCounter, proposedName); if (error != B_OK) return error; if (strcmp(name, proposedName)) @@ -1392,10 +1426,11 @@ partition, B_PARTITION_SET_NAME); } + // _user_set_partition_content_name status_t _user_set_partition_content_name(partition_id partitionID, int32 changeCounter, - const char *_name) + const char *_name) { if (!_name) return B_BAD_VALUE; @@ -1430,10 +1465,11 @@ partition, B_PARTITION_SET_CONTENT_NAME); } + // _user_set_partition_type status_t _user_set_partition_type(partition_id partitionID, int32 changeCounter, - const char *_type) + const char *_type) { if (!_type) return B_BAD_VALUE; @@ -1450,8 +1486,7 @@ PartitionRegistrar registrar2(partition->Device(), true); DeviceWriteLocker locker(partition->Device(), true); // check type - error = validate_set_partition_type(partition, changeCounter, - type); + error = validate_set_partition_type(partition, changeCounter, type); if (error != B_OK) return error; // set type @@ -1464,10 +1499,11 @@ partition, B_PARTITION_SET_TYPE); } + // _user_set_partition_parameters status_t _user_set_partition_parameters(partition_id partitionID, int32 changeCounter, - const char *_parameters, size_t parametersSize) + const char *_parameters, size_t parametersSize) { if (!_parameters || parametersSize > B_DISK_DEVICE_MAX_PARAMETER_SIZE) return B_BAD_VALUE; @@ -1482,7 +1518,7 @@ KDiskDeviceManager *manager = KDiskDeviceManager::Default(); // get the partition KPartition *partition = manager->WriteLockPartition(partitionID); - status_t error = partition ? B_OK : B_ENTRY_NOT_FOUND; + status_t error = partition ? (status_t)B_OK : (status_t)B_ENTRY_NOT_FOUND; if (!error) { PartitionRegistrar registrar1(partition, true); PartitionRegistrar registrar2(partition->Device(), true); @@ -1496,8 +1532,9 @@ if (!error) { partition->Changed(B_PARTITION_CHANGED_PARAMETERS); // implicit partitioning system changes - error = partition->Parent()->DiskSystem()->ShadowPartitionChanged( - partition, B_PARTITION_SET_PARAMETERS); + error = partition->Parent()->DiskSystem() + ->ShadowPartitionChanged(partition, + B_PARTITION_SET_PARAMETERS); } } } @@ -1505,12 +1542,11 @@ return error; } + // _user_set_partition_content_parameters status_t _user_set_partition_content_parameters(partition_id partitionID, - int32 changeCounter, - const char *_parameters, - size_t parametersSize) + int32 changeCounter, const char *_parameters, size_t parametersSize) { if (!_parameters || parametersSize > B_DISK_DEVICE_MAX_PARAMETER_SIZE) return B_BAD_VALUE; @@ -1525,7 +1561,7 @@ KDiskDeviceManager *manager = KDiskDeviceManager::Default(); // get the partition KPartition *partition = manager->WriteLockPartition(partitionID); - status_t error = partition ? B_OK : B_ENTRY_NOT_FOUND; + status_t error = partition ? (status_t)B_OK : (status_t)B_ENTRY_NOT_FOUND; if (!error) { PartitionRegistrar registrar1(partition, true); PartitionRegistrar registrar2(partition->Device(), true); @@ -1548,18 +1584,22 @@ return error; } + // _user_initialize_partition status_t _user_initialize_partition(partition_id partitionID, int32 changeCounter, - const char *_diskSystemName, const char *_name, - const char *_parameters, size_t parametersSize) + const char *_diskSystemName, const char *_name, const char *_parameters, + size_t parametersSize) { - if (!_diskSystemName || !_name || parametersSize > B_DISK_DEVICE_MAX_PARAMETER_SIZE) + if (!_diskSystemName || !_name + || parametersSize > B_DISK_DEVICE_MAX_PARAMETER_SIZE) { return B_BAD_VALUE; + } char diskSystemName[B_DISK_SYSTEM_NAME_LENGTH]; char name[B_DISK_DEVICE_NAME_LENGTH]; char *parameters = NULL; - status_t error = ddm_strlcpy(diskSystemName, _diskSystemName, B_DISK_SYSTEM_NAME_LENGTH); + status_t error = ddm_strlcpy(diskSystemName, _diskSystemName, + B_DISK_SYSTEM_NAME_LENGTH); if (!error) error = ddm_strlcpy(name, _name, B_DISK_DEVICE_NAME_LENGTH); if (error) @@ -1574,14 +1614,14 @@ KDiskDeviceManager *manager = KDiskDeviceManager::Default(); // get the partition KPartition *partition = manager->WriteLockPartition(partitionID); - error = partition ? B_OK : B_ENTRY_NOT_FOUND; + error = partition ? (status_t)B_OK : (status_t)B_ENTRY_NOT_FOUND; if (!error) { PartitionRegistrar registrar1(partition, true); PartitionRegistrar registrar2(partition->Device(), true); DeviceWriteLocker locker(partition->Device(), true); // get the disk system KDiskSystem *diskSystem = manager->LoadDiskSystem(diskSystemName); - error = diskSystem ? B_OK : B_ENTRY_NOT_FOUND; + error = diskSystem ? (status_t)B_OK : (status_t)B_ENTRY_NOT_FOUND; if (!error) { DiskSystemLoader loader(diskSystem, true); // check parameters @@ -1593,7 +1633,8 @@ error = !strcmp(name, proposedName) ? B_OK : B_BAD_VALUE; } if (!error) { - // unitialize the partition's contents and set the new parameters + // unitialize the partition's contents and set the new + // parameters error = partition->UninitializeContents(true); } if (!error) { @@ -1617,6 +1658,7 @@ return error; } + // _user_uninitialize_partition status_t _user_uninitialize_partition(partition_id partitionID, int32 changeCounter) @@ -1633,12 +1675,12 @@ return partition->UninitializeContents(true); } + // _user_create_child_partition status_t _user_create_child_partition(partition_id partitionID, int32 changeCounter, - off_t offset, off_t size, const char *_type, - const char *_parameters, size_t parametersSize, - partition_id *_childID) + off_t offset, off_t size, const char *_type, const char *_parameters, + size_t parametersSize, partition_id *_childID) { if (!_type || parametersSize > B_DISK_DEVICE_MAX_PARAMETER_SIZE) return B_BAD_VALUE; @@ -1657,7 +1699,7 @@ KDiskDeviceManager *manager = KDiskDeviceManager::Default(); // get the partition KPartition *partition = manager->WriteLockPartition(partitionID); - error = partition ? B_OK : B_ENTRY_NOT_FOUND; + error = partition ? (status_t)B_OK : (status_t)B_ENTRY_NOT_FOUND; if (!error) { PartitionRegistrar registrar1(partition, true); PartitionRegistrar registrar2(partition->Device(), true); @@ -1701,6 +1743,7 @@ return error; } + // _user_delete_partition status_t _user_delete_partition(partition_id partitionID, int32 changeCounter) @@ -1725,10 +1768,11 @@ return B_OK; } + // _user_get_next_disk_device_job_info status_t _user_get_next_disk_device_job_info(int32 *_cookie, - user_disk_device_job_info *_info) + user_disk_device_job_info *_info) { if (!_cookie || !_info) return B_BAD_VALUE; @@ -1761,6 +1805,7 @@ return error; } + // _user_get_disk_device_job_info status_t _user_get_disk_device_job_info(disk_job_id id, user_disk_device_job_info *_info) @@ -1780,10 +1825,11 @@ return error; } + // _user_get_disk_device_job_status status_t _user_get_disk_device_job_progress_info(disk_job_id id, - disk_device_job_progress_info *_info) + disk_device_job_progress_info *_info) { if (!_info) return B_BAD_VALUE; @@ -1800,6 +1846,7 @@ return error; } + // _user_pause_disk_device_job status_t _user_pause_disk_device_job(disk_job_id id) @@ -1819,6 +1866,7 @@ return B_ENTRY_NOT_FOUND; } [... truncated: 6 lines follow ...] From bonefish at mail.berlios.de Sat Oct 6 01:25:59 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sat, 6 Oct 2007 01:25:59 +0200 Subject: [Haiku-commits] r22454 - in haiku/trunk/src: kits/storage system/kernel/disk_device_manager Message-ID: <200710052325.l95NPxdb014118@sheep.berlios.de> Author: bonefish Date: 2007-10-06 01:25:58 +0200 (Sat, 06 Oct 2007) New Revision: 22454 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22454&view=rev Modified: haiku/trunk/src/kits/storage/Partition.cpp haiku/trunk/src/system/kernel/disk_device_manager/KFileSystem.cpp haiku/trunk/src/system/kernel/disk_device_manager/KPartitioningSystem.cpp haiku/trunk/src/system/kernel/disk_device_manager/ddm_operation_validation.cpp haiku/trunk/src/system/kernel/disk_device_manager/ddm_userland_interface.cpp Log: * Allow NULL name argument on initialization. * Some code beautification on the way. Modified: haiku/trunk/src/kits/storage/Partition.cpp =================================================================== --- haiku/trunk/src/kits/storage/Partition.cpp 2007-10-05 22:39:52 UTC (rev 22453) +++ haiku/trunk/src/kits/storage/Partition.cpp 2007-10-05 23:25:58 UTC (rev 22454) @@ -980,11 +980,11 @@ BPartition::ValidateInitialize(const char *diskSystem, char *name, const char *parameters) { - if (!fPartitionData || !_IsShadow() || !diskSystem || !name) + if (!fPartitionData || !_IsShadow() || !diskSystem) return B_BAD_VALUE; return _kern_validate_initialize_partition(_ShadowID(), _ChangeCounter(), - diskSystem, name, parameters, - (parameters ? strlen(parameters)+1 : 0)); + diskSystem, name, parameters, + (parameters ? strlen(parameters) + 1 : 0)); } // Initialize @@ -992,11 +992,11 @@ BPartition::Initialize(const char *diskSystem, const char *name, const char *parameters) { - if (!fPartitionData || !_IsShadow() || !diskSystem || !name) + if (!fPartitionData || !_IsShadow() || !diskSystem) return B_BAD_VALUE; status_t error = _kern_initialize_partition(_ShadowID(), _ChangeCounter(), - diskSystem, name, parameters, - (parameters ? strlen(parameters)+1 : 0)); + diskSystem, name, parameters, + (parameters ? strlen(parameters) + 1 : 0)); if (error == B_OK) error = Device()->Update(); return error; Modified: haiku/trunk/src/system/kernel/disk_device_manager/KFileSystem.cpp =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/KFileSystem.cpp 2007-10-05 22:39:52 UTC (rev 22453) +++ haiku/trunk/src/system/kernel/disk_device_manager/KFileSystem.cpp 2007-10-05 23:25:58 UTC (rev 22454) @@ -165,9 +165,9 @@ KFileSystem::ValidateInitialize(KPartition *partition, char *name, const char *parameters) { - return (partition && name && fModule && fModule->validate_initialize - && fModule->validate_initialize(partition->PartitionData(), name, - parameters)); + return (partition && fModule && fModule->validate_initialize + && fModule->validate_initialize(partition->PartitionData(), name, + parameters)); } Modified: haiku/trunk/src/system/kernel/disk_device_manager/KPartitioningSystem.cpp =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/KPartitioningSystem.cpp 2007-10-05 22:39:52 UTC (rev 22453) +++ haiku/trunk/src/system/kernel/disk_device_manager/KPartitioningSystem.cpp 2007-10-05 23:25:58 UTC (rev 22454) @@ -314,7 +314,7 @@ KPartitioningSystem::ValidateInitialize(KPartition *partition, char *name, const char *parameters) { - return (partition && name && fModule && fModule->validate_initialize + return (partition && fModule && fModule->validate_initialize && fModule->validate_initialize(partition->PartitionData(), name, parameters)); } @@ -788,7 +788,7 @@ const char *parameters, KDiskDeviceJob *job) { // check parameters - if (!partition || !job || !name /*|| !parameters*/) + if (!partition || !job /*|| !parameters*/) return B_BAD_VALUE; if (!fModule->initialize) return B_ENTRY_NOT_FOUND; Modified: haiku/trunk/src/system/kernel/disk_device_manager/ddm_operation_validation.cpp =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/ddm_operation_validation.cpp 2007-10-05 22:39:52 UTC (rev 22453) +++ haiku/trunk/src/system/kernel/disk_device_manager/ddm_operation_validation.cpp 2007-10-05 23:25:58 UTC (rev 22454) @@ -401,20 +401,25 @@ int32 changeCounter, const char *diskSystemName, char *name, const char *parameters, bool requireShadow) { - if (!partition || !diskSystemName || !name) + if (!partition || !diskSystemName) return B_BAD_VALUE; + // truncate name to maximal size - name[B_OS_NAME_LENGTH] = '\0'; + if (name) + name[B_OS_NAME_LENGTH] = '\0'; + // check the partition status_t error = check_partition(partition, changeCounter, requireShadow); if (error != B_OK) return error; + // get the disk system KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KDiskSystem *diskSystem = manager->LoadDiskSystem(diskSystemName); if (!diskSystem) return B_ENTRY_NOT_FOUND; DiskSystemLoader loader(diskSystem, true); + // get the info if (diskSystem->ValidateInitialize(partition, name, parameters)) return B_OK; Modified: haiku/trunk/src/system/kernel/disk_device_manager/ddm_userland_interface.cpp =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/ddm_userland_interface.cpp 2007-10-05 22:39:52 UTC (rev 22453) +++ haiku/trunk/src/system/kernel/disk_device_manager/ddm_userland_interface.cpp 2007-10-05 23:25:58 UTC (rev 22454) @@ -1022,40 +1022,52 @@ int32 changeCounter, const char *_diskSystemName, char *_name, const char *_parameters, size_t parametersSize) { - if (!_diskSystemName || !_name - || parametersSize > B_DISK_DEVICE_MAX_PARAMETER_SIZE) { + if (!_diskSystemName || parametersSize > B_DISK_DEVICE_MAX_PARAMETER_SIZE) return B_BAD_VALUE; - } + + // copy disk system name char diskSystemName[B_DISK_SYSTEM_NAME_LENGTH]; - char name[B_DISK_DEVICE_NAME_LENGTH]; - char *parameters = NULL; status_t error = ddm_strlcpy(diskSystemName, _diskSystemName, B_DISK_SYSTEM_NAME_LENGTH); - if (!error) + + // copy name + char name[B_DISK_DEVICE_NAME_LENGTH]; + if (!error && _name) error = ddm_strlcpy(name, _name, B_DISK_DEVICE_NAME_LENGTH, true); - if (error) + + if (error != B_OK) return error; + + // copy parameters + char *parameters = NULL; + MemoryDeleter parameterDeleter; if (_parameters) { parameters = static_cast(malloc(parametersSize)); - if (parameters) - user_memcpy(parameters, _parameters, parametersSize); - else + if (!parameters) return B_NO_MEMORY; + parameterDeleter.SetTo(parameters); + + if (user_memcpy(parameters, _parameters, parametersSize) != B_OK) + return B_BAD_ADDRESS; } + + // get the partition KDiskDeviceManager *manager = KDiskDeviceManager::Default(); - // get the partition KPartition *partition = manager->ReadLockPartition(partitionID); - error = partition ? (status_t)B_OK : (status_t)B_ENTRY_NOT_FOUND; - if (!error) { - PartitionRegistrar registrar1(partition, true); - PartitionRegistrar registrar2(partition->Device(), true); - DeviceReadLocker locker(partition->Device(), true); - error = validate_initialize_partition(partition, changeCounter, - diskSystemName, name, parameters); - } - if (!error) + if (!partition) + return B_ENTRY_NOT_FOUND; + + // validate + PartitionRegistrar registrar1(partition, true); + PartitionRegistrar registrar2(partition->Device(), true); + DeviceReadLocker locker(partition->Device(), true); + error = validate_initialize_partition(partition, changeCounter, + diskSystemName, _name ? name : NULL, parameters); + + // copy back the modified name + if (!error && _name) error = ddm_strlcpy(_name, name, B_DISK_DEVICE_NAME_LENGTH); - free(parameters); + return error; } @@ -1591,71 +1603,83 @@ const char *_diskSystemName, const char *_name, const char *_parameters, size_t parametersSize) { - if (!_diskSystemName || !_name - || parametersSize > B_DISK_DEVICE_MAX_PARAMETER_SIZE) { + if (!_diskSystemName || parametersSize > B_DISK_DEVICE_MAX_PARAMETER_SIZE) return B_BAD_VALUE; - } + + // copy disk system name char diskSystemName[B_DISK_SYSTEM_NAME_LENGTH]; - char name[B_DISK_DEVICE_NAME_LENGTH]; - char *parameters = NULL; status_t error = ddm_strlcpy(diskSystemName, _diskSystemName, B_DISK_SYSTEM_NAME_LENGTH); - if (!error) + + // copy name + char name[B_DISK_DEVICE_NAME_LENGTH]; + if (!error && _name) error = ddm_strlcpy(name, _name, B_DISK_DEVICE_NAME_LENGTH); + if (error) return error; + + // copy parameters + MemoryDeleter parameterDeleter; + char *parameters = NULL; if (_parameters) { parameters = static_cast(malloc(parametersSize)); - if (parameters) - user_memcpy(parameters, _parameters, parametersSize); - else + if (!parameters) return B_NO_MEMORY; + parameterDeleter.SetTo(parameters); + + if (user_memcpy(parameters, _parameters, parametersSize) != B_OK) + return B_BAD_ADDRESS; } + + // get the partition KDiskDeviceManager *manager = KDiskDeviceManager::Default(); - // get the partition KPartition *partition = manager->WriteLockPartition(partitionID); - error = partition ? (status_t)B_OK : (status_t)B_ENTRY_NOT_FOUND; - if (!error) { - PartitionRegistrar registrar1(partition, true); - PartitionRegistrar registrar2(partition->Device(), true); - DeviceWriteLocker locker(partition->Device(), true); - // get the disk system - KDiskSystem *diskSystem = manager->LoadDiskSystem(diskSystemName); - error = diskSystem ? (status_t)B_OK : (status_t)B_ENTRY_NOT_FOUND; - if (!error) { - DiskSystemLoader loader(diskSystem, true); - // check parameters - char proposedName[B_DISK_DEVICE_NAME_LENGTH]; - strcpy(proposedName, name); - error = validate_initialize_partition(partition, changeCounter, - diskSystemName, proposedName, parameters); - if (!error) { - error = !strcmp(name, proposedName) ? B_OK : B_BAD_VALUE; - } - if (!error) { - // unitialize the partition's contents and set the new - // parameters - error = partition->UninitializeContents(true); - } - if (!error) { - partition->SetDiskSystem(diskSystem); - error = partition->SetContentName(name); - } - if (!error) { - partition->Changed(B_PARTITION_CHANGED_CONTENT_NAME); - error = partition->SetContentParameters(parameters); - } - if (!error) { - partition->Changed(B_PARTITION_CHANGED_CONTENT_PARAMETERS); - partition->Changed(B_PARTITION_CHANGED_INITIALIZATION); - // implicit content disk system changes - error = partition->DiskSystem()->ShadowPartitionChanged( - partition, B_PARTITION_INITIALIZE); - } - } - } - free(parameters); - return error; + if (!partition) + return B_ENTRY_NOT_FOUND; + + PartitionRegistrar registrar1(partition, true); + PartitionRegistrar registrar2(partition->Device(), true); + DeviceWriteLocker locker(partition->Device(), true); + + // get the disk system + KDiskSystem *diskSystem = manager->LoadDiskSystem(diskSystemName); + if (!diskSystem) + return B_ENTRY_NOT_FOUND; + DiskSystemLoader loader(diskSystem, true); + + // check parameters + char proposedName[B_DISK_DEVICE_NAME_LENGTH]; + if (_name) + strcpy(proposedName, name); + + error = validate_initialize_partition(partition, changeCounter, + diskSystemName, _name ? proposedName : NULL, parameters); + if (error != B_OK) + return error; + if (_name && strcmp(name, proposedName) != 0) + return B_BAD_VALUE; + + // unitialize the partition's contents and set the new + // parameters + if ((error = partition->UninitializeContents(true)) != B_OK) + return error; + + partition->SetDiskSystem(diskSystem); + + if ((error = partition->SetContentName(_name ? name : NULL)) != B_OK) + return error; + partition->Changed(B_PARTITION_CHANGED_CONTENT_NAME); + + if ((error = partition->SetContentParameters(parameters)) != B_OK) + return error; + partition->Changed(B_PARTITION_CHANGED_CONTENT_PARAMETERS); + + partition->Changed(B_PARTITION_CHANGED_INITIALIZATION); + + // implicit content disk system changes + return partition->DiskSystem()->ShadowPartitionChanged( + partition, B_PARTITION_INITIALIZE); } From axeld at mail.berlios.de Sat Oct 6 13:18:23 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sat, 6 Oct 2007 13:18:23 +0200 Subject: [Haiku-commits] r22455 - in haiku/trunk: headers/private/kernel src/system/kernel/arch/ppc src/system/kernel/arch/x86 src/system/kernel/vm Message-ID: <200710061118.l96BINUO010331@sheep.berlios.de> Author: axeld Date: 2007-10-06 13:18:21 +0200 (Sat, 06 Oct 2007) New Revision: 22455 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22455&view=rev Modified: haiku/trunk/headers/private/kernel/vm_translation_map.h haiku/trunk/src/system/kernel/arch/ppc/arch_vm_translation_map.cpp haiku/trunk/src/system/kernel/arch/x86/arch_vm_translation_map.cpp haiku/trunk/src/system/kernel/vm/vm.cpp haiku/trunk/src/system/kernel/vm/vm_page.cpp Log: * Mapping a page might actually need memory - since we usually have locks that interfere with the page thief, we always need to have reserved a page for this upfront. I introduced a function to the vm_translation_map layer that estimates how much pages a mapping might need at maximum. All functions that map a page now call this and reserve the needed pages upfront. It might not be a nice solution, but it works. * The page thief could run into a panic when trying to call vm_cache_release_ref() on a non-existing (NULL) cache. * Also, it will now ignore wired active pages. * There is still a race condition between the page writer and the vnode destruction - writing a page back needs a valid vnode, but that might just have been deleted. Modified: haiku/trunk/headers/private/kernel/vm_translation_map.h =================================================================== --- haiku/trunk/headers/private/kernel/vm_translation_map.h 2007-10-05 23:25:58 UTC (rev 22454) +++ haiku/trunk/headers/private/kernel/vm_translation_map.h 2007-10-06 11:18:21 UTC (rev 22455) @@ -30,6 +30,7 @@ void (*destroy)(vm_translation_map *map); status_t (*lock)(vm_translation_map *map); status_t (*unlock)(vm_translation_map *map); + size_t (*map_max_pages_need)(vm_translation_map *map, addr_t start, addr_t end); status_t (*map)(vm_translation_map *map, addr_t va, addr_t pa, uint32 attributes); status_t (*unmap)(vm_translation_map *map, addr_t start, addr_t end); Modified: haiku/trunk/src/system/kernel/arch/ppc/arch_vm_translation_map.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/ppc/arch_vm_translation_map.cpp 2007-10-05 23:25:58 UTC (rev 22454) +++ haiku/trunk/src/system/kernel/arch/ppc/arch_vm_translation_map.cpp 2007-10-06 11:18:21 UTC (rev 22455) @@ -1,5 +1,5 @@ /* - * Copyright 2003-2006, Axel D?rfler, axeld at pinc-software.de. + * Copyright 2003-2007, Axel D?rfler, axeld at pinc-software.de. * Distributed under the terms of the MIT License. * * Copyright 2001, Travis Geiselbrecht. All rights reserved. @@ -205,6 +205,13 @@ } +static size_t +map_max_pages_need(vm_translation_map *map, addr_t start, addr_t end) +{ + return 0; +} + + static status_t map_tmap(vm_translation_map *map, addr_t virtualAddress, addr_t physicalAddress, uint32 attributes) { @@ -454,6 +461,7 @@ destroy_tmap, lock_tmap, unlock_tmap, + map_max_pages_need, map_tmap, unmap_tmap, query_tmap, Modified: haiku/trunk/src/system/kernel/arch/x86/arch_vm_translation_map.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/arch_vm_translation_map.cpp 2007-10-05 23:25:58 UTC (rev 22454) +++ haiku/trunk/src/system/kernel/arch/x86/arch_vm_translation_map.cpp 2007-10-06 11:18:21 UTC (rev 22455) @@ -325,6 +325,13 @@ } +static size_t +map_max_pages_need(vm_translation_map */*map*/, addr_t start, addr_t end) +{ + return VADDR_TO_PDENT(end) + 1 - VADDR_TO_PDENT(start); +} + + static status_t map_tmap(vm_translation_map *map, addr_t va, addr_t pa, uint32 attributes) { @@ -352,7 +359,7 @@ vm_page *page; // we need to allocate a pgtable - page = vm_page_allocate_page(PAGE_STATE_CLEAR, false); + page = vm_page_allocate_page(PAGE_STATE_CLEAR, true); // mark the page WIRED vm_page_set_state(page, PAGE_STATE_WIRED); @@ -737,6 +744,7 @@ destroy_tmap, lock_tmap, unlock_tmap, + map_max_pages_need, map_tmap, unmap_tmap, query_tmap, Modified: haiku/trunk/src/system/kernel/vm/vm.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm.cpp 2007-10-05 23:25:58 UTC (rev 22454) +++ haiku/trunk/src/system/kernel/vm/vm.cpp 2007-10-06 11:18:21 UTC (rev 22455) @@ -1483,6 +1483,11 @@ case B_FULL_LOCK: { + vm_translation_map *map = &addressSpace->translation_map; + size_t reservePages = map->ops->map_max_pages_need(map, + area->base, area->base + (area->size - 1)); + vm_page_reserve_pages(reservePages); + // Allocate and map all pages for this area mutex_lock(&cache->lock); @@ -1510,6 +1515,7 @@ } mutex_unlock(&cache->lock); + vm_page_unreserve_pages(reservePages); break; } @@ -1561,9 +1567,12 @@ // map them in the address space vm_translation_map *map = &addressSpace->translation_map; addr_t physicalAddress = page->physical_page_number * B_PAGE_SIZE; - addr_t virtualAddress; + addr_t virtualAddress = area->base; + size_t reservePages = map->ops->map_max_pages_need(map, + virtualAddress, virtualAddress + (area->size - 1)); off_t offset = 0; + vm_page_reserve_pages(reservePages); mutex_lock(&cache->lock); map->ops->lock(map); @@ -1587,6 +1596,7 @@ map->ops->unlock(map); mutex_unlock(&cache->lock); + vm_page_unreserve_pages(reservePages); break; } @@ -1687,6 +1697,10 @@ // make sure our area is mapped in completely vm_translation_map *map = &locker.AddressSpace()->translation_map; + size_t reservePages = map->ops->map_max_pages_need(map, area->base, + area->base + (size - 1)); + + vm_page_reserve_pages(reservePages); map->ops->lock(map); for (addr_t offset = 0; offset < size; offset += B_PAGE_SIZE) { @@ -1695,6 +1709,7 @@ } map->ops->unlock(map); + vm_page_unreserve_pages(reservePages); } if (status < B_OK) @@ -1966,6 +1981,10 @@ map->ops->unlock(map); map = &targetAddressSpace->translation_map; + size_t reservePages = map->ops->map_max_pages_need(map, + newArea->base, newArea->base + (newArea->size - 1)); + + vm_page_reserve_pages(reservePages); map->ops->lock(map); for (addr_t offset = 0; offset < newArea->size; @@ -1975,7 +1994,13 @@ } map->ops->unlock(map); + vm_page_unreserve_pages(reservePages); } else { + vm_translation_map *map = &targetAddressSpace->translation_map; + size_t reservePages = map->ops->map_max_pages_need(map, + newArea->base, newArea->base + (newArea->size - 1)); + vm_page_reserve_pages(reservePages); + // map in all pages from source for (vm_page *page = cache->page_list; page != NULL; page = page->cache_next) { @@ -1983,6 +2008,8 @@ + ((page->cache_offset << PAGE_SHIFT) - newArea->cache_offset), protection); } + + vm_page_unreserve_pages(reservePages); } } if (status == B_OK) @@ -2549,6 +2576,7 @@ } +/*! When calling this function, you need to have pages reserved! */ status_t vm_map_page(vm_area *area, vm_page *page, addr_t address, uint32 protection) { @@ -4193,12 +4221,14 @@ // The top most cache has no fault handler, so let's see if the cache or its sources // already have the page we're searching for (we're going from top to bottom) - vm_page_reserve_pages(2); + vm_translation_map *map = &addressSpace->translation_map; + size_t reservePages = 2 + map->ops->map_max_pages_need(map, + originalAddress, originalAddress); + vm_page_reserve_pages(reservePages); // we may need up to 2 pages - reserving them upfront makes sure // we don't have any cache locked, so that the page daemon/thief // can do their job without problems - vm_translation_map *map = &addressSpace->translation_map; vm_dummy_page dummyPage; dummyPage.cache = NULL; dummyPage.state = PAGE_STATE_INACTIVE; @@ -4252,7 +4282,7 @@ } vm_cache_release_ref(topCache); - vm_page_unreserve_pages(2); + vm_page_unreserve_pages(reservePages); return status; } Modified: haiku/trunk/src/system/kernel/vm/vm_page.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_page.cpp 2007-10-05 23:25:58 UTC (rev 22454) +++ haiku/trunk/src/system/kernel/vm/vm_page.cpp 2007-10-06 11:18:21 UTC (rev 22455) @@ -776,7 +776,8 @@ enqueue_page(&sActivePageQueue, page); if ((page->state == PAGE_STATE_INACTIVE - || stealActive && page->state == PAGE_STATE_ACTIVE) + || (stealActive && page->state == PAGE_STATE_ACTIVE + && page->wired_count == 0)) && page->usage_count <= score) break; } @@ -826,8 +827,8 @@ { if (fIsLocked) mutex_unlock(&fCache->lock); - - vm_cache_release_ref(fCache); + if (fCache != NULL) + vm_cache_release_ref(fCache); } bool IsLocked() { return fIsLocked; } @@ -836,7 +837,7 @@ vm_cache *fCache; bool fIsLocked; } cacheLocker(page); - + if (!cacheLocker.IsLocked()) continue; @@ -863,7 +864,7 @@ // we can now steal this page - //dprintf(" steal page %p from cache %p\n", page, cache); + //dprintf(" steal page %p from cache %p\n", page, page->cache); vm_cache_remove_page(page->cache, page); vm_page_set_state(page, PAGE_STATE_FREE); From axeld at mail.berlios.de Sat Oct 6 13:38:04 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sat, 6 Oct 2007 13:38:04 +0200 Subject: [Haiku-commits] r22456 - haiku/trunk/src/system/kernel/vm Message-ID: <200710061138.l96Bc44f030897@sheep.berlios.de> Author: axeld Date: 2007-10-06 13:38:03 +0200 (Sat, 06 Oct 2007) New Revision: 22456 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22456&view=rev Modified: haiku/trunk/src/system/kernel/vm/vm_page.cpp Log: The page thief can now also steal active pages under pressure. Modified: haiku/trunk/src/system/kernel/vm/vm_page.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_page.cpp 2007-10-06 11:18:21 UTC (rev 22455) +++ haiku/trunk/src/system/kernel/vm/vm_page.cpp 2007-10-06 11:38:03 UTC (rev 22456) @@ -760,7 +760,7 @@ //dprintf("page thief running - target %ld...\n", steal); vm_page* page = NULL; - bool stealActive = false; + bool stealActive = false, desperate = false; InterruptsSpinLocker locker(sPageLock); while (steal > 0) { @@ -790,9 +790,10 @@ break; // when memory is really low, we really want pages - if (stealActive) + if (stealActive) { score = 127; - else { + desperate = true; + } else { stealActive = true; score = 5; steal = 5; @@ -841,13 +842,11 @@ if (!cacheLocker.IsLocked()) continue; - if (page->state != PAGE_STATE_INACTIVE) { - // TODO: if this is an active page (as in stealActive), we need - // to unmap it and check if it's modified in an atomic operation. - // For now, we'll just ignore it, even though this might let - // vm_page_allocate_page() wait forever... + // check again if that page is still a candidate + if (page->state != PAGE_STATE_INACTIVE + && (!stealActive || page->state != PAGE_STATE_ACTIVE + || page->wired_count != 0)) continue; - } // recheck eventual last minute changes uint32 flags; @@ -856,7 +855,7 @@ // page was modified, don't steal it vm_page_set_state(page, PAGE_STATE_MODIFIED); continue; - } else if ((flags & PAGE_ACCESSED) != 0) { + } else if ((flags & PAGE_ACCESSED) != 0 && !desperate) { // page is in active use, don't steal it vm_page_set_state(page, PAGE_STATE_ACTIVE); continue; From axeld at mail.berlios.de Sat Oct 6 15:14:11 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sat, 6 Oct 2007 15:14:11 +0200 Subject: [Haiku-commits] r22457 - haiku/trunk/src/system/kernel Message-ID: <200710061314.l96DEBUk003161@sheep.berlios.de> Author: axeld Date: 2007-10-06 15:14:11 +0200 (Sat, 06 Oct 2007) New Revision: 22457 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22457&view=rev Modified: haiku/trunk/src/system/kernel/heap.c Log: Applied Fran?\195?\167ois' patch to be able to free large allocations. Even though the heap is going away soon, it doesn't hurt to have it in the repository. Modified: haiku/trunk/src/system/kernel/heap.c =================================================================== --- haiku/trunk/src/system/kernel/heap.c 2007-10-06 11:38:03 UTC (rev 22456) +++ haiku/trunk/src/system/kernel/heap.c 2007-10-06 13:14:11 UTC (rev 22457) @@ -73,6 +73,10 @@ uint16 in_use : 1; } PACKED; +// used for bin==bin_count allocations +#define allocation_id free_count + +static vint32 current_alloc_id = 0; static struct heap_page *heap_alloc_table; static addr_t heap_base_ptr; static addr_t heap_base; @@ -367,6 +371,13 @@ } +static inline int32 +next_alloc_id(void) +{ + return atomic_add(¤t_alloc_id, 1) & ((1<<(9-1))-1); +} + + static char * raw_alloc(unsigned int size, int bin_index) { @@ -451,9 +462,37 @@ break; if (bin_index == bin_count) { - address = raw_alloc(size, bin_index); - dprintf("heap: allocated big chunk (%ld bytes), it will never be freed!\n", - size); + int32 alloc_id; + alloc_id = next_alloc_id(); + + // try to find freed blocks first... + if (size < (heap_base_ptr - heap_base) / 10) { // but don't try too hard + int first = -1; + page = heap_alloc_table; + for (i = 0; i < (heap_base_ptr-heap_base)/B_PAGE_SIZE; i++) { + if (page[i].in_use) { + first = -1; + continue; + } + if (first > 0) { + if ((1 + i - first)*B_PAGE_SIZE > size) + break; + } + first = i; + } + if (first > -1) + address = (void *)(heap_base + first * B_PAGE_SIZE); + + } + if (address == NULL) + address = raw_alloc(size, bin_index); + page = &heap_alloc_table[((unsigned int)address - heap_base) / B_PAGE_SIZE]; + for (i = 0; i < (size+B_PAGE_SIZE-1)/B_PAGE_SIZE; i++) { + page[i].in_use = 1; + page[i].cleaning = 0; + page[i].bin_index = bin_count; + page[i].allocation_id = alloc_id; + } } else { if (bins[bin_index].free_list != NULL) { address = bins[bin_index].free_list; @@ -600,6 +639,21 @@ // TODO: since the heap must be replaced anyway, we don't // free this allocation anymore... (tracking them would // require some extra stuff) + + for (i = 1; i <= (heap_base_ptr-heap_base)/B_PAGE_SIZE; i++) { + if (!page[i].in_use) + break; + if (page[i].bin_index != bin_count) + break; + if (page[i].allocation_id != page[0].allocation_id) + break; + page[i].in_use = 0; + page[i].cleaning = 0; + page[i].allocation_id = 0; + } + page[0].in_use = 0; + page[0].cleaning = 0; + page[0].allocation_id = 0; } mutex_unlock(&heap_lock); @@ -644,11 +698,25 @@ TRACE(("realloc(): page %p: bin_index %d, free_count %d\n", page, page->bin_index, page->free_count)); - if (page[0].bin_index >= bin_count) + if (page[0].bin_index > bin_count) panic("realloc(): page %p: invalid bin_index %d\n", page, page->bin_index); - maxSize = bins[page[0].bin_index].element_size; - minSize = page[0].bin_index > 0 ? bins[page[0].bin_index - 1].element_size : 0; + if (page[0].bin_index < bin_count) { + maxSize = bins[page[0].bin_index].element_size; + minSize = page[0].bin_index > 0 ? bins[page[0].bin_index - 1].element_size : 0; + } else { + int i; + for (i = 1; (addr_t)&page[i] < heap_base; i++) { + if (!page[i].in_use) + break; + if (page[i].bin_index != bin_count) + break; + if (page[i].allocation_id != page[0].allocation_id) + break; + } + minSize = 0; + maxSize = i * B_PAGE_SIZE; + } mutex_unlock(&heap_lock); From korli at mail.berlios.de Sat Oct 6 15:45:17 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Sat, 6 Oct 2007 15:45:17 +0200 Subject: [Haiku-commits] r22458 - in haiku/trunk/src/add-ons/kernel/drivers/audio: . ice1712 Message-ID: <200710061345.l96DjHVJ004787@sheep.berlios.de> Author: korli Date: 2007-10-06 15:45:16 +0200 (Sat, 06 Oct 2007) New Revision: 22458 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22458&view=rev Added: haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/ haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/Jamfile haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/debug.c haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/debug.h haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/ice1712.c haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/ice1712.h haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/ice1712_reg.h haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/io.c haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/io.h haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/midi.c haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/multi.c haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/multi.h haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/util.c haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/util.h Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/Jamfile Log: added ice1712 driver on behalf of J?\195?\169r?\195?\180me Leveque. Thanks! Current status : playback only. Support for M-Audio Delta 1010, Delta 1010 LT, Delta DIO 2496, Delta 66, Delta 44, Audiophile 2496 and Delta 410 VX 442. Tested on M-Audio Audiophile2496. Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/Jamfile 2007-10-06 13:14:11 UTC (rev 22457) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/Jamfile 2007-10-06 13:45:16 UTC (rev 22458) @@ -5,6 +5,7 @@ SubInclude HAIKU_TOP src add-ons kernel drivers audio echo ; SubInclude HAIKU_TOP src add-ons kernel drivers audio emuxki ; SubInclude HAIKU_TOP src add-ons kernel drivers audio hda ; +SubInclude HAIKU_TOP src add-ons kernel drivers audio ice1712 ; SubInclude HAIKU_TOP src add-ons kernel drivers audio module_driver ; SubInclude HAIKU_TOP src add-ons kernel drivers audio null ; SubInclude HAIKU_TOP src add-ons kernel drivers audio sb16 ; Added: haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/Jamfile 2007-10-06 13:14:11 UTC (rev 22457) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/Jamfile 2007-10-06 13:45:16 UTC (rev 22458) @@ -0,0 +1,16 @@ +SubDir HAIKU_TOP src add-ons kernel drivers audio ice1712 ; + +SetSubDirSupportedPlatformsBeOSCompatible ; + +UsePrivateHeaders media ; + +KernelAddon ice1712 : + debug.c + ice1712.c + io.c + midi.c + multi.c + util.c +; + + Added: haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/debug.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/debug.c 2007-10-06 13:14:11 UTC (rev 22457) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/debug.c 2007-10-06 13:45:16 UTC (rev 22458) @@ -0,0 +1,79 @@ +/* + * ice1712 BeOS/Haiku Driver for VIA - VT1712 Multi Channel Audio Controller + * + * Copyright (c) 2002, Jerome Duval (jerome.duval at free.fr) + * Copyright (c) 2003, Marcus Overhagen (marcus at overhagen.de) + * Copyright (c) 2007, Jerome Leveque (leveque.jerome at neuf.fr) + * + * All rights reserved + * Distributed under the terms of the MIT license. + */ + +#include +#include +#include +#include +#include +#include "debug.h" +#include "ice1712.h" + +#if DEBUG > 0 +static const char * logfile="/boot/home/"DRIVER_NAME".log"; +static sem_id loglock; +#endif + +void debug_printf(const char *text,...); +void log_printf(const char *text,...); +void log_create(void); + +void debug_printf(const char *text,...) +{ + char buf[1024]; + va_list ap; + + va_start(ap,text); + vsprintf(buf,text,ap); + va_end(ap); + + dprintf(DRIVER_NAME ": %s",buf); +} + +void log_create(void) +{ +#if DEBUG > 0 + int fd = open(logfile, O_WRONLY | O_CREAT | O_TRUNC, 0666); + const char *text = "Driver for " DRIVER_NAME ", Version " VERSION "\n=================\n"; + loglock = create_sem(1,"logfile sem"); + write(fd,text,strlen(text)); + close(fd); +#endif +} + +void log_printf(const char *text,...) +{ +#if DEBUG > 0 + int fd; + char buf[1024]; + va_list ap; + + va_start(ap,text); + vsprintf(buf,text,ap); + va_end(ap); + + dprintf(DRIVER_NAME ": %s",buf); + + acquire_sem(loglock); + fd = open(logfile, O_WRONLY | O_APPEND); + if (fd > 0) + { + write(fd, buf, strlen(buf)); + close(fd); + } + release_sem(loglock); + + #if DEBUG > 1 + snooze(150000); + #endif +#endif +} + Added: haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/debug.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/debug.h 2007-10-06 13:14:11 UTC (rev 22457) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/debug.h 2007-10-06 13:45:16 UTC (rev 22458) @@ -0,0 +1,54 @@ +/* + * ice1712 BeOS/Haiku Driver for VIA - VT1712 Multi Channel Audio Controller + * + * Copyright (c) 2002, Jerome Duval (jerome.duval at free.fr) + * Copyright (c) 2003, Marcus Overhagen (marcus at overhagen.de) + * Copyright (c) 2007, Jerome Leveque (leveque.jerome at neuf.fr) + * + * All rights reserved + * Distributed under the terms of the MIT license. + */ + +#ifndef _DEBUG_H_ +#define _DEBUG_H_ + +/* + * PRINT() executes dprintf if DEBUG = 0 (disabled), or expands to LOG() when DEBUG > 0 + * TRACE() executes dprintf if DEBUG > 0 + * LOG() executes dprintf and writes to the logfile if DEBUG > 0 + */ + +/* DEBUG == 0, no debugging, PRINT writes to syslog + * DEBUG == 1, TRACE & LOG, PRINT + * DEBUG == 2, TRACE & LOG, PRINT with snooze() + */ +#undef DEBUG + +#ifndef DEBUG +// #define DEBUG 1 +#endif + +#undef PRINT_ICE +#undef TRACE_ICE +#undef ASSERT_ICE + +#if DEBUG > 0 + #define PRINT_ICE(a) log_printf a +// #define TRACE_ICE(a) debug_printf a + #define TRACE_ICE(a) log_printf a + #define LOG_ICE(a) log_printf a + #define LOG_CREATE_ICE() log_create() + #define ASSERT_ICE(a) if (a) {} else LOG_ICE(("ASSERT failed! file = %s, line = %d\n",__FILE__,__LINE__)) + void log_create(); + void log_printf(const char *text,...); + void debug_printf(const char *text,...); +#else + void debug_printf(const char *text,...); + #define PRINT_ICE(a) debug_printf a + #define TRACE_ICE(a) ((void)(0)) + #define ASSERT_ICE(a) ((void)(0)) + #define LOG_ICE(a) ((void)(0)) + #define LOG_CREATE_ICE() +#endif + +#endif Added: haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/ice1712.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/ice1712.c 2007-10-06 13:14:11 UTC (rev 22457) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/ice1712.c 2007-10-06 13:45:16 UTC (rev 22458) @@ -0,0 +1,575 @@ +/* + * ice1712 BeOS/Haiku Driver for VIA - VT1712 Multi Channel Audio Controller + * + * Copyright (c) 2002, Jerome Duval (jerome.duval at free.fr) + * Copyright (c) 2003, Marcus Overhagen (marcus at overhagen.de) + * Copyright (c) 2007, Jerome Leveque (leveque.jerome at neuf.fr) + * + * All rights reserved + * Distributed under the terms of the MIT license. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "debug.h" +#include "ice1712.h" +#include "ice1712_reg.h" +#include "io.h" +#include "midi_driver.h" +#include "multi.h" +#include "multi_audio.h" +#include "util.h" + + +//------------------------------------------------------ +//------------------------------------------------------ + +status_t init_hardware(void); +status_t init_driver(void); +void uninit_driver(void); +const char **publish_devices(void); +device_hooks *find_device(const char *); + +//------------------------------------------------------ + +int32 ice_1712_int(void *arg); + +//------------------------------------------------------ + +static char pci_name[] = B_PCI_MODULE_NAME; +pci_module_info *pci; +static char mpu401_name[] = B_MPU_401_MODULE_NAME; +generic_mpu401_module *mpu401; + +int32 num_cards = 0; +ice1712 cards[NUM_CARDS]; +int32 num_names = 0; +char *names[NUM_CARDS*20+1]; + +//------------------------------------------------------ +//------------------------------------------------------ + +int32 api_version = B_CUR_DRIVER_API_VERSION; + +#define MODULE_TEST_PATH "audio/multi/ice1712" + +//------------------------------------------------------ +//------------------------------------------------------ + +//void republish_devices(void); + +//extern image_id load_kernel_addon(const char *path); +//extern status_t unload_kernel_addon(image_id imid); + +//------------------------------------------------------ +//------------------------------------------------------ + +status_t init_hardware(void) +{ + int ix = 0; + pci_info info; + + memset(cards, 0, sizeof(ice1712) * NUM_CARDS); + LOG_CREATE_ICE(); + TRACE_ICE(("===init_hardware()===\n")); + + if (get_module(pci_name, (module_info **)&pci)) + return ENOSYS; + + while ((*pci->get_nth_pci_info)(ix, &info) == B_OK) { + if ((info.vendor_id == ICE1712_VENDOR_ID) && + (info.device_id == ICE1712_DEVICE_ID)) { + TRACE_ICE(("Found at least 1 card\n")); + put_module(pci_name); + return B_OK; + } + ix++; + } + put_module(pci_name); + return B_ERROR; +} + + +int32 +ice_1712_int(void *arg) +{ + ice1712 *ice = arg; + uint8 reg8 = 0; + uint16 reg16 = 0; + uint32 status = B_UNHANDLED_INTERRUPT; + +// interrupt from DMA PATH + reg8 = read_mt_uint8(ice, MT_DMA_INT_MASK_STATUS); + if (reg8 != 0) { + ice->buffer++; + ice->played_time = system_time(); + + release_sem_etc(ice->buffer_ready_sem, 1, B_DO_NOT_RESCHEDULE); + write_mt_uint8(ice, MT_DMA_INT_MASK_STATUS, reg8); + status = B_HANDLED_INTERRUPT; + } + +// interrupt from Controller Registers + reg8 = read_ccs_uint8(ice, CCS_INTERRUPT_STATUS); + if (reg8 != 0) { + write_ccs_uint8(ice, CCS_INTERRUPT_STATUS, reg8); + status = B_HANDLED_INTERRUPT; + } + +// interrupt from DS PATH + reg16 = read_ds_uint16(ice, DS_DMA_INT_STATUS); + if (reg16 != 0) { + //Ack interrupt + write_ds_uint16(ice, DS_DMA_INT_STATUS, reg16); + status = B_HANDLED_INTERRUPT; + } + + return status; +} + + +static status_t +ice1712_setup(ice1712 *ice) +{ + int result, i; + long result_l = 0; + uint8 eeprom_data[32]; + uint8 reg8 = 0; + + ice->irq = ice->info.u.h0.interrupt_line; + ice->Controller = ice->info.u.h0.base_registers[0]; + ice->DDMA = ice->info.u.h0.base_registers[1]; + ice->DMA_Path = ice->info.u.h0.base_registers[2]; + ice->Multi_Track = ice->info.u.h0.base_registers[3]; + + // Soft Reset + write_ccs_uint8(ice, CCS_CONTROL_STATUS, 0x81); + snooze(200000); + write_ccs_uint8(ice, CCS_CONTROL_STATUS, 0x01); + snooze(200000); + + result = read_eeprom(ice, eeprom_data); + + TRACE_ICE(("EEprom -> ")); + for (i = 0; i < 32; i++) + TRACE_ICE(("%x, ", eeprom_data[i])); + TRACE_ICE(("<- EEprom\n")); + + write_ccs_uint8(ice, CCS_SERR_SHADOW, 0x01); + + //Write all configurations register from EEProm + + //Write enable SVID +// (pci->write_pci_config)(ice->info.bus, ice->info.device, ice->info.function, 0x42, 2, 0x86); + //Change SVID + ice->info.device_id = eeprom_data[1] << 8 | eeprom_data[0]; + ice->info.vendor_id = eeprom_data[3] << 8 | eeprom_data[2]; + ice->product = ice->info.vendor_id << 16 | ice->info.device_id; +// (pci->write_pci_config)(ice->info.bus, ice->info.device, ice->info.function, 0x2C, 4, ice->product); + + //Write Disable SVID +// (pci->write_pci_config)(ice->info.bus, ice->info.device, ice->info.function, 0x42, 2, 0x06); + + TRACE_ICE(("Product ID : 0x%x\n", ice->product)); + + (pci->write_pci_config)(ice->info.bus, ice->info.device, ice->info.function, 0x60, 1, eeprom_data[6]); + (pci->write_pci_config)(ice->info.bus, ice->info.device, ice->info.function, 0x61, 1, eeprom_data[7]); + (pci->write_pci_config)(ice->info.bus, ice->info.device, ice->info.function, 0x62, 1, eeprom_data[8]); + (pci->write_pci_config)(ice->info.bus, ice->info.device, ice->info.function, 0x63, 1, eeprom_data[9]); + + write_cci_uint8(ice, CCI_GPIO_WRITE_MASK, eeprom_data[10]); + write_cci_uint8(ice, CCI_GPIO_DATA, eeprom_data[11]); + write_cci_uint8(ice, CCI_GPIO_DIRECTION_CONTROL, eeprom_data[12]); + write_cci_uint8(ice, CCI_CONS_POWER_DOWN, eeprom_data[13]); + write_cci_uint8(ice, CCI_MULTI_POWER_DOWN, eeprom_data[14]); + + ice->nb_MPU401 = ((eeprom_data[6] & 0x20) >> 5) + 1; + ice->nb_ADC = (((eeprom_data[6] & 0x0C) >> 2) + 1 ) * 2; + ice->nb_DAC = ((eeprom_data[6] & 0x03) + 1) * 2; + ice->spdif_config = eeprom_data[9] & 0x03; + + for (i = 0; i < ice->nb_MPU401; i++) { + sprintf(ice->midi_interf[i].name, "midi/ice1712/%ld/%d", ice - cards + 1, i + 1); + names[num_names++] = ice->midi_interf[i].name; + } + + switch (ice->product) + { + case ICE1712_SUBDEVICE_DELTA66 : + case ICE1712_SUBDEVICE_DELTA44 : + ice->gpio_cs_mask = DELTA66_CLK | DELTA66_DOUT | DELTA66_CODEC_CS_0 | DELTA66_CODEC_CS_1; + ice->analog_codec = (codec_info){DELTA66_CLK, 0, DELTA66_DOUT}; + break; + case ICE1712_SUBDEVICE_DELTA410 : + case ICE1712_SUBDEVICE_AUDIOPHILE_2496 : + case ICE1712_SUBDEVICE_DELTADIO2496 : + ice->gpio_cs_mask = AP2496_CLK | AP2496_DIN | AP2496_DOUT | AP2496_SPDIF_CS | AP2496_CODEC_CS; + ice->analog_codec = (codec_info){AP2496_CLK, AP2496_DIN, AP2496_DOUT}; + break; + case ICE1712_SUBDEVICE_DELTA1010 : + case ICE1712_SUBDEVICE_DELTA1010LT : + ice->gpio_cs_mask = DELTA1010LT_CLK | DELTA1010LT_DIN | DELTA1010LT_DOUT | DELTA1010LT_CS_NONE; + ice->analog_codec = (codec_info){DELTA1010LT_CLK, DELTA1010LT_DIN, DELTA1010LT_DOUT}; + break; + case ICE1712_SUBDEVICE_VX442 : + ice->gpio_cs_mask = VX442_SPDIF_CS | VX442_CODEC_CS_0 | VX442_CODEC_CS_1; + ice->analog_codec = (codec_info){VX442_CLK, VX442_DIN, VX442_DOUT}; + break; + } + + sprintf(ice->name, "%s/%ld", MODULE_TEST_PATH, ice - cards + 1); + names[num_names++] = ice->name; + names[num_names] = NULL; + + if ((eeprom_data[6] & 0x10) == 0) {//Consumer AC'97 Exist + TRACE_ICE(("Consumer AC'97 does exist\n")); + write_ccs_uint8(ice, CCS_CONS_AC97_COMMAND_STATUS, 0x40); + snooze(10000); + write_ccs_uint8(ice, CCS_CONS_AC97_COMMAND_STATUS, 0x00); + snooze(20000); + } else { + TRACE_ICE(("Consumer AC'97 does NOT exist\n")); + } + + ice->buffer_ready_sem = create_sem(0, "Buffer Exchange"); + +// TRACE_ICE(("installing interrupt : %0x\n", ice->irq)); + result_l = install_io_interrupt_handler(ice->irq, ice_1712_int, ice, 0); + if (result_l == B_OK) + TRACE_ICE(("Install Interrupt Handler == B_OK\n")); + else + TRACE_ICE(("Install Interrupt Handler != B_OK\n")); + + ice->mem_id_pb = alloc_mem(&ice->phys_addr_pb, &ice->log_addr_pb, + PLAYBACK_BUFFER_TOTAL_SIZE, + "playback buffer"); + + ice->mem_id_rec = alloc_mem(&ice->phys_addr_rec, &ice->log_addr_rec, + RECORD_BUFFER_TOTAL_SIZE, + "record buffer"); + + memset(ice->log_addr_pb, 0, PLAYBACK_BUFFER_TOTAL_SIZE); + memset(ice->log_addr_rec, 0, RECORD_BUFFER_TOTAL_SIZE); + + ice->sampling_rate = 0x08; + ice->buffer = 0; + ice->output_buffer_size = MAX_BUFFER_FRAMES; + ice->input_buffer_size = MAX_BUFFER_FRAMES; + + ice->total_output_channels = ice->nb_DAC; + if (ice->spdif_config & NO_IN_YES_OUT) + ice->total_output_channels += 2; + + ice->total_input_channels = ice->nb_ADC + 2; + if (ice->spdif_config & YES_IN_NO_OUT) + ice->total_input_channels += 2; + + //Write bits in the GPIO + write_cci_uint8(ice, CCI_GPIO_WRITE_MASK, ~(ice->gpio_cs_mask)); + //Deselect CS + write_cci_uint8(ice, CCI_GPIO_DATA, ice->gpio_cs_mask); + + //Just to route input to output +// write_mt_uint16(ice, MT_ROUTING_CONTROL_PSDOUT, 0x0101); +// write_mt_uint32(ice, MT_CAPTURED_DATA, 0x0000); + + //Unmask Interrupt + write_ccs_uint8(ice, CCS_CONTROL_STATUS, 0x41); + + reg8 = read_ccs_uint8(ice, CCS_INTERRUPT_MASK); + TRACE_ICE(("-----CCS----- = %x\n", reg8)); + write_ccs_uint8(ice, CCS_INTERRUPT_MASK, 0x6F); + +/* reg16 = read_ds_uint16(ice, DS_DMA_INT_MASK); + TRACE_ICE(("-----DS_DMA----- = %x\n", reg16)); + write_ds_uint16(ice, DS_DMA_INT_MASK, 0x0000); +*/ + reg8 = read_mt_uint8(ice, MT_DMA_INT_MASK_STATUS); + TRACE_ICE(("-----MT_DMA----- = %x\n", reg8)); + write_mt_uint8(ice, MT_DMA_INT_MASK_STATUS, 0x00); + + return B_OK; +}; + + +status_t +init_driver(void) +{ + int i = 0; + num_cards = 0; + + TRACE_ICE(("===init_driver()===\n")); + + if (get_module(pci_name, (module_info **)&pci)) + return ENOSYS; + + if (get_module(mpu401_name, (module_info **) &mpu401)) { + put_module(pci_name); + return ENOSYS; + } + + while ((*pci->get_nth_pci_info)(i, &cards[num_cards].info) == B_OK) + {//TODO check other Vendor_ID and DEVICE_ID + if ((cards[num_cards].info.vendor_id == ICE1712_VENDOR_ID) && + (cards[num_cards].info.device_id == ICE1712_DEVICE_ID)) + { + if (num_cards == NUM_CARDS) + { + TRACE_ICE(("Too many ice1712 cards installed!\n")); + break; + } + + if (ice1712_setup(&cards[num_cards]) != B_OK) + //Vendor_ID and Device_ID has been modified + { + TRACE_ICE(("Setup of ice1712 %d failed\n", num_cards + 1)); + } + else + { + num_cards++; + } + } + i++; + } + + TRACE_ICE(("Number of succesfully initialised card : %d\n", num_cards)); + + if (num_cards == 0) { + put_module(pci_name); + put_module(mpu401_name); + return ENODEV; + } + return B_OK; +} + + +static void +ice_1712_shutdown(ice1712 *ice) +{ + long result_l; + + result_l = remove_io_interrupt_handler(ice->irq, ice_1712_int, ice); + if (result_l == B_OK) + TRACE_ICE(("remove Interrupt result == B_OK\n")); + else + TRACE_ICE(("remove Interrupt result != B_OK\n")); + + if (ice->mem_id_pb != B_ERROR) + delete_area(ice->mem_id_pb); + + if (ice->mem_id_rec != B_ERROR) + delete_area(ice->mem_id_rec); + + codec_write(ice, AK45xx_RESET_REGISTER, 0x00); +} + + +void +uninit_driver(void) +{ + int ix, cnt = num_cards; + + TRACE_ICE(("===uninit_driver()===\n")); + + num_cards = 0; + + for (ix = 0; ix < cnt; ix++) { + ice_1712_shutdown(&cards[ix]); + } + memset(&cards, 0, sizeof(cards)); + put_module(mpu401_name); + put_module(pci_name); +} + +//------------------------------------------------------ + +const char ** +publish_devices(void) +{ + int ix = 0; + TRACE_ICE(("===publish_devices()===\n")); + + for (ix=0; names[ix]; ix++) { + TRACE_ICE(("publish %s\n", names[ix])); + } + return (const char **)names; +} + + +static status_t +ice_1712_open(const char *name, uint32 flags, void **cookie) +{//Not Implemented (partialy only) + TRACE_ICE(("===open()===\n")); + *cookie = cards; + return B_OK; +} + + +static status_t +ice_1712_close(void *cookie) +{ + TRACE_ICE(("===close()===\n")); + return B_ERROR; +} + + +static status_t +ice_1712_free(void *cookie) +{ + TRACE_ICE(("===free()===\n")); + return B_ERROR; +} + + +static status_t +ice_1712_control(void *cookie, uint32 op, void *arg, size_t len) +{ + switch (op) + { + case B_MULTI_GET_DESCRIPTION : + TRACE_ICE(("B_MULTI_GET_DESCRIPTION\n")); + return ice1712_get_description((ice1712 *)cookie, (multi_description*)arg); + case B_MULTI_GET_EVENT_INFO : + TRACE_ICE(("B_MULTI_GET_EVENT_INFO\n")); + return B_ERROR; + case B_MULTI_SET_EVENT_INFO : + TRACE_ICE(("B_MULTI_SET_EVENT_INFO\n")); + return B_ERROR; + case B_MULTI_GET_EVENT : + TRACE_ICE(("B_MULTI_GET_EVENT\n")); + return B_ERROR; + case B_MULTI_GET_ENABLED_CHANNELS : + TRACE_ICE(("B_MULTI_GET_ENABLED_CHANNELS\n")); + return ice1712_get_enabled_channels((ice1712*)cookie, (multi_channel_enable*)arg); + case B_MULTI_SET_ENABLED_CHANNELS : + TRACE_ICE(("B_MULTI_SET_ENABLED_CHANNELS\n")); + return ice1712_set_enabled_channels((ice1712*)cookie, (multi_channel_enable*)arg); + case B_MULTI_GET_GLOBAL_FORMAT : + TRACE_ICE(("B_MULTI_GET_GLOBAL_FORMAT\n")); + return ice1712_get_global_format((ice1712*)cookie, (multi_format_info *)arg); + case B_MULTI_SET_GLOBAL_FORMAT : + TRACE_ICE(("B_MULTI_SET_GLOBAL_FORMAT\n")); + return ice1712_set_global_format((ice1712*)cookie, (multi_format_info *)arg); + case B_MULTI_GET_CHANNEL_FORMATS : + TRACE_ICE(("B_MULTI_GET_CHANNEL_FORMATS\n")); + return B_ERROR; + case B_MULTI_SET_CHANNEL_FORMATS : + TRACE_ICE(("B_MULTI_SET_CHANNEL_FORMATS\n")); + return B_ERROR; + case B_MULTI_GET_MIX : + TRACE_ICE(("B_MULTI_GET_MIX\n")); + return ice1712_get_mix((ice1712*)cookie, (multi_mix_value_info *)arg); + case B_MULTI_SET_MIX : + TRACE_ICE(("B_MULTI_SET_MIX\n")); + return ice1712_set_mix((ice1712*)cookie, (multi_mix_value_info *)arg); + case B_MULTI_LIST_MIX_CHANNELS : + TRACE_ICE(("B_MULTI_LIST_MIX_CHANNELS\n")); + return ice1712_list_mix_channels((ice1712*)cookie, (multi_mix_channel_info *)arg); + case B_MULTI_LIST_MIX_CONTROLS : + TRACE_ICE(("B_MULTI_LIST_MIX_CONTROLS\n")); + return ice1712_list_mix_controls((ice1712*)cookie, (multi_mix_control_info *)arg); + case B_MULTI_LIST_MIX_CONNECTIONS : + TRACE_ICE(("B_MULTI_LIST_MIX_CONNECTIONS\n")); + return ice1712_list_mix_connections((ice1712*)cookie, (multi_mix_connection_info *)arg); + case B_MULTI_GET_BUFFERS : + TRACE_ICE(("B_MULTI_GET_BUFFERS\n")); + return ice1712_get_buffers((ice1712*)cookie, (multi_buffer_list*)arg); + case B_MULTI_SET_BUFFERS : + TRACE_ICE(("B_MULTI_SET_BUFFERS\n")); + return B_ERROR; + case B_MULTI_SET_START_TIME : + TRACE_ICE(("B_MULTI_SET_START_TIME\n")); + return B_ERROR; + case B_MULTI_BUFFER_EXCHANGE : +// TRACE_ICE(("B_MULTI_BUFFER_EXCHANGE\n")); + return ice1712_buffer_exchange((ice1712*)cookie, (multi_buffer_info *)arg); + case B_MULTI_BUFFER_FORCE_STOP : + TRACE_ICE(("B_MULTI_BUFFER_FORCE_STOP\n")); + return ice1712_buffer_force_stop((ice1712*)cookie); + case B_MULTI_LIST_EXTENSIONS : + TRACE_ICE(("B_MULTI_LIST_EXTENSIONS\n")); + return B_ERROR; + case B_MULTI_GET_EXTENSION : + TRACE_ICE(("B_MULTI_GET_EXTENSION\n")); + return B_ERROR; + case B_MULTI_SET_EXTENSION : + TRACE_ICE(("B_MULTI_SET_EXTENSION\n")); + return B_ERROR; + case B_MULTI_LIST_MODES : + TRACE_ICE(("B_MULTI_LIST_MODES\n")); + return B_ERROR; + case B_MULTI_GET_MODE : + TRACE_ICE(("B_MULTI_GET_MODE\n")); + return B_ERROR; + case B_MULTI_SET_MODE : + TRACE_ICE(("B_MULTI_SET_MODE\n")); + return B_ERROR; + + default : + TRACE_ICE(("ERROR: unknown multi_control %#x\n", op)); + return B_ERROR; + } +} + + +static status_t +ice_1712_read(void *cookie, off_t position, void *buf, size_t *num_bytes) +{ + TRACE_ICE(("===read()===\n")); + *num_bytes = 0; + return B_IO_ERROR; +} + + +static status_t +ice_1712_write(void *cookie, off_t position, const void *buffer, size_t *num_bytes) +{ + TRACE_ICE(("===write()===\n")); + *num_bytes = 0; + return B_IO_ERROR; +} + + +device_hooks ice_1712_hooks = +{ + ice_1712_open, + ice_1712_close, + ice_1712_free, + ice_1712_control, + ice_1712_read, + ice_1712_write, + NULL, + NULL, + NULL, + NULL +}; + + +device_hooks * +find_device(const char * name) +{ + int ix; + + PRINT_ICE(("ice1712: find_device(%s)\n", name)); + + for (ix=0; ix + +#define DRIVER_NAME "ice1712" +#define VERSION "0.3" + +#define ICE1712_VENDOR_ID 0x1412 +#define ICE1712_DEVICE_ID 0x1712 + + +typedef enum product_t { + ICE1712_SUBDEVICE_DELTA1010 = 0x121430d6, + ICE1712_SUBDEVICE_DELTADIO2496 = 0x121431d6, + ICE1712_SUBDEVICE_DELTA66 = 0x121432d6, + ICE1712_SUBDEVICE_DELTA44 = 0x121433d6, + ICE1712_SUBDEVICE_AUDIOPHILE_2496 = 0x121434d6, + ICE1712_SUBDEVICE_DELTA410 = 0x121438d6, + ICE1712_SUBDEVICE_DELTA1010LT = 0x12143bd6, + ICE1712_SUBDEVICE_VX442 = 0x12143cd6, +} product_t; + +#define NUM_CARDS 4 +#define MAX_ADC 12 // + the output of the Digital mixer +#define MAX_DAC 10 +#define SWAPPING_BUFFERS 2 +#define SAMPLE_SIZE 4 +#define MIN_BUFFER_FRAMES 64 +#define MAX_BUFFER_FRAMES 2048 + +#define PLAYBACK_BUFFER_SIZE (MAX_BUFFER_FRAMES * MAX_DAC * SAMPLE_SIZE) +#define RECORD_BUFFER_SIZE (MAX_BUFFER_FRAMES * MAX_ADC * SAMPLE_SIZE) + +#define PLAYBACK_BUFFER_TOTAL_SIZE (PLAYBACK_BUFFER_SIZE * SWAPPING_BUFFERS) +#define RECORD_BUFFER_TOTAL_SIZE (RECORD_BUFFER_SIZE * SWAPPING_BUFFERS) + +#define SPDIF_LEFT 8 +#define SPDIF_RIGHT 9 +#define MIXER_OUT_LEFT 10 +#define MIXER_OUT_RIGHT 11 + +typedef enum { + NO_IN_NO_OUT = 0, + NO_IN_YES_OUT = 1, + YES_IN_NO_OUT = 2, + YES_IN_YES_OUT = 3, +} _spdif_config_ ; + +typedef struct _midi_dev { + struct _ice1712_ *card; + void *driver; + void *cookie; + int32 count; + char name[64]; +} midi_dev; + +typedef struct codec_info +{ + uint8 clock; + uint8 data_in; + uint8 data_out; + uint8 reserved[5]; +} codec_info; + +typedef struct _ice1712_ +{ + uint32 irq; + pci_info info; + char name[128]; + + midi_dev midi_interf[2]; + + uint32 Controller; //PCI_10 + uint32 DDMA; //PCI_14 + uint32 DMA_Path; //PCI_18 + uint32 Multi_Track; //PCI_1C + + int8 nb_ADC; //Mono Channel + int8 nb_DAC; //Mono Channel + _spdif_config_ spdif_config; + int8 nb_MPU401; + + product_t product; + uint8 gpio_cs_mask; //a Mask for removing all Chip select + + //We hope all manufacturer will not use different codec on the same card + codec_info analog_codec; + codec_info digital_codec; + + uint32 buffer; + bigtime_t played_time; + + //Output + area_id mem_id_pb; + void *phys_addr_pb, *log_addr_pb; + uint32 output_buffer_size; //in frames + uint8 total_output_channels; + + //Input + area_id mem_id_rec; + void *phys_addr_rec, *log_addr_rec; + uint32 input_buffer_size; //in frames + uint8 total_input_channels; + + sem_id buffer_ready_sem; + + uint8 sampling_rate; //in the format of the register + +} ice1712; + +extern int32 num_cards; +extern ice1712 cards[NUM_CARDS]; + +//??????? +#define GPIO_SPDIF_STATUS 0x02 //Status +#define GPIO_SPDIF_CCLK 0x04 //data Clock +#define GPIO_SPDIF_DOUT 0x08 //data output + +//For Delta 66 / Delta 44 +#define DELTA66_DOUT 0x10 // data output +#define DELTA66_CLK 0x20 // clock +#define DELTA66_CODEC_CS_0 0x40 // AK4524 #0 +#define DELTA66_CODEC_CS_1 0x80 // AK4524 #1 + +//For AudioPhile 2496 / Delta 410 +#define AP2496_CLK 0x02 // clock +#define AP2496_DIN 0x04 // data input +#define AP2496_DOUT 0x08 // data output +#define AP2496_SPDIF_CS 0x10 // CS8427 chip select +#define AP2496_CODEC_CS 0x20 // AK4528 chip select + +//For Delta 1010 LT +#define DELTA1010LT_CLK 0x02 // clock +#define DELTA1010LT_DIN 0x04 // data input +#define DELTA1010LT_DOUT 0x08 // data output +#define DELTA1010LT_CODEC_CS_0 0x00 // AK4524 #0 +#define DELTA1010LT_CODEC_CS_1 0x10 // AK4524 #1 +#define DELTA1010LT_CODEC_CS_2 0x20 // AK4524 #2 +#define DELTA1010LT_CODEC_CS_3 0x30 // AK4524 #3 +#define DELTA1010LT_SPDIF_CS 0x40 // CS8427 +#define DELTA1010LT_CS_NONE 0x50 // All CS deselected + +//For VX442 +#define VX442_CLK 0x02 // clock +#define VX442_DIN 0x04 // data input +#define VX442_DOUT 0x08 // data output +#define VX442_SPDIF_CS 0x10 // CS8427 +#define VX442_CODEC_CS_0 0x20 // ?? #0 +#define VX442_CODEC_CS_1 0x40 // ?? #1 + +#define AK45xx_BITS_TO_WRITE 16 +//2 - Chip Address (10b) +//1 - R/W (Always 1 for Writing) +//5 - Register Address +//8 - Data + +//Register definition for the AK45xx codec (xx = 24 or 28) +#define AK45xx_DELAY 100 //Clock Delay +#define AK45xx_CHIP_ADDRESS 0x02 //Chip address of the codec +#define AK45xx_RESET_REGISTER 0x01 +#define AK45xx_CLOCK_FORMAT_REGISTER 0x02 +//Other register are not defined cause they are not used, I'm very lazy... + +#define CS84xx_BITS_TO_WRITE 24 +//7 - Chip Address (0010000b) +//1 - R/W (1 for Reading) +//8 - Register MAP +//8 - Data + +//Register definition for the CS84xx codec (xx = 27) +#define CS84xx_DELAY 100 //Clock Delay +#define CS84xx_CHIP_ADDRESS 0x10 //Chip address of the codec +#define CS84xx_CONTROL_1_PORT_REG 0x01 +#define CS84xx_CONTROL_2_PORT_REG 0x02 +#define CS84xx_DATA_FLOW_CONTROL_REG 0x03 +#define CS84xx_CLOCK_SOURCE_REG 0x04 +#define CS84xx_SERIAL_INPUT_FORMAT_REG 0x05 +#define CS84xx_SERIAL_OUTPUT_FORMAT_REG 0x06 +//Other register are not defined cause they are not used, I'm very lazy... + + +/* A default switch for all suported product + switch (card->product) + { + case ICE1712_SUBDEVICE_DELTA1010 : + break; + case ICE1712_SUBDEVICE_DELTADIO2496 : + break; + case ICE1712_SUBDEVICE_DELTA66 : + break; + case ICE1712_SUBDEVICE_DELTA44 : + break; + case ICE1712_SUBDEVICE_AUDIOPHILE : + break; + case ICE1712_SUBDEVICE_DELTA410 : + break; + case ICE1712_SUBDEVICE_DELTA1010LT : + break; + case ICE1712_SUBDEVICE_VX442 : + break; + } +*/ + +#endif Added: haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/ice1712_reg.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/ice1712_reg.h 2007-10-06 13:14:11 UTC (rev 22457) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/ice1712_reg.h 2007-10-06 13:45:16 UTC (rev 22458) @@ -0,0 +1,167 @@ +/* + * ice1712 BeOS/Haiku Driver for VIA - VT1712 Multi Channel Audio Controller + * + * Copyright (c) 2007, Jerome Leveque (leveque.jerome at neuf.fr) + * + * All rights reserved + * Distributed under the terms of the MIT license. + */ + +#ifndef _ICE1712_REG_H_ +#define _ICE1712_REG_H_ + [... truncated: 1646 lines follow ...] From korli at mail.berlios.de Sat Oct 6 16:04:09 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Sat, 6 Oct 2007 16:04:09 +0200 Subject: [Haiku-commits] r22459 - haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712 Message-ID: <200710061404.l96E49lS005767@sheep.berlios.de> Author: korli Date: 2007-10-06 16:04:09 +0200 (Sat, 06 Oct 2007) New Revision: 22459 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22459&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/ice1712.c Log: clean up Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/ice1712.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/ice1712.c 2007-10-06 13:45:16 UTC (rev 22458) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/ice1712/ice1712.c 2007-10-06 14:04:09 UTC (rev 22459) @@ -44,9 +44,7 @@ //------------------------------------------------------ -static char pci_name[] = B_PCI_MODULE_NAME; pci_module_info *pci; -static char mpu401_name[] = B_MPU_401_MODULE_NAME; generic_mpu401_module *mpu401; int32 num_cards = 0; @@ -59,7 +57,7 @@ int32 api_version = B_CUR_DRIVER_API_VERSION; -#define MODULE_TEST_PATH "audio/multi/ice1712" +#define MODULE_TEST_PATH "audio/hmulti/ice1712" //------------------------------------------------------ //------------------------------------------------------ @@ -81,20 +79,20 @@ LOG_CREATE_ICE(); TRACE_ICE(("===init_hardware()===\n")); - if (get_module(pci_name, (module_info **)&pci)) + if (get_module(B_PCI_MODULE_NAME, (module_info **)&pci)) return ENOSYS; while ((*pci->get_nth_pci_info)(ix, &info) == B_OK) { if ((info.vendor_id == ICE1712_VENDOR_ID) && (info.device_id == ICE1712_DEVICE_ID)) { TRACE_ICE(("Found at least 1 card\n")); - put_module(pci_name); + put_module(B_PCI_MODULE_NAME); return B_OK; } ix++; } - put_module(pci_name); - return B_ERROR; + put_module(B_PCI_MODULE_NAME); + return ENODEV; } @@ -308,11 +306,11 @@ TRACE_ICE(("===init_driver()===\n")); - if (get_module(pci_name, (module_info **)&pci)) + if (get_module(B_PCI_MODULE_NAME, (module_info **)&pci)) return ENOSYS; - if (get_module(mpu401_name, (module_info **) &mpu401)) { - put_module(pci_name); + if (get_module(B_MPU_401_MODULE_NAME, (module_info **) &mpu401)) { + put_module(B_PCI_MODULE_NAME); return ENOSYS; } @@ -343,8 +341,8 @@ TRACE_ICE(("Number of succesfully initialised card : %d\n", num_cards)); if (num_cards == 0) { - put_module(pci_name); - put_module(mpu401_name); + put_module(B_PCI_MODULE_NAME); + put_module(B_MPU_401_MODULE_NAME); return ENODEV; } return B_OK; @@ -385,8 +383,8 @@ ice_1712_shutdown(&cards[ix]); } memset(&cards, 0, sizeof(cards)); - put_module(mpu401_name); - put_module(pci_name); + put_module(B_MPU_401_MODULE_NAME); + put_module(B_PCI_MODULE_NAME); } //------------------------------------------------------ From korli at mail.berlios.de Sat Oct 6 16:11:25 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Sat, 6 Oct 2007 16:11:25 +0200 Subject: [Haiku-commits] r22460 - in haiku/trunk/src/add-ons/kernel/drivers: audio/hda random Message-ID: <200710061411.l96EBPa9006123@sheep.berlios.de> Author: korli Date: 2007-10-06 16:11:25 +0200 (Sat, 06 Oct 2007) New Revision: 22460 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22460&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h haiku/trunk/src/add-ons/kernel/drivers/random/driver.c Log: switch from COMPILE_FOR_R5 to HAIKU_TARGET_PLATFORM_HAIKU Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h 2007-10-06 14:04:09 UTC (rev 22459) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h 2007-10-06 14:11:25 UTC (rev 22460) @@ -8,7 +8,7 @@ #include #include -#ifdef COMPILE_FOR_R5 +#ifndef HAIKU_TARGET_PLATFORM_HAIKU #define DEVFS_PATH_FORMAT "audio/multi/hda/%lu" #include #else Modified: haiku/trunk/src/add-ons/kernel/drivers/random/driver.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/random/driver.c 2007-10-06 14:04:09 UTC (rev 22459) +++ haiku/trunk/src/add-ons/kernel/drivers/random/driver.c 2007-10-06 14:11:25 UTC (rev 22460) @@ -463,7 +463,7 @@ if (event == B_SELECT_READ) { /* tell there is already data to read */ -#ifdef COMPILE_FOR_R5 +#ifndef HAIKU_TARGET_PLATFORM_HAIKU notify_select_event(sync, ref); #else notify_select_event(sync, event); From axeld at mail.berlios.de Sat Oct 6 17:33:14 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sat, 6 Oct 2007 17:33:14 +0200 Subject: [Haiku-commits] r22461 - in haiku/trunk: headers/private/kernel src/system/kernel src/system/kernel/cache src/system/kernel/fs src/system/kernel/vm Message-ID: <200710061533.l96FXE0Y010384@sheep.berlios.de> Author: axeld Date: 2007-10-06 17:33:12 +0200 (Sat, 06 Oct 2007) New Revision: 22461 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22461&view=rev Modified: haiku/trunk/headers/private/kernel/elf_priv.h haiku/trunk/headers/private/kernel/file_cache.h haiku/trunk/headers/private/kernel/vfs.h haiku/trunk/src/system/kernel/cache/file_cache.cpp haiku/trunk/src/system/kernel/elf.cpp haiku/trunk/src/system/kernel/fs/vfs.cpp haiku/trunk/src/system/kernel/vm/vm.cpp Log: * struct vnode is an opaque type now, removed void* where it was used incorrectly. * Minor cleanup. Modified: haiku/trunk/headers/private/kernel/elf_priv.h =================================================================== --- haiku/trunk/headers/private/kernel/elf_priv.h 2007-10-06 14:11:25 UTC (rev 22460) +++ haiku/trunk/headers/private/kernel/elf_priv.h 2007-10-06 15:33:12 UTC (rev 22461) @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006, Haiku Inc. All Rights Reserved. + * Copyright 2002-2007, Haiku Inc. All Rights Reserved. * Distributed under the terms of the MIT license. * * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. @@ -25,7 +25,7 @@ char *name; image_id id; int32 ref_count; - void *vnode; + struct vnode *vnode; elf_region text_region; elf_region data_region; addr_t dynamic_section; // pointer to the dynamic section Modified: haiku/trunk/headers/private/kernel/file_cache.h =================================================================== --- haiku/trunk/headers/private/kernel/file_cache.h 2007-10-06 14:11:25 UTC (rev 22460) +++ haiku/trunk/headers/private/kernel/file_cache.h 2007-10-06 15:33:12 UTC (rev 22461) @@ -26,10 +26,10 @@ struct cache_module_info { module_info info; - void (*node_opened)(void *vnode, int32 fdType, dev_t mountID, ino_t parentID, - ino_t vnodeID, const char *name, off_t size); - void (*node_closed)(void *vnode, int32 fdType, dev_t mountID, ino_t vnodeID, - int32 accessType); + void (*node_opened)(struct vnode *vnode, int32 fdType, dev_t mountID, + ino_t parentID, ino_t vnodeID, const char *name, off_t size); + void (*node_closed)(struct vnode *vnode, int32 fdType, dev_t mountID, + ino_t vnodeID, int32 accessType); void (*node_launched)(size_t argCount, char * const *args); }; @@ -37,12 +37,12 @@ extern "C" { #endif -extern void cache_node_opened(void *vnode, int32 fdType, vm_cache *cache, +extern void cache_node_opened(struct vnode *vnode, int32 fdType, vm_cache *cache, dev_t mountID, ino_t parentID, ino_t vnodeID, const char *name); -extern void cache_node_closed(void *vnode, int32 fdType, vm_cache *cache, +extern void cache_node_closed(struct vnode *vnode, int32 fdType, vm_cache *cache, dev_t mountID, ino_t vnodeID); extern void cache_node_launched(size_t argCount, char * const *args); -extern void cache_prefetch_vnode(void *vnode, off_t offset, size_t size); +extern void cache_prefetch_vnode(struct vnode *vnode, off_t offset, size_t size); extern void cache_prefetch(dev_t mountID, ino_t vnodeID, off_t offset, size_t size); extern status_t file_cache_init_post_boot_device(void); extern status_t file_cache_init(void); Modified: haiku/trunk/headers/private/kernel/vfs.h =================================================================== --- haiku/trunk/headers/private/kernel/vfs.h 2007-10-06 14:11:25 UTC (rev 22460) +++ haiku/trunk/headers/private/kernel/vfs.h 2007-10-06 15:33:12 UTC (rev 22461) @@ -78,32 +78,34 @@ int vfs_setrlimit(int resource, const struct rlimit * rlp); /* calls needed by the VM for paging and by the file cache */ -int vfs_get_vnode_from_fd(int fd, bool kernel, void **vnode); -status_t vfs_get_vnode_from_path(const char *path, bool kernel, void **vnode); -status_t vfs_get_vnode(dev_t mountID, ino_t vnodeID, void **_vnode); +int vfs_get_vnode_from_fd(int fd, bool kernel, struct vnode **_vnode); +status_t vfs_get_vnode_from_path(const char *path, bool kernel, + struct vnode **_vnode); +status_t vfs_get_vnode(dev_t mountID, ino_t vnodeID, struct vnode **_vnode); status_t vfs_entry_ref_to_vnode(dev_t mountID, ino_t directoryID, - const char *name, void **_vnode); -void vfs_vnode_to_node_ref(void *_vnode, dev_t *_mountID, ino_t *_vnodeID); + const char *name, struct vnode **_vnode); +void vfs_vnode_to_node_ref(struct vnode *vnode, dev_t *_mountID, + ino_t *_vnodeID); -status_t vfs_lookup_vnode(dev_t mountID, ino_t vnodeID, void **_vnode); -void vfs_put_vnode(void *vnode); -void vfs_acquire_vnode(void *vnode); +status_t vfs_lookup_vnode(dev_t mountID, ino_t vnodeID, struct vnode **_vnode); +void vfs_put_vnode(struct vnode *vnode); +void vfs_acquire_vnode(struct vnode *vnode); status_t vfs_get_cookie_from_fd(int fd, void **_cookie); -bool vfs_can_page(void *vnode, void *cookie); -status_t vfs_read_pages(void *vnode, void *cookie, off_t pos, +bool vfs_can_page(struct vnode *vnode, void *cookie); +status_t vfs_read_pages(struct vnode *vnode, void *cookie, off_t pos, const iovec *vecs, size_t count, size_t *_numBytes, bool mayBlock, bool fsReenter); -status_t vfs_write_pages(void *vnode, void *cookie, off_t pos, +status_t vfs_write_pages(struct vnode *vnode, void *cookie, off_t pos, const iovec *vecs, size_t count, size_t *_numBytes, bool mayBlock, bool fsReenter); -status_t vfs_get_vnode_cache(void *vnode, struct vm_cache **_cache, +status_t vfs_get_vnode_cache(struct vnode *vnode, struct vm_cache **_cache, bool allocate); -status_t vfs_get_file_map( void *_vnode, off_t offset, size_t size, +status_t vfs_get_file_map(struct vnode *vnode, off_t offset, size_t size, struct file_io_vec *vecs, size_t *_count); status_t vfs_get_fs_node_from_path(dev_t mountID, const char *path, bool kernel, void **_node); -status_t vfs_stat_vnode(void *_vnode, struct stat *stat); -status_t vfs_get_vnode_name(void *vnode, char *name, size_t nameSize); +status_t vfs_stat_vnode(struct vnode *vnode, struct stat *stat); +status_t vfs_get_vnode_name(struct vnode *vnode, char *name, size_t nameSize); status_t vfs_get_cwd(dev_t *_mountID, ino_t *_vnodeID); void vfs_unlock_vnode_if_locked(struct file_descriptor *descriptor); status_t vfs_disconnect_vnode(dev_t mountID, ino_t vnodeID); Modified: haiku/trunk/src/system/kernel/cache/file_cache.cpp =================================================================== --- haiku/trunk/src/system/kernel/cache/file_cache.cpp 2007-10-06 14:11:25 UTC (rev 22460) +++ haiku/trunk/src/system/kernel/cache/file_cache.cpp 2007-10-06 15:33:12 UTC (rev 22461) @@ -62,8 +62,8 @@ struct file_cache_ref { vm_cache *cache; - void *vnode; - void *device; + struct vnode *vnode; + struct vnode *device; void *cookie; file_map map; }; @@ -1063,7 +1063,7 @@ extern "C" void -cache_prefetch_vnode(void *vnode, off_t offset, size_t size) +cache_prefetch_vnode(struct vnode *vnode, off_t offset, size_t size) { vm_cache *cache; if (vfs_get_vnode_cache(vnode, &cache, false) != B_OK) @@ -1137,13 +1137,12 @@ extern "C" void cache_prefetch(dev_t mountID, ino_t vnodeID, off_t offset, size_t size) { - void *vnode; - // ToDo: schedule prefetch TRACE(("cache_prefetch(vnode %ld:%Ld)\n", mountID, vnodeID)); // get the vnode for the object, this also grabs a ref to it + struct vnode *vnode; if (vfs_get_vnode(mountID, vnodeID, &vnode) != B_OK) return; @@ -1153,8 +1152,8 @@ extern "C" void -cache_node_opened(void *vnode, int32 fdType, vm_cache *cache, dev_t mountID, - ino_t parentID, ino_t vnodeID, const char *name) +cache_node_opened(struct vnode *vnode, int32 fdType, vm_cache *cache, + dev_t mountID, ino_t parentID, ino_t vnodeID, const char *name) { if (sCacheModule == NULL || sCacheModule->node_opened == NULL) return; @@ -1173,7 +1172,7 @@ extern "C" void -cache_node_closed(void *vnode, int32 fdType, vm_cache *cache, +cache_node_closed(struct vnode *vnode, int32 fdType, vm_cache *cache, dev_t mountID, ino_t vnodeID) { if (sCacheModule == NULL || sCacheModule->node_closed == NULL) Modified: haiku/trunk/src/system/kernel/elf.cpp =================================================================== --- haiku/trunk/src/system/kernel/elf.cpp 2007-10-06 14:11:25 UTC (rev 22460) +++ haiku/trunk/src/system/kernel/elf.cpp 2007-10-06 15:33:12 UTC (rev 22461) @@ -1193,20 +1193,19 @@ struct Elf32_Ehdr *elfHeader; struct elf_image_info *image; const char *fileName; - void *vnode = NULL; void *reservedAddress; addr_t start; size_t reservedSize; status_t status; - int fd; ssize_t length; TRACE(("elf_load_kspace: entry path '%s'\n", path)); - fd = _kern_open(-1, path, O_RDONLY, 0); + int fd = _kern_open(-1, path, O_RDONLY, 0); if (fd < 0) return fd; + struct vnode *vnode; status = vfs_get_vnode_from_fd(fd, true, &vnode); if (status < B_OK) goto error0; Modified: haiku/trunk/src/system/kernel/fs/vfs.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/vfs.cpp 2007-10-06 14:11:25 UTC (rev 22460) +++ haiku/trunk/src/system/kernel/fs/vfs.cpp 2007-10-06 15:33:12 UTC (rev 22461) @@ -91,7 +91,7 @@ #define FS_CALL(vnode, op) (vnode->mount->fs->op) #define FS_MOUNT_CALL(mount, op) (mount->fs->op) -/** \brief Structure to manage a mounted file system +/*! \brief Structure to manage a mounted file system Note: The root_vnode and covers_vnode fields (what others?) are initialized in fs_mount() and not changed afterwards. That is as soon @@ -102,7 +102,7 @@ making the access path vnode->mount->covers_vnode->mount->... safe if a reference to vnode is held (note that for the root mount covers_vnode is NULL, though). - */ +*/ struct fs_mount { struct fs_mount *next; file_system_module_info *fs; @@ -455,10 +455,9 @@ } -/** Finds the mounted device (the fs_mount structure) with the given ID. - * Note, you must hold the gMountMutex lock when you call this function. - */ - +/*! Finds the mounted device (the fs_mount structure) with the given ID. + Note, you must hold the gMountMutex lock when you call this function. +*/ static struct fs_mount * find_mount(dev_t id) { @@ -508,12 +507,11 @@ } -/** Tries to open the specified file system module. - * Accepts a file system name of the form "bfs" or "file_systems/bfs/v1". - * Returns a pointer to file system module interface, or NULL if it - * could not open the module. - */ - +/*! Tries to open the specified file system module. + Accepts a file system name of the form "bfs" or "file_systems/bfs/v1". + Returns a pointer to file system module interface, or NULL if it + could not open the module. +*/ static file_system_module_info * get_file_system(const char *fsName) { @@ -533,13 +531,12 @@ } -/** Accepts a file system name of the form "bfs" or "file_systems/bfs/v1" - * and returns a compatible fs_info.fsh_name name ("bfs" in both cases). - * The name is allocated for you, and you have to free() it when you're - * done with it. - * Returns NULL if the required memory is no available. - */ - +/*! Accepts a file system name of the form "bfs" or "file_systems/bfs/v1" + and returns a compatible fs_info.fsh_name name ("bfs" in both cases). + The name is allocated for you, and you have to free() it when you're + done with it. + Returns NULL if the required memory is no available. +*/ static char * get_file_system_name(const char *fsName) { @@ -656,11 +653,10 @@ } -/** Frees the vnode and all resources it has acquired, and removes - * it from the vnode hash as well as from its mount structure. - * Will also make sure that any cache modifications are written back. - */ - +/*! Frees the vnode and all resources it has acquired, and removes + it from the vnode hash as well as from its mount structure. + Will also make sure that any cache modifications are written back. +*/ static void free_vnode(struct vnode *vnode, bool reenter) { @@ -719,19 +715,18 @@ } -/** \brief Decrements the reference counter of the given vnode and deletes it, - * if the counter dropped to 0. - * - * The caller must, of course, own a reference to the vnode to call this - * function. - * The caller must not hold the sVnodeMutex or the sMountMutex. - * - * \param vnode the vnode. - * \param reenter \c true, if this function is called (indirectly) from within - * a file system. - * \return \c B_OK, if everything went fine, an error code otherwise. - */ +/*! \brief Decrements the reference counter of the given vnode and deletes it, + if the counter dropped to 0. + The caller must, of course, own a reference to the vnode to call this + function. + The caller must not hold the sVnodeMutex or the sMountMutex. + + \param vnode the vnode. + \param reenter \c true, if this function is called (indirectly) from within + a file system. + \return \c B_OK, if everything went fine, an error code otherwise. +*/ static status_t dec_vnode_ref_count(struct vnode *vnode, bool reenter) { @@ -778,14 +773,13 @@ } -/** \brief Increments the reference counter of the given vnode. - * - * The caller must either already have a reference to the vnode or hold - * the sVnodeMutex. - * - * \param vnode the vnode. - */ +/*! \brief Increments the reference counter of the given vnode. + The caller must either already have a reference to the vnode or hold + the sVnodeMutex. + + \param vnode the vnode. +*/ static void inc_vnode_ref_count(struct vnode *vnode) { @@ -794,17 +788,16 @@ } -/** \brief Looks up a vnode by mount and node ID in the sVnodeTable. - * - * The caller must hold the sVnodeMutex. - * - * \param mountID the mount ID. - * \param vnodeID the node ID. - * - * \return The vnode structure, if it was found in the hash table, \c NULL - * otherwise. - */ +/*! \brief Looks up a vnode by mount and node ID in the sVnodeTable. + The caller must hold the sVnodeMutex. + + \param mountID the mount ID. + \param vnodeID the node ID. + + \return The vnode structure, if it was found in the hash table, \c NULL + otherwise. +*/ static struct vnode * lookup_vnode(dev_t mountID, ino_t vnodeID) { @@ -817,21 +810,20 @@ } -/** \brief Retrieves a vnode for a given mount ID, node ID pair. - * - * If the node is not yet in memory, it will be loaded. - * - * The caller must not hold the sVnodeMutex or the sMountMutex. - * - * \param mountID the mount ID. - * \param vnodeID the node ID. - * \param _vnode Pointer to a vnode* variable into which the pointer to the - * retrieved vnode structure shall be written. - * \param reenter \c true, if this function is called (indirectly) from within - * a file system. - * \return \c B_OK, if everything when fine, an error code otherwise. - */ +/*! \brief Retrieves a vnode for a given mount ID, node ID pair. + If the node is not yet in memory, it will be loaded. + + The caller must not hold the sVnodeMutex or the sMountMutex. + + \param mountID the mount ID. + \param vnodeID the node ID. + \param _vnode Pointer to a vnode* variable into which the pointer to the + retrieved vnode structure shall be written. + \param reenter \c true, if this function is called (indirectly) from within + a file system. + \return \c B_OK, if everything when fine, an error code otherwise. +*/ static status_t get_vnode(dev_t mountID, ino_t vnodeID, struct vnode **_vnode, int reenter) { @@ -906,16 +898,15 @@ } -/** \brief Decrements the reference counter of the given vnode and deletes it, - * if the counter dropped to 0. - * - * The caller must, of course, own a reference to the vnode to call this - * function. - * The caller must not hold the sVnodeMutex or the sMountMutex. - * - * \param vnode the vnode. - */ +/*! \brief Decrements the reference counter of the given vnode and deletes it, + if the counter dropped to 0. + The caller must, of course, own a reference to the vnode to call this + function. + The caller must not hold the sVnodeMutex or the sMountMutex. + + \param vnode the vnode. +*/ static inline void put_vnode(struct vnode *vnode) { @@ -970,14 +961,13 @@ } -/** Returns the advisory_locking object of the \a vnode in case it - * has one, and locks it. - * You have to call put_advisory_locking() when you're done with - * it. - * Note, you must not have the vnode mutex locked when calling - * this function. - */ - +/*! Returns the advisory_locking object of the \a vnode in case it + has one, and locks it. + You have to call put_advisory_locking() when you're done with + it. + Note, you must not have the vnode mutex locked when calling + this function. +*/ static struct advisory_locking * get_advisory_locking(struct vnode *vnode) { @@ -1001,13 +991,12 @@ } -/** Creates a locked advisory_locking object, and attaches it to the - * given \a vnode. - * Returns B_OK in case of success - also if the vnode got such an - * object from someone else in the mean time, you'll still get this - * one locked then. - */ - +/*! Creates a locked advisory_locking object, and attaches it to the + given \a vnode. + Returns B_OK in case of success - also if the vnode got such an + object from someone else in the mean time, you'll still get this + one locked then. +*/ static status_t create_advisory_locking(struct vnode *vnode) { @@ -1056,8 +1045,8 @@ } -/** Retrieves the first lock that has been set by the current team. - */ +/*! Retrieves the first lock that has been set by the current team. +*/ static status_t get_advisory_lock(struct vnode *vnode, struct flock *flock) @@ -1085,10 +1074,9 @@ } -/** Removes the specified lock, or all locks of the calling team - * if \a flock is NULL. - */ - +/*! Removes the specified lock, or all locks of the calling team + if \a flock is NULL. +*/ static status_t release_advisory_lock(struct vnode *vnode, struct flock *flock) { @@ -1280,18 +1268,17 @@ } -/** Disconnects all file descriptors that are associated with the - * \a vnodeToDisconnect, or if this is NULL, all vnodes of the specified - * \a mount object. - * - * Note, after you've called this function, there might still be ongoing - * accesses - they won't be interrupted if they already happened before. - * However, any subsequent access will fail. - * - * This is not a cheap function and should be used with care and rarely. - * TODO: there is currently no means to stop a blocking read/write! - */ +/*! Disconnects all file descriptors that are associated with the + \a vnodeToDisconnect, or if this is NULL, all vnodes of the specified + \a mount object. + Note, after you've called this function, there might still be ongoing + accesses - they won't be interrupted if they already happened before. + However, any subsequent access will fail. + + This is not a cheap function and should be used with care and rarely. + TODO: there is currently no means to stop a blocking read/write! +*/ void disconnect_mount_or_vnode_fds(struct fs_mount *mount, struct vnode *vnodeToDisconnect) @@ -1379,18 +1366,17 @@ } -/** \brief Resolves a mount point vnode to the volume root vnode it is covered - * by. - * - * Given an arbitrary vnode, the function checks, whether the node is covered - * by the root of a volume. If it is the function obtains a reference to the - * volume root node and returns it. - * - * \param vnode The vnode in question. - * \return The volume root vnode the vnode cover is covered by, if it is - * indeed a mount point, or \c NULL otherwise. - */ +/*! \brief Resolves a mount point vnode to the volume root vnode it is covered + by. + Given an arbitrary vnode, the function checks, whether the node is covered + by the root of a volume. If it is the function obtains a reference to the + volume root node and returns it. + + \param vnode The vnode in question. + \return The volume root vnode the vnode cover is covered by, if it is + indeed a mount point, or \c NULL otherwise. +*/ static struct vnode * resolve_mount_point_to_volume_root(struct vnode *vnode) { @@ -1410,27 +1396,26 @@ } -/** \brief Resolves a mount point vnode to the volume root vnode it is covered - * by. - * - * Given an arbitrary vnode (identified by mount and node ID), the function - * checks, whether the node is covered by the root of a volume. If it is the - * function returns the mount and node ID of the volume root node. Otherwise - * it simply returns the supplied mount and node ID. - * - * In case of error (e.g. the supplied node could not be found) the variables - * for storing the resolved mount and node ID remain untouched and an error - * code is returned. - * - * \param mountID The mount ID of the vnode in question. - * \param nodeID The node ID of the vnode in question. - * \param resolvedMountID Pointer to storage for the resolved mount ID. - * \param resolvedNodeID Pointer to storage for the resolved node ID. - * \return - * - \c B_OK, if everything went fine, - * - another error code, if something went wrong. - */ +/*! \brief Resolves a mount point vnode to the volume root vnode it is covered + by. + Given an arbitrary vnode (identified by mount and node ID), the function + checks, whether the node is covered by the root of a volume. If it is the + function returns the mount and node ID of the volume root node. Otherwise + it simply returns the supplied mount and node ID. + + In case of error (e.g. the supplied node could not be found) the variables + for storing the resolved mount and node ID remain untouched and an error + code is returned. + + \param mountID The mount ID of the vnode in question. + \param nodeID The node ID of the vnode in question. + \param resolvedMountID Pointer to storage for the resolved mount ID. + \param resolvedNodeID Pointer to storage for the resolved node ID. + \return + - \c B_OK, if everything went fine, + - another error code, if something went wrong. +*/ status_t resolve_mount_point_to_volume_root(dev_t mountID, ino_t nodeID, dev_t *resolvedMountID, ino_t *resolvedNodeID) @@ -1458,17 +1443,16 @@ } -/** \brief Resolves a volume root vnode to the underlying mount point vnode. - * - * Given an arbitrary vnode, the function checks, whether the node is the - * root of a volume. If it is (and if it is not "/"), the function obtains - * a reference to the underlying mount point node and returns it. - * - * \param vnode The vnode in question (caller must have a reference). - * \return The mount point vnode the vnode covers, if it is indeed a volume - * root and not "/", or \c NULL otherwise. - */ +/*! \brief Resolves a volume root vnode to the underlying mount point vnode. + Given an arbitrary vnode, the function checks, whether the node is the + root of a volume. If it is (and if it is not "/"), the function obtains + a reference to the underlying mount point node and returns it. + + \param vnode The vnode in question (caller must have a reference). + \return The mount point vnode the vnode covers, if it is indeed a volume + root and not "/", or \c NULL otherwise. +*/ static struct vnode * resolve_volume_root_to_mount_point(struct vnode *vnode) { @@ -1935,22 +1919,21 @@ } -/** Gets the full path to a given directory vnode. - * It uses the fs_get_vnode_name() call to get the name of a vnode; if a - * file system doesn't support this call, it will fall back to iterating - * through the parent directory to get the name of the child. - * - * To protect against circular loops, it supports a maximum tree depth - * of 256 levels. - * - * Note that the path may not be correct the time this function returns! - * It doesn't use any locking to prevent returning the correct path, as - * paths aren't safe anyway: the path to a file can change at any time. - * - * It might be a good idea, though, to check if the returned path exists - * in the calling function (it's not done here because of efficiency) - */ +/*! Gets the full path to a given directory vnode. + It uses the fs_get_vnode_name() call to get the name of a vnode; if a + file system doesn't support this call, it will fall back to iterating + through the parent directory to get the name of the child. + To protect against circular loops, it supports a maximum tree depth + of 256 levels. + + Note that the path may not be correct the time this function returns! + It doesn't use any locking to prevent returning the correct path, as + paths aren't safe anyway: the path to a file can change at any time. + + It might be a good idea, though, to check if the returned path exists + in the calling function (it's not done here because of efficiency) +*/ static status_t dir_vnode_to_path(struct vnode *vnode, char *buffer, size_t bufferSize) { @@ -2721,25 +2704,23 @@ // Functions the VFS exports for other parts of the kernel -/** Acquires another reference to the vnode that has to be released - * by calling vfs_put_vnode(). - */ - +/*! Acquires another reference to the vnode that has to be released + by calling vfs_put_vnode(). +*/ void -vfs_acquire_vnode(void *_vnode) +vfs_acquire_vnode(struct vnode *vnode) { - inc_vnode_ref_count((struct vnode *)_vnode); + inc_vnode_ref_count(vnode); } -/** This is currently called from file_cache_create() only. - * It's probably a temporary solution as long as devfs requires that - * fs_read_pages()/fs_write_pages() are called with the standard - * open cookie and not with a device cookie. - * If that's done differently, remove this call; it has no other - * purpose. - */ - +/*! This is currently called from file_cache_create() only. + It's probably a temporary solution as long as devfs requires that + fs_read_pages()/fs_write_pages() are called with the standard + open cookie and not with a device cookie. + If that's done differently, remove this call; it has no other + purpose. +*/ extern "C" status_t vfs_get_cookie_from_fd(int fd, void **_cookie) { @@ -2755,7 +2736,7 @@ extern "C" int -vfs_get_vnode_from_fd(int fd, bool kernel, void **vnode) +vfs_get_vnode_from_fd(int fd, bool kernel, struct vnode **vnode) { *vnode = get_vnode_from_fd(fd, kernel); @@ -2767,9 +2748,10 @@ extern "C" status_t -vfs_get_vnode_from_path(const char *path, bool kernel, void **_vnode) +vfs_get_vnode_from_path(const char *path, bool kernel, struct vnode **_vnode) { - TRACE(("vfs_get_vnode_from_path: entry. path = '%s', kernel %d\n", path, kernel)); + TRACE(("vfs_get_vnode_from_path: entry. path = '%s', kernel %d\n", + path, kernel)); KPath pathBuffer(B_PATH_NAME_LENGTH + 1); if (pathBuffer.InitCheck() != B_OK) @@ -2789,7 +2771,7 @@ extern "C" status_t -vfs_get_vnode(dev_t mountID, ino_t vnodeID, void **_vnode) +vfs_get_vnode(dev_t mountID, ino_t vnodeID, struct vnode **_vnode) { struct vnode *vnode; @@ -2804,30 +2786,27 @@ extern "C" status_t vfs_entry_ref_to_vnode(dev_t mountID, ino_t directoryID, - const char *name, void **_vnode) + const char *name, struct vnode **_vnode) { - return entry_ref_to_vnode(mountID, directoryID, name, (struct vnode **)_vnode); + return entry_ref_to_vnode(mountID, directoryID, name, _vnode); } extern "C" void -vfs_vnode_to_node_ref(void *_vnode, dev_t *_mountID, ino_t *_vnodeID) +vfs_vnode_to_node_ref(struct vnode *vnode, dev_t *_mountID, ino_t *_vnodeID) { - struct vnode *vnode = (struct vnode *)_vnode; - *_mountID = vnode->device; *_vnodeID = vnode->id; } -/** Looks up a vnode with the given mount and vnode ID. - * Must only be used with "in-use" vnodes as it doesn't grab a reference - * to the node. - * It's currently only be used by file_cache_create(). - */ - +/*! Looks up a vnode with the given mount and vnode ID. + Must only be used with "in-use" vnodes as it doesn't grab a reference + to the node. + It's currently only be used by file_cache_create(). +*/ extern "C" status_t -vfs_lookup_vnode(dev_t mountID, ino_t vnodeID, void **_vnode) +vfs_lookup_vnode(dev_t mountID, ino_t vnodeID, struct vnode **_vnode) { mutex_lock(&sVnodeMutex); struct vnode *vnode = lookup_vnode(mountID, vnodeID); @@ -2842,7 +2821,8 @@ extern "C" status_t -vfs_get_fs_node_from_path(dev_t mountID, const char *path, bool kernel, void **_node) +vfs_get_fs_node_from_path(dev_t mountID, const char *path, bool kernel, + void **_node) { TRACE(("vfs_get_fs_node_from_path(mountID = %ld, path = \"%s\", kernel %d)\n", mountID, path, kernel)); @@ -2885,17 +2865,16 @@ } -/** Finds the full path to the file that contains the module \a moduleName, - * puts it into \a pathBuffer, and returns B_OK for success. - * If \a pathBuffer was too small, it returns \c B_BUFFER_OVERFLOW, - * \c B_ENTRY_NOT_FOUNT if no file could be found. - * \a pathBuffer is clobbered in any case and must not be relied on if this - * functions returns unsuccessfully. - */ - +/*! Finds the full path to the file that contains the module \a moduleName, + puts it into \a pathBuffer, and returns B_OK for success. + If \a pathBuffer was too small, it returns \c B_BUFFER_OVERFLOW, + \c B_ENTRY_NOT_FOUNT if no file could be found. + \a pathBuffer is clobbered in any case and must not be relied on if this + functions returns unsuccessfully. +*/ status_t -vfs_get_module_path(const char *basePath, const char *moduleName, char *pathBuffer, - size_t bufferSize) +vfs_get_module_path(const char *basePath, const char *moduleName, + char *pathBuffer, size_t bufferSize) { struct vnode *dir, *file; status_t status; @@ -2974,29 +2953,28 @@ } -/** \brief Normalizes a given path. - * - * The path must refer to an existing or non-existing entry in an existing - * directory, that is chopping off the leaf component the remaining path must - * refer to an existing directory. - * - * The returned will be canonical in that it will be absolute, will not - * contain any "." or ".." components or duplicate occurrences of '/'s, - * and none of the directory components will by symbolic links. - * - * Any two paths referring to the same entry, will result in the same - * normalized path (well, that is pretty much the definition of `normalized', - * isn't it :-). - * - * \param path The path to be normalized. - * \param buffer The buffer into which the normalized path will be written. - * \param bufferSize The size of \a buffer. - * \param kernel \c true, if the IO context of the kernel shall be used, - * otherwise that of the team this thread belongs to. Only relevant, - * if the path is relative (to get the CWD). - * \return \c B_OK if everything went fine, another error code otherwise. - */ +/*! \brief Normalizes a given path. + The path must refer to an existing or non-existing entry in an existing + directory, that is chopping off the leaf component the remaining path must + refer to an existing directory. + + The returned will be canonical in that it will be absolute, will not + contain any "." or ".." components or duplicate occurrences of '/'s, + and none of the directory components will by symbolic links. + + Any two paths referring to the same entry, will result in the same + normalized path (well, that is pretty much the definition of `normalized', + isn't it :-). + + \param path The path to be normalized. + \param buffer The buffer into which the normalized path will be written. + \param bufferSize The size of \a buffer. + \param kernel \c true, if the IO context of the kernel shall be used, + otherwise that of the team this thread belongs to. Only relevant, + if the path is relative (to get the CWD). + \return \c B_OK if everything went fine, another error code otherwise. +*/ status_t vfs_normalize_path(const char *path, char *buffer, size_t bufferSize, bool kernel) @@ -3059,9 +3037,9 @@ extern "C" void -vfs_put_vnode(void *_vnode) +vfs_put_vnode(struct vnode *vnode) { - put_vnode((struct vnode *)_vnode); + put_vnode(vnode); } @@ -3107,25 +3085,22 @@ extern "C" bool -vfs_can_page(void *_vnode, void *cookie) +vfs_can_page(struct vnode *vnode, void *cookie) { - struct vnode *vnode = (struct vnode *)_vnode; - FUNCTION(("vfs_canpage: vnode 0x%p\n", vnode)); - if (FS_CALL(vnode, can_page)) - return FS_CALL(vnode, can_page)(vnode->mount->cookie, vnode->private_node, cookie); - + if (FS_CALL(vnode, can_page)) { + return FS_CALL(vnode, can_page)(vnode->mount->cookie, + vnode->private_node, cookie); + } return false; } extern "C" status_t -vfs_read_pages(void *_vnode, void *cookie, off_t pos, const iovec *vecs, +vfs_read_pages(struct vnode *vnode, void *cookie, off_t pos, const iovec *vecs, size_t count, size_t *_numBytes, bool mayBlock, bool fsReenter) { - struct vnode *vnode = (struct vnode *)_vnode; - FUNCTION(("vfs_read_pages: vnode %p, vecs %p, pos %Ld\n", vnode, vecs, pos)); return FS_CALL(vnode, read_pages)(vnode->mount->cookie, vnode->private_node, @@ -3134,11 +3109,9 @@ extern "C" status_t -vfs_write_pages(void *_vnode, void *cookie, off_t pos, const iovec *vecs, +vfs_write_pages(struct vnode *vnode, void *cookie, off_t pos, const iovec *vecs, size_t count, size_t *_numBytes, bool mayBlock, bool fsReenter) { - struct vnode *vnode = (struct vnode *)_vnode; - FUNCTION(("vfs_write_pages: vnode %p, vecs %p, pos %Ld\n", vnode, vecs, pos)); return FS_CALL(vnode, write_pages)(vnode->mount->cookie, vnode->private_node, @@ -3152,10 +3125,8 @@ it returns. */ extern "C" status_t -vfs_get_vnode_cache(void *_vnode, vm_cache **_cache, bool allocate) +vfs_get_vnode_cache(struct vnode *vnode, vm_cache **_cache, bool allocate) { - struct vnode *vnode = (struct vnode *)_vnode; - if (vnode->cache != NULL) { vm_cache_acquire_ref(vnode->cache); *_cache = vnode->cache; @@ -3194,21 +3165,19 @@ status_t -vfs_get_file_map(void *_vnode, off_t offset, size_t size, file_io_vec *vecs, size_t *_count) +vfs_get_file_map(struct vnode *vnode, off_t offset, size_t size, + file_io_vec *vecs, size_t *_count) { - struct vnode *vnode = (struct vnode *)_vnode; - FUNCTION(("vfs_get_file_map: vnode %p, vecs %p, offset %Ld, size = %lu\n", vnode, vecs, offset, size)); - return FS_CALL(vnode, get_file_map)(vnode->mount->cookie, vnode->private_node, offset, size, vecs, _count); + return FS_CALL(vnode, get_file_map)(vnode->mount->cookie, + vnode->private_node, offset, size, vecs, _count); } status_t -vfs_stat_vnode(void *_vnode, struct stat *stat) +vfs_stat_vnode(struct vnode *vnode, struct stat *stat) { - struct vnode *vnode = (struct vnode *)_vnode; - status_t status = FS_CALL(vnode, read_stat)(vnode->mount->cookie, vnode->private_node, stat); @@ -3223,15 +3192,13 @@ status_t -vfs_get_vnode_name(void *_vnode, char *name, size_t nameSize) +vfs_get_vnode_name(struct vnode *vnode, char *name, size_t nameSize) { - return get_vnode_name((struct vnode *)_vnode, NULL, name, nameSize); + return get_vnode_name(vnode, NULL, name, nameSize); } -/** If the given descriptor locked its vnode, that lock will be released. - */ - +/*! If the given descriptor locked its vnode, that lock will be released. */ void vfs_unlock_vnode_if_locked(struct file_descriptor *descriptor) { @@ -3242,10 +3209,9 @@ } -/** Closes all file descriptors of the specified I/O context that - * don't have the O_CLOEXEC flag set. - */ - +/*! Closes all file descriptors of the specified I/O context that + don't have the O_CLOEXEC flag set. +*/ void vfs_exec_io_context(void *_context) { @@ -3275,10 +3241,9 @@ } -/** Sets up a new io_control structure, and inherits the properties - * of the parent io_control if it is given. - */ - +/*! Sets up a new io_control structure, and inherits the properties [... truncated: 532 lines follow ...] From axeld at mail.berlios.de Sat Oct 6 17:35:39 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sat, 6 Oct 2007 17:35:39 +0200 Subject: [Haiku-commits] r22462 - in haiku/trunk: headers/private/kernel src/system/kernel/cache src/system/kernel/vm Message-ID: <200710061535.l96FZdig010563@sheep.berlios.de> Author: axeld Date: 2007-10-06 17:35:38 +0200 (Sat, 06 Oct 2007) New Revision: 22462 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22462&view=rev Modified: haiku/trunk/headers/private/kernel/vm_types.h haiku/trunk/src/system/kernel/cache/vnode_store.cpp haiku/trunk/src/system/kernel/cache/vnode_store.h haiku/trunk/src/system/kernel/vm/vm_page.cpp haiku/trunk/src/system/kernel/vm/vm_store_anonymous_noswap.cpp haiku/trunk/src/system/kernel/vm/vm_store_device.c haiku/trunk/src/system/kernel/vm/vm_store_null.c Log: * Added a acquire_unreferenced_ref() to vm_store * his has to be used by the page writer to make sure the vnode is still valid. * This should have been the final nail on the Luposian bug - I haven't tested it yet, but we'll certainly see :-) Modified: haiku/trunk/headers/private/kernel/vm_types.h =================================================================== --- haiku/trunk/headers/private/kernel/vm_types.h 2007-10-06 15:33:12 UTC (rev 22461) +++ haiku/trunk/headers/private/kernel/vm_types.h 2007-10-06 15:35:38 UTC (rev 22462) @@ -219,19 +219,20 @@ }; typedef struct vm_store_ops { - void (*destroy)(struct vm_store *backing_store); - status_t (*commit)(struct vm_store *backing_store, off_t size); - bool (*has_page)(struct vm_store *backing_store, off_t offset); - status_t (*read)(struct vm_store *backing_store, off_t offset, + void (*destroy)(struct vm_store *backingStore); + status_t (*commit)(struct vm_store *backingStore, off_t size); + bool (*has_page)(struct vm_store *backingStore, off_t offset); + status_t (*read)(struct vm_store *backingStore, off_t offset, const iovec *vecs, size_t count, size_t *_numBytes, bool mayBlock, bool fsReenter); - status_t (*write)(struct vm_store *backing_store, off_t offset, + status_t (*write)(struct vm_store *backingStore, off_t offset, const iovec *vecs, size_t count, size_t *_numBytes, bool mayBlock, bool fsReenter); - status_t (*fault)(struct vm_store *backing_store, + status_t (*fault)(struct vm_store *backingStore, struct vm_address_space *aspace, off_t offset); - void (*acquire_ref)(struct vm_store *backing_store); - void (*release_ref)(struct vm_store *backing_store); + status_t (*acquire_unreferenced_ref)(struct vm_store *backingStore); + void (*acquire_ref)(struct vm_store *backingStore); + void (*release_ref)(struct vm_store *backingStore); } vm_store_ops; #endif /* _KERNEL_VM_TYPES_H */ Modified: haiku/trunk/src/system/kernel/cache/vnode_store.cpp =================================================================== --- haiku/trunk/src/system/kernel/cache/vnode_store.cpp 2007-10-06 15:33:12 UTC (rev 22461) +++ haiku/trunk/src/system/kernel/cache/vnode_store.cpp 2007-10-06 15:35:38 UTC (rev 22462) @@ -83,6 +83,15 @@ } +static status_t +store_acquire_unreferenced_ref(struct vm_store *_store) +{ + vnode_store *store = (vnode_store *)_store; + struct vnode *vnode; + return vfs_get_vnode(store->device, store->inode, &vnode); +} + + static void store_acquire_ref(struct vm_store *_store) { @@ -106,6 +115,7 @@ &store_read, &store_write, NULL, /* fault */ + &store_acquire_unreferenced_ref, &store_acquire_ref, &store_release_ref }; @@ -128,6 +138,7 @@ store->vnode = vnode; store->file_cache_ref = NULL; + vfs_vnode_to_node_ref(vnode, &store->device, &store->inode); return &store->vm; } Modified: haiku/trunk/src/system/kernel/cache/vnode_store.h =================================================================== --- haiku/trunk/src/system/kernel/cache/vnode_store.h 2007-10-06 15:33:12 UTC (rev 22461) +++ haiku/trunk/src/system/kernel/cache/vnode_store.h 2007-10-06 15:35:38 UTC (rev 22462) @@ -12,6 +12,8 @@ struct vnode_store { vm_store vm; struct vnode* vnode; + dev_t device; + ino_t inode; void* file_cache_ref; }; Modified: haiku/trunk/src/system/kernel/vm/vm_page.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_page.cpp 2007-10-06 15:33:12 UTC (rev 22461) +++ haiku/trunk/src/system/kernel/vm/vm_page.cpp 2007-10-06 15:35:38 UTC (rev 22462) @@ -665,6 +665,15 @@ if (!cacheLocker.IsLocked()) continue; + vm_cache *cache = page->cache; + if (cache->store->ops->acquire_unreferenced_ref != NULL) { + // we need our own reference to the store, as it might + // currently be destructed + if (cache->store->ops->acquire_unreferenced_ref(cache->store) + != B_OK) + continue; + } + locker.Lock(); remove_page_from_queue(&sModifiedPageQueue, page); page->state = PAGE_STATE_BUSY; @@ -675,7 +684,7 @@ //dprintf("write page %p, cache %p (%ld)\n", page, page->cache, page->cache->ref_count); vm_clear_map_flags(page, PAGE_MODIFIED); - vm_cache_acquire_ref(page->cache); + vm_cache_acquire_ref(cache); pages[numPages++] = page; } @@ -711,6 +720,8 @@ busyConditions[i].Unpublish(); mutex_unlock(&cache->lock); + if (cache->store->ops->release_ref != NULL) + cache->store->ops->release_ref(cache->store); vm_cache_release_ref(cache); } } Modified: haiku/trunk/src/system/kernel/vm/vm_store_anonymous_noswap.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_store_anonymous_noswap.cpp 2007-10-06 15:33:12 UTC (rev 22461) +++ haiku/trunk/src/system/kernel/vm/vm_store_anonymous_noswap.cpp 2007-10-06 15:35:38 UTC (rev 22462) @@ -154,6 +154,7 @@ &anonymous_read, &anonymous_write, &anonymous_fault, + NULL, // acquire unreferenced ref NULL, // acquire ref NULL // release ref }; Modified: haiku/trunk/src/system/kernel/vm/vm_store_device.c =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_store_device.c 2007-10-06 15:33:12 UTC (rev 22461) +++ haiku/trunk/src/system/kernel/vm/vm_store_device.c 2007-10-06 15:35:38 UTC (rev 22462) @@ -78,8 +78,9 @@ &device_read, &device_write, &device_fault, - NULL, - NULL + NULL, // acquire unreferenced ref + NULL, // acquire ref + NULL // release ref }; Modified: haiku/trunk/src/system/kernel/vm/vm_store_null.c =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_store_null.c 2007-10-06 15:33:12 UTC (rev 22461) +++ haiku/trunk/src/system/kernel/vm/vm_store_null.c 2007-10-06 15:35:38 UTC (rev 22462) @@ -67,8 +67,9 @@ &null_read, &null_write, &null_fault, - NULL, - NULL + NULL, // acquire unreferenced ref + NULL, // acquire ref + NULL // release ref }; From korli at mail.berlios.de Sat Oct 6 20:20:06 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Sat, 6 Oct 2007 20:20:06 +0200 Subject: [Haiku-commits] r22463 - haiku/trunk/src/system/kernel/arch/ppc Message-ID: <200710061820.l96IK6OU004375@sheep.berlios.de> Author: korli Date: 2007-10-06 20:20:05 +0200 (Sat, 06 Oct 2007) New Revision: 22463 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22463&view=rev Modified: haiku/trunk/src/system/kernel/arch/ppc/arch_vm.cpp Log: fix ppc kernel build Modified: haiku/trunk/src/system/kernel/arch/ppc/arch_vm.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/ppc/arch_vm.cpp 2007-10-06 15:35:38 UTC (rev 22462) +++ haiku/trunk/src/system/kernel/arch/ppc/arch_vm.cpp 2007-10-06 18:20:05 UTC (rev 22463) @@ -11,6 +11,7 @@ #include #include +#include #include #include From korli at mail.berlios.de Sat Oct 6 20:40:33 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Sat, 6 Oct 2007 20:40:33 +0200 Subject: [Haiku-commits] r22464 - haiku/trunk/src/system/boot/platform/openfirmware Message-ID: <200710061840.l96IeXnD005209@sheep.berlios.de> Author: korli Date: 2007-10-06 20:40:32 +0200 (Sat, 06 Oct 2007) New Revision: 22464 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22464&view=rev Modified: haiku/trunk/src/system/boot/platform/openfirmware/debug.c Log: dprintf_no_syslog is needed for openfirmware platform Modified: haiku/trunk/src/system/boot/platform/openfirmware/debug.c =================================================================== --- haiku/trunk/src/system/boot/platform/openfirmware/debug.c 2007-10-06 18:20:05 UTC (rev 22463) +++ haiku/trunk/src/system/boot/platform/openfirmware/debug.c 2007-10-06 18:40:32 UTC (rev 22464) @@ -39,3 +39,14 @@ va_end(list); } + +void +dprintf_no_syslog(const char *format, ...) +{ + va_list list; + + va_start(list, format); + vprintf(format, list); + va_end(list); +} + From bonefish at cs.tu-berlin.de Sat Oct 6 21:11:43 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Sat, 06 Oct 2007 21:11:43 +0200 Subject: [Haiku-commits] r22464 - haiku/trunk/src/system/boot/platform/openfirmware In-Reply-To: <200710061840.l96IeXnD005209@sheep.berlios.de> References: <200710061840.l96IeXnD005209@sheep.berlios.de> Message-ID: <20071006211143.1512.2@cs.tu-berlin.de> On 2007-10-06 at 20:40:33 [+0200], korli at BerliOS wrote: > Author: korli > Date: 2007-10-06 20:40:32 +0200 (Sat, 06 Oct 2007) > New Revision: 22464 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22464&view=rev > > Modified: > haiku/trunk/src/system/boot/platform/openfirmware/debug.c > Log: > dprintf_no_syslog is needed for openfirmware platform It should not be needed. If it is, that part is apparently not compiled with the _BOOT_MODE macro defined. CU, Ingo From koki at myhaiku.org Sun Oct 7 00:30:35 2007 From: koki at myhaiku.org (Jorge G. Mare (a.k.a. Koki)) Date: Sat, 06 Oct 2007 15:30:35 -0700 Subject: [Haiku-commits] r22462 - in haiku/trunk: headers/private/kernel src/system/kernel/cache src/system/kernel/vm In-Reply-To: <200710061535.l96FZdig010563@sheep.berlios.de> References: <200710061535.l96FZdig010563@sheep.berlios.de> Message-ID: <47080C8B.10600@myhaiku.org> Hi Axel, axeld at BerliOS wrote: > Author: axeld > Date: 2007-10-06 17:35:38 +0200 (Sat, 06 Oct 2007) > New Revision: 22462 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22462&view=rev > Log: > * Added a acquire_unreferenced_ref() to vm_store > * his has to be used by the page writer to make sure the vnode is still valid. > * This should have been the final nail on the Luposian bug - I haven't tested > it yet, but we'll certainly see :-) I tested copying about 1GB worth of files from a Zeta partition to a Haiku partition, and memory load increased until the system froze. Upon reboot, none of the files had been copied to the Haiku partition. I am not sure if this is the way to test the Luposian bug, but thought I would report my results anyway (FWMBW). Tested with build 22464 on native hardware. Cheers, Koki From axeld at mail.berlios.de Sun Oct 7 14:21:18 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sun, 7 Oct 2007 14:21:18 +0200 Subject: [Haiku-commits] r22465 - haiku/trunk/src/system/kernel/cache Message-ID: <200710071221.l97CLIin019464@sheep.berlios.de> Author: axeld Date: 2007-10-07 14:21:18 +0200 (Sun, 07 Oct 2007) New Revision: 22465 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22465&view=rev Modified: haiku/trunk/src/system/kernel/cache/file_cache.cpp Log: * Fixed a serious oversight that could result in trying to insert a page twice into the same cache: cache_io() called read_into_cache() (or write_to_cache()), and that broke down the request into smaller parts. It then called read_chunk_into_cache() (or write_chunk_to_cache() resp.) to actually allocate pages and fulfill the request. However, it needed to unlock the cache for each chunk, and in the mean time someone else could insert pages into the remaining chunks. * Now, cache_io() already takes care of chunking the data which makes this approach safe, and also simplified the code a bit - read_into_cache()/ write_to_cache() are gone now. I've renamed read_chunk_into_cache() to read_into_cache() (same for the write function). * Also got rid of that goto in that function while I was on it. * Disabled cache_prefetch_vnode() for now (it's similar to cache_io(), but since it's currently not used [since no cache module is installed yet], I didn't want to go through updating it now, too). Modified: haiku/trunk/src/system/kernel/cache/file_cache.cpp =================================================================== --- haiku/trunk/src/system/kernel/cache/file_cache.cpp 2007-10-06 18:40:32 UTC (rev 22464) +++ haiku/trunk/src/system/kernel/cache/file_cache.cpp 2007-10-07 12:21:18 UTC (rev 22465) @@ -511,16 +511,18 @@ } -/*! - This function is called by read_into_cache() (and from there only) - it - can only handle a certain amount of bytes, and read_into_cache() makes +/*! Reads the requested amount of data into the cache, and allocates + pages needed to fulfill that request. This function is called by cache_io(). + It can only handle a certain amount of bytes, and the caller must make sure that it matches that criterion. + The cache_ref lock must be hold when calling this function; during + operation it will unlock the cache, though. */ static inline status_t -read_chunk_into_cache(file_cache_ref *ref, off_t offset, size_t numBytes, +read_into_cache(file_cache_ref *ref, off_t offset, size_t numBytes, int32 pageOffset, addr_t buffer, size_t bufferSize) { - TRACE(("read_chunk(offset = %Ld, size = %lu, pageOffset = %ld, buffer " + TRACE(("read_into_cache(offset = %Ld, size = %lu, pageOffset = %ld, buffer " "= %#lx, bufferSize = %lu\n", offset, size, pageOffset, buffer, bufferSize)); @@ -620,63 +622,13 @@ } -/*! - This function reads \a size bytes directly from the file into the cache. - If \a bufferSize does not equal zero, \a bufferSize bytes from the data - read in are also copied to the provided \a buffer. - This function always allocates all pages; it is the responsibility of the - calling function to only ask for yet uncached ranges. - The cache_ref lock must be hold when calling this function. +/*! Like read_into_cache() but writes data into the cache. + To preserve data consistency, it might also read pages into the cache, + though, if only a partial page gets written. + The same restrictions apply. */ -static status_t -read_into_cache(file_cache_ref *ref, off_t offset, size_t size, addr_t buffer, - size_t bufferSize) -{ - TRACE(("read_from_cache: ref = %p, offset = %Ld, size = %lu, buffer = %p, " - "bufferSize = %lu\n", ref, offset, size, (void *)buffer, bufferSize)); - - // do we have to read in anything at all? - if (size == 0) - return B_OK; - - // make sure "offset" is page aligned - but also remember the page offset - int32 pageOffset = offset & (B_PAGE_SIZE - 1); - size = PAGE_ALIGN(size + pageOffset); - offset -= pageOffset; - - while (true) { - size_t chunkSize = size; - if (chunkSize > (MAX_IO_VECS * B_PAGE_SIZE)) - chunkSize = MAX_IO_VECS * B_PAGE_SIZE; - - status_t status = read_chunk_into_cache(ref, offset, chunkSize, - pageOffset, buffer, bufferSize); - if (status != B_OK) - return status; - - if ((size -= chunkSize) == 0) - return B_OK; - - if (chunkSize >= bufferSize) { - bufferSize = 0; - buffer = NULL; - } else { - bufferSize -= chunkSize - pageOffset; - buffer += chunkSize - pageOffset; - } - - offset += chunkSize; - pageOffset = 0; - } - - return B_OK; -} - - -/** Like read_chunk_into_cache() but writes data into the cache */ - static inline status_t -write_chunk_to_cache(file_cache_ref *ref, off_t offset, size_t numBytes, +write_to_cache(file_cache_ref *ref, off_t offset, size_t numBytes, int32 pageOffset, addr_t buffer, size_t bufferSize) { // TODO: We're using way too much stack! Rather allocate a sufficiently @@ -805,66 +757,35 @@ } -/*! Like read_into_cache() but writes data into the cache. To preserve data - consistency, it might also read pages into the cache, though, if only a - partial page gets written. - The cache_ref lock must be hold when calling this function. -*/ static status_t -write_to_cache(file_cache_ref *ref, off_t offset, size_t size, addr_t buffer, - size_t bufferSize) +satisfy_cache_io(file_cache_ref *ref, off_t offset, addr_t buffer, + int32 &pageOffset, size_t bytesLeft, off_t &lastOffset, addr_t &lastBuffer, + int32 &lastPageOffset, size_t &lastLeft, bool doWrite) { - TRACE(("write_to_cache: ref = %p, offset = %Ld, size = %lu, buffer = %p, " - "bufferSize = %lu\n", ref, offset, size, (void *)buffer, bufferSize)); + if (lastBuffer == buffer) + return B_OK; - // make sure "offset" is page aligned - but also remember the page offset - int32 pageOffset = offset & (B_PAGE_SIZE - 1); - size = PAGE_ALIGN(size + pageOffset); - offset -= pageOffset; - - while (true) { - size_t chunkSize = size; - if (chunkSize > (MAX_IO_VECS * B_PAGE_SIZE)) - chunkSize = MAX_IO_VECS * B_PAGE_SIZE; - - status_t status = write_chunk_to_cache(ref, offset, chunkSize, - pageOffset, buffer, bufferSize); - if (status != B_OK) - return status; - - if ((size -= chunkSize) == 0) - return B_OK; - - if (chunkSize >= bufferSize) { - bufferSize = 0; - buffer = NULL; - } else { - bufferSize -= chunkSize - pageOffset; - buffer += chunkSize - pageOffset; - } - - offset += chunkSize; + size_t requestSize = buffer - lastBuffer; + status_t status; + if (doWrite) { + status = write_to_cache(ref, lastOffset, requestSize, lastPageOffset, + lastBuffer, requestSize); + } else { + status = read_into_cache(ref, lastOffset, requestSize, lastPageOffset, + lastBuffer, requestSize); + } + if (status == B_OK) { + lastBuffer = buffer; + lastLeft = bytesLeft; + lastOffset = offset; + lastPageOffset = 0; pageOffset = 0; } - - return B_OK; + return status; } static status_t -satisfy_cache_io(file_cache_ref *ref, off_t offset, addr_t buffer, - addr_t lastBuffer, bool doWrite) -{ - size_t requestSize = buffer - lastBuffer; - - if (doWrite) - return write_to_cache(ref, offset, requestSize, lastBuffer, requestSize); - - return read_into_cache(ref, offset, requestSize, lastBuffer, requestSize); -} - - -static status_t cache_io(void *_cacheRef, off_t offset, addr_t buffer, size_t *_size, bool doWrite) { @@ -893,11 +814,14 @@ size = fileSize - pageOffset - offset; *_size = size; } + if (size == 0) + return B_OK; // "offset" and "lastOffset" are always aligned to B_PAGE_SIZE, // the "last*" variables always point to the end of the last // satisfied request part + const uint32 kMaxChunkSize = MAX_IO_VECS * B_PAGE_SIZE; size_t bytesLeft = size, lastLeft = size; int32 lastPageOffset = pageOffset; addr_t lastBuffer = buffer; @@ -905,29 +829,17 @@ mutex_lock(&cache->lock); - for (; bytesLeft > 0; offset += B_PAGE_SIZE) { + while (bytesLeft > 0) { // check if this page is already in memory - restart: vm_page *page = vm_cache_lookup_page(cache, offset); if (page != NULL) { - // The page is busy - since we need to unlock the cache sometime + // The page may be busy - since we need to unlock the cache sometime // in the near future, we need to satisfy the request of the pages // we didn't get yet (to make sure no one else interferes in the // mean time). - status_t status = B_OK; - - if (lastBuffer != buffer) { - status = satisfy_cache_io(ref, lastOffset + lastPageOffset, - buffer, lastBuffer, doWrite); - if (status == B_OK) { - lastBuffer = buffer; - lastLeft = bytesLeft; - lastOffset = offset; - lastPageOffset = 0; - pageOffset = 0; - } - } - + status_t status = satisfy_cache_io(ref, offset, buffer, pageOffset, + bytesLeft, lastOffset, lastBuffer, lastPageOffset, lastLeft, + doWrite); if (status != B_OK) { mutex_unlock(&cache->lock); return status; @@ -939,7 +851,7 @@ mutex_unlock(&cache->lock); entry.Wait(); mutex_lock(&cache->lock); - goto restart; + continue; } } @@ -991,16 +903,27 @@ buffer += bytesInPage; bytesLeft -= bytesInPage; pageOffset = 0; + offset += B_PAGE_SIZE; + + if (buffer - lastBuffer + lastPageOffset >= kMaxChunkSize) { + status_t status = satisfy_cache_io(ref, offset, buffer, pageOffset, + bytesLeft, lastOffset, lastBuffer, lastPageOffset, lastLeft, + doWrite); + if (status != B_OK) { + mutex_unlock(&cache->lock); + return status; + } + } } // fill the last remaining bytes of the request (either write or read) status_t status; if (doWrite) { - status = write_to_cache(ref, lastOffset + lastPageOffset, lastLeft, + status = write_to_cache(ref, lastOffset, lastLeft, lastPageOffset, lastBuffer, lastLeft); } else { - status = read_into_cache(ref, lastOffset + lastPageOffset, lastLeft, + status = read_into_cache(ref, lastOffset, lastLeft, lastPageOffset, lastBuffer, lastLeft); } @@ -1065,6 +988,7 @@ extern "C" void cache_prefetch_vnode(struct vnode *vnode, off_t offset, size_t size) { +#if 0 vm_cache *cache; if (vfs_get_vnode_cache(vnode, &cache, false) != B_OK) return; @@ -1131,6 +1055,7 @@ out: mutex_unlock(&cache->lock); vm_cache_release_ref(cache); +#endif } From axeld at mail.berlios.de Sun Oct 7 15:32:13 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sun, 7 Oct 2007 15:32:13 +0200 Subject: [Haiku-commits] r22466 - in haiku/trunk/src/system/kernel: cache vm Message-ID: <200710071332.l97DWDZu026617@sheep.berlios.de> Author: axeld Date: 2007-10-07 15:32:13 +0200 (Sun, 07 Oct 2007) New Revision: 22466 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22466&view=rev Modified: haiku/trunk/src/system/kernel/cache/file_cache.cpp haiku/trunk/src/system/kernel/vm/vm_page.cpp Log: Actually forgot this nail: the file cache will now reserve the pages it will allocate with the vm_cache locked - this is necessary to be able to steal pages from itself (large files...). The system doesn't actually lock up anymore, but it still renders itself unusable; obviously the page thief does not work correctly, yet. The rest of the experience is created by our current scheduler (the page thief runs and runs, but it doesn't free any pages anymore). Modified: haiku/trunk/src/system/kernel/cache/file_cache.cpp =================================================================== --- haiku/trunk/src/system/kernel/cache/file_cache.cpp 2007-10-07 12:21:18 UTC (rev 22465) +++ haiku/trunk/src/system/kernel/cache/file_cache.cpp 2007-10-07 13:32:13 UTC (rev 22466) @@ -520,7 +520,8 @@ */ static inline status_t read_into_cache(file_cache_ref *ref, off_t offset, size_t numBytes, - int32 pageOffset, addr_t buffer, size_t bufferSize) + int32 pageOffset, addr_t buffer, size_t bufferSize, + size_t lastReservedPages, size_t reservePages) { TRACE(("read_into_cache(offset = %Ld, size = %lu, pageOffset = %ld, buffer " "= %#lx, bufferSize = %lu\n", offset, size, pageOffset, buffer, @@ -540,7 +541,7 @@ // allocate pages for the cache and mark them busy for (size_t pos = 0; pos < numBytes; pos += B_PAGE_SIZE) { vm_page *page = pages[pageIndex++] = vm_page_allocate_page( - PAGE_STATE_FREE, false); + PAGE_STATE_FREE, true); if (page == NULL) panic("no more pages!"); @@ -558,6 +559,7 @@ } mutex_unlock(&cache->lock); + vm_page_unreserve_pages(lastReservedPages); // read file into reserved pages status_t status = pages_io(ref, offset, vecs, vecCount, &numBytes, false); @@ -609,6 +611,7 @@ } } + vm_page_reserve_pages(reservePages); mutex_lock(&cache->lock); // make the pages accessible in the cache @@ -629,7 +632,8 @@ */ static inline status_t write_to_cache(file_cache_ref *ref, off_t offset, size_t numBytes, - int32 pageOffset, addr_t buffer, size_t bufferSize) + int32 pageOffset, addr_t buffer, size_t bufferSize, + size_t lastReservedPages, size_t reservePages) { // TODO: We're using way too much stack! Rather allocate a sufficiently // large chunk on the heap. @@ -651,7 +655,7 @@ // TODO: the pages we allocate here should have been reserved upfront // in cache_io() vm_page *page = pages[pageIndex++] = vm_page_allocate_page( - PAGE_STATE_FREE, false); + PAGE_STATE_FREE, true); busyConditions[pageIndex - 1].Publish(page, "page"); vm_cache_insert_page(ref->cache, page, offset + pos); @@ -665,6 +669,7 @@ } mutex_unlock(&ref->cache->lock); + vm_page_unreserve_pages(lastReservedPages); // copy contents (and read in partially written pages first) @@ -730,6 +735,9 @@ } } + if (status == B_OK) + vm_page_reserve_pages(reservePages); + mutex_lock(&ref->cache->lock); // unmap the pages again @@ -759,22 +767,27 @@ static status_t satisfy_cache_io(file_cache_ref *ref, off_t offset, addr_t buffer, - int32 &pageOffset, size_t bytesLeft, off_t &lastOffset, addr_t &lastBuffer, - int32 &lastPageOffset, size_t &lastLeft, bool doWrite) + int32 &pageOffset, size_t bytesLeft, size_t &reservePages, + off_t &lastOffset, addr_t &lastBuffer, int32 &lastPageOffset, + size_t &lastLeft, size_t &lastReservedPages, bool doWrite) { if (lastBuffer == buffer) return B_OK; size_t requestSize = buffer - lastBuffer; + reservePages = min_c(MAX_IO_VECS, + (bytesLeft - requestSize + B_PAGE_SIZE - 1) >> PAGE_SHIFT); + status_t status; if (doWrite) { status = write_to_cache(ref, lastOffset, requestSize, lastPageOffset, - lastBuffer, requestSize); + lastBuffer, requestSize, lastReservedPages, reservePages); } else { status = read_into_cache(ref, lastOffset, requestSize, lastPageOffset, - lastBuffer, requestSize); + lastBuffer, requestSize, lastReservedPages, reservePages); } if (status == B_OK) { + lastReservedPages = reservePages; lastBuffer = buffer; lastLeft = bytesLeft; lastOffset = offset; @@ -826,7 +839,11 @@ int32 lastPageOffset = pageOffset; addr_t lastBuffer = buffer; off_t lastOffset = offset; + size_t lastReservedPages = min_c(MAX_IO_VECS, + (bytesLeft + B_PAGE_SIZE - 1) >> PAGE_SHIFT); + size_t reservePages = 0; + vm_page_reserve_pages(lastReservedPages); mutex_lock(&cache->lock); while (bytesLeft > 0) { @@ -838,8 +855,8 @@ // we didn't get yet (to make sure no one else interferes in the // mean time). status_t status = satisfy_cache_io(ref, offset, buffer, pageOffset, - bytesLeft, lastOffset, lastBuffer, lastPageOffset, lastLeft, - doWrite); + bytesLeft, reservePages, lastOffset, lastBuffer, lastPageOffset, + lastLeft, lastReservedPages, doWrite); if (status != B_OK) { mutex_unlock(&cache->lock); return status; @@ -887,6 +904,7 @@ if (bytesLeft <= bytesInPage) { // we've read the last page, so we're done! mutex_unlock(&cache->lock); + vm_page_unreserve_pages(lastReservedPages); return B_OK; } @@ -907,8 +925,8 @@ if (buffer - lastBuffer + lastPageOffset >= kMaxChunkSize) { status_t status = satisfy_cache_io(ref, offset, buffer, pageOffset, - bytesLeft, lastOffset, lastBuffer, lastPageOffset, lastLeft, - doWrite); + bytesLeft, reservePages, lastOffset, lastBuffer, lastPageOffset, + lastLeft, lastReservedPages, doWrite); if (status != B_OK) { mutex_unlock(&cache->lock); return status; @@ -921,10 +939,10 @@ status_t status; if (doWrite) { status = write_to_cache(ref, lastOffset, lastLeft, lastPageOffset, - lastBuffer, lastLeft); + lastBuffer, lastLeft, lastReservedPages, 0); } else { status = read_into_cache(ref, lastOffset, lastLeft, lastPageOffset, - lastBuffer, lastLeft); + lastBuffer, lastLeft, lastReservedPages, 0); } mutex_unlock(&cache->lock); Modified: haiku/trunk/src/system/kernel/vm/vm_page.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_page.cpp 2007-10-07 12:21:18 UTC (rev 22465) +++ haiku/trunk/src/system/kernel/vm/vm_page.cpp 2007-10-07 13:32:13 UTC (rev 22466) @@ -1179,11 +1179,14 @@ void vm_page_unreserve_pages(uint32 count) { + if (count == 0) + return; + InterruptsSpinLocker locker(sPageLock); ASSERT(sReservedPages >= count); sReservedPages -= count; - + if (vm_page_num_free_pages() <= sReservedPages) sFreePageCondition.NotifyAll(); } @@ -1197,6 +1200,9 @@ void vm_page_reserve_pages(uint32 count) { + if (count == 0) + return; + InterruptsSpinLocker locker(sPageLock); sReservedPages += count; From bonefish at mail.berlios.de Sun Oct 7 16:41:56 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sun, 7 Oct 2007 16:41:56 +0200 Subject: [Haiku-commits] r22467 - haiku/trunk/src/kits/storage Message-ID: <200710071441.l97EfuOD006783@sheep.berlios.de> Author: bonefish Date: 2007-10-07 16:41:55 +0200 (Sun, 07 Oct 2007) New Revision: 22467 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22467&view=rev Modified: haiku/trunk/src/kits/storage/PartitioningInfo.cpp Log: Aesthetical changes. Modified: haiku/trunk/src/kits/storage/PartitioningInfo.cpp =================================================================== --- haiku/trunk/src/kits/storage/PartitioningInfo.cpp 2007-10-07 13:32:13 UTC (rev 22466) +++ haiku/trunk/src/kits/storage/PartitioningInfo.cpp 2007-10-07 14:41:55 UTC (rev 22467) @@ -67,24 +67,28 @@ BPartitioningInfo::_SetTo(partition_id partition, int32 changeCounter) { Unset(); + status_t error = B_OK; - partitionable_space_data *buffer = NULL; + partitionable_space_data* buffer = NULL; int32 count = 0; int32 actualCount = 0; - do { + while (true) { error = _kern_get_partitionable_spaces(partition, changeCounter, - buffer, count, &actualCount); - if (error == B_BUFFER_OVERFLOW) { - // buffer to small re-allocate it - if (buffer) - delete[] buffer; - buffer = new(nothrow) partitionable_space_data[actualCount]; - if (buffer) - count = actualCount; - else - error = B_NO_MEMORY; + buffer, count, &actualCount); + if (error != B_BUFFER_OVERFLOW) + break; + + // buffer too small re-allocate it + delete[] buffer; + buffer = new(nothrow) partitionable_space_data[actualCount]; + if (!buffer) { + error = B_NO_MEMORY; + break; } - } while (error == B_BUFFER_OVERFLOW); + + count = actualCount; + } + // set data / cleanup on failure if (error == B_OK) { fPartitionID = partition; @@ -92,6 +96,7 @@ fCount = actualCount; } else if (buffer) delete[] buffer; + return error; } From bonefish at mail.berlios.de Sun Oct 7 16:47:18 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sun, 7 Oct 2007 16:47:18 +0200 Subject: [Haiku-commits] r22468 - haiku/trunk/src/tests/apps/partitioner Message-ID: <200710071447.l97ElIBK007684@sheep.berlios.de> Author: bonefish Date: 2007-10-07 16:47:17 +0200 (Sun, 07 Oct 2007) New Revision: 22468 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22468&view=rev Modified: haiku/trunk/src/tests/apps/partitioner/Partitioner.cpp Log: * Ask for a partition name for initialization only, if the disk system supports names. * Finished interface for creating partitions. * Cosmetic changes. Modified: haiku/trunk/src/tests/apps/partitioner/Partitioner.cpp =================================================================== --- haiku/trunk/src/tests/apps/partitioner/Partitioner.cpp 2007-10-07 14:41:55 UTC (rev 22467) +++ haiku/trunk/src/tests/apps/partitioner/Partitioner.cpp 2007-10-07 14:47:17 UTC (rev 22468) @@ -6,6 +6,7 @@ * Ingo Weinhold */ +#include #include #include #include @@ -118,12 +119,15 @@ printf("%s read only: %d\n", prefix, partition->IsReadOnly()); printf("%s mounted: %d\n", prefix, partition->IsMounted()); printf("%s flags: %lx\n", prefix, partition->Flags()); - printf("%s name: `%s'\n", prefix, partition->Name()); + printf("%s name: \"%s\"\n", prefix, partition->Name()); printf("%s content name: \"%s\"\n", prefix, partition->ContentName()); printf("%s type: \"%s\"\n", prefix, partition->Type()); printf("%s content type: \"%s\"\n", prefix, partition->ContentType()); + printf("%s params: \"%s\"\n", prefix, partition->Parameters()); + printf("%s content params: \"%s\"\n", prefix, + partition->ContentParameters()); // volume, icon,... return false; } @@ -262,7 +266,7 @@ // main input loop while (true) { BString line; - if (!_ReadLine("> ", line)) + if (!_ReadLine("party> ", line)) return; if (line == "") { @@ -361,25 +365,20 @@ printf("\n"); // get the disk system - BDiskSystem* diskSystem = NULL; int64 diskSystemIndex; - do { - _ReadNumber("disk system index [-1 to abort]: ", diskSystemIndex); - if (diskSystemIndex < 0) - return; + if (!_ReadNumber("disk system index [-1 to abort]: ", 0, + diskSystems.CountItems() - 1, -1, "invalid index", + diskSystemIndex)) { + return; + } + BDiskSystem* diskSystem = diskSystems.ItemAt(diskSystemIndex); - diskSystem = diskSystems.ItemAt(diskSystemIndex); - if (!diskSystem) - printf("invalid index\n"); - } while (!diskSystem); - + bool supportsName = diskSystem->SupportsContentName(); BString name; BString parameters; while (true) { // let the user enter name and parameters -// TODO: Obviously we should be able to check whether the disk system supports -// naming at all. - if (!_ReadLine("partition name: ", name) + if (supportsName && !_ReadLine("partition name: ", name) || !_ReadLine("partition parameters: ", parameters)) { return; } @@ -387,15 +386,16 @@ // validate parameters char validatedName[B_OS_NAME_LENGTH]; strlcpy(validatedName, name.String(), sizeof(validatedName)); - if (partition->ValidateInitialize(diskSystem->Name(), validatedName, - parameters.String()) != B_OK) { + if (partition->ValidateInitialize(diskSystem->Name(), + supportsName ? validatedName : NULL, parameters.String()) + != B_OK) { printf("Validation of the given values failed. Sorry, can't " - "continue."); + "continue.\n"); return; } // did the disk system change the name? - if (name == validatedName) { + if (!supportsName || name == validatedName) { printf("Everything looks dandy.\n"); } else { printf("The disk system adjusted the file name to \"%s\".\n", @@ -408,8 +408,7 @@ bool changeParameters = false; while (true) { BString line; - _ReadLine("Everything looks dandy. [c]ontinue, change " - "[p]arameters, or [a]bort? ", line); + _ReadLine("[c]ontinue, change [p]arameters, or [a]bort? ", line); if (line == "a") return; if (line == "p") { @@ -428,7 +427,7 @@ // initialize status_t error = partition->Initialize(diskSystem->Name(), - name.String(), parameters.String()); + supportsName ? name.String() : NULL, parameters.String()); if (error != B_OK) printf("Initialization failed: %s\n", strerror(error)); } @@ -472,7 +471,7 @@ // get supported types BObjectList supportedTypes(20, true); - char typeBuffer[B_OS_NAME_LENGTH]; + char typeBuffer[B_DISK_DEVICE_TYPE_LENGTH]; int32 cookie = 0; while (diskSystem.GetNextSupportedType(partition, &cookie, typeBuffer) == B_OK) { @@ -501,6 +500,23 @@ return; } + // let the user select the partition type, if there's more than one + int64 typeIndex = 0; + int32 supportedTypesCount = supportedTypes.CountItems(); + if (supportedTypesCount > 1) { + // list them + printf("Possible partition types:\n"); + for (int32 i = 0; i < supportedTypesCount; i++) + printf("%2ld %s\n", i, supportedTypes.ItemAt(i)->String()); + + if (!_ReadNumber("supported type index [-1 to abort]: ", 0, + supportedTypesCount - 1, -1, "invalid index", typeIndex)) { + return; + } + } + + const char* type = supportedTypes.ItemAt(typeIndex)->String(); + // list partitionable spaces printf("Unused regions where the new partition could be created:\n"); for (int32 i = 0; i < spacesCount; i++) { @@ -510,11 +526,117 @@ BString offset, size; get_size_string(_offset, offset); get_size_string(_size, size); - printf("%2ld start: %8s, size: %8s", i, offset.String(), + printf("%2ld start: %8s, size: %8s\n", i, offset.String(), size.String()); } - // TODO:... + // let the user select the partitionable space, if there's more than one + int64 spaceIndex = 0; + if (spacesCount > 1) { + if (!_ReadNumber("unused region index [-1 to abort]: ", 0, + spacesCount - 1, -1, "invalid index", spaceIndex)) { + return; + } + } + + off_t spaceOffset; + off_t spaceSize; + partitioningInfo.GetPartitionableSpaceAt(spaceIndex, &spaceOffset, + &spaceSize); + + off_t start; + off_t size; + BString parameters; + while (true) { + // let the user enter start, size, and parameters + + // start + while (true) { + BString spaceOffsetString; + get_size_string(spaceOffset, spaceOffsetString); + BString prompt("partition start [default: "); + prompt << spaceOffsetString << "]: "; + if (!_ReadSize(prompt.String(), spaceOffset, start)) + return; + + if (start >= spaceOffset && start <= spaceOffset + spaceSize) + break; + + printf("invalid partition start\n"); + } + + // size + off_t maxSize = spaceOffset + spaceSize - start; + while (true) { + BString maxSizeString; + get_size_string(maxSize, maxSizeString); + BString prompt("partition size [default: "); + prompt << maxSizeString << "]: "; + if (!_ReadSize(prompt.String(), maxSize, size)) + return; + + if (size >= 0 && start + size <= spaceOffset + spaceSize) + break; + + printf("invalid partition size\n"); + } + + // parameters + if (!_ReadLine("partition parameters: ", parameters)) + return; + + // validate parameters + off_t validatedStart = start; + off_t validatedSize = size; + if (partition->ValidateCreateChild(&start, &size, type, + parameters.String()) != B_OK) { + printf("Validation of the given values failed. Sorry, can't " + "continue.\n"); + return; + } + + // did the disk system change offset or size? + if (validatedStart == start && validatedSize == size) { + printf("Everything looks dandy.\n"); + } else { + BString startString, sizeString; + get_size_string(validatedStart, startString); + get_size_string(validatedSize, sizeString); + printf("The disk system adjusted the partition start and " + "size to %lld (%s) and %lld (%s).\n", + validatedStart, startString.String(), validatedSize, + sizeString.String()); + start = validatedStart; + size = validatedSize; + } + + // let the user decide whether to continue, change parameters, or + // abort + bool changeParameters = false; + while (true) { + BString line; + _ReadLine("[c]ontinue, change [p]arameters, or [a]bort? ", line); + if (line == "a") + return; + if (line == "p") { + changeParameters = true; + break; + } + if (line == "c") + break; + + printf("invalid input\n"); + } + + if (!changeParameters) + break; + } + + // create child + error = partition->CreateChild(start, size, type, + parameters.String()); + if (error != B_OK) + printf("Creating the partiiton failed: %s\n", strerror(error)); } void _WriteChanges() @@ -554,11 +676,12 @@ } // otherwise let the user select + _PrintPartitionsShort(); + partition = NULL; int64 partitionIndex; while (true) { - _ReadNumber(prompt, partitionIndex); - if (partitionIndex < 0) + if (!_ReadNumber(prompt, partitionIndex) || partitionIndex < 0) return false; FindPartitionByIndexVisitor visitor(partitionIndex); @@ -606,6 +729,100 @@ } } + bool _ReadNumber(const char* prompt, int64 minNumber, int64 maxNumber, + int64 abortNumber, const char* invalidNumberMessage, int64& number) + { + while (true) { + BString line; + if (!_ReadLine(prompt, line)) + return false; + + char buffer[256]; + if (sscanf(line.String(), "%lld%s", &number, buffer) != 1) { + printf("invalid input\n"); + continue; + } + + if (number == abortNumber) + return false; + + if (number >= minNumber && number <= maxNumber) + return true; + + puts(invalidNumberMessage); + } + } + + bool _ReadSize(const char* prompt, off_t defaultValue, off_t& size) + { + while (true) { + BString _line; + if (!_ReadLine(prompt, _line)) + return false; + const char* line = _line.String(); + + // skip whitespace + while (isspace(*line)) + line++; + + if (*line == '\0') { + size = defaultValue; + return true; + } + + // get the number + int32 endIndex = 0; + while (isdigit(line[endIndex])) + endIndex++; + + if (endIndex == 0) { + printf("invalid input\n"); + continue; + } + + size = atoll(BString(line, endIndex).String()); + + // skip whitespace + line += endIndex; + while (isspace(*line)) + line++; + + // get the size modifier + if (*line != '\0') { + switch (*line) { + case 'K': + size *= 1024; + break; + case 'M': + size *= 1024 * 1024; + break; + case 'G': + size *= 1024LL * 1024 * 1024; + break; + case 'T': + size *= 1024LL * 1024 * 1024 * 1024; + break; + default: + line--; + } + + line++; + } + + if (*line == 'B') + line++; + + // skip whitespace + while (isspace(*line)) + line++; + + if (*line == '\0') + return true; + + printf("invalid input\n"); + } + } + private: BDiskDevice* fDevice; bool fPrepared; From bonefish at mail.berlios.de Sun Oct 7 16:50:25 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sun, 7 Oct 2007 16:50:25 +0200 Subject: [Haiku-commits] r22469 - haiku/trunk/src/kits/storage Message-ID: <200710071450.l97EoPtn008192@sheep.berlios.de> Author: bonefish Date: 2007-10-07 16:50:25 +0200 (Sun, 07 Oct 2007) New Revision: 22469 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22469&view=rev Modified: haiku/trunk/src/kits/storage/DiskSystem.cpp Log: Changed semantics of GetNextSupportedType(): It expects a pointer to the parent (not the child) partition, now. A method with the old semantics is probably needed, too, but before creating a child partition, one obviously doesn't have a child to pass yet. Modified: haiku/trunk/src/kits/storage/DiskSystem.cpp =================================================================== --- haiku/trunk/src/kits/storage/DiskSystem.cpp 2007-10-07 14:47:17 UTC (rev 22468) +++ haiku/trunk/src/kits/storage/DiskSystem.cpp 2007-10-07 14:50:25 UTC (rev 22469) @@ -243,18 +243,22 @@ // GetNextSupportedType status_t BDiskSystem::GetNextSupportedType(BPartition *partition, int32 *cookie, - char *type) const + char *type) const { +// TODO: We probably need a second method for and modify the partitioning +// system module hook a little. This method takes the parent partition of +// a partition to be created for which we want to get supported types. It +// should also be possible to invoke it for the partition whose type to change +// though. if (InitCheck() != B_OK) return InitCheck(); if (!cookie || !type || !partition || !partition->_IsShadow() - || !partition->Parent() || partition->Parent()->_DiskSystem() != fID - || !IsPartitioningSystem()) { + || partition->_DiskSystem() != fID || !IsPartitioningSystem()) { return B_BAD_VALUE; } + return _kern_get_next_supported_partition_type(partition->_ShadowID(), - partition->_ChangeCounter(), - cookie, type); + partition->_ChangeCounter(), cookie, type); } // GetTypeForContentType From bonefish at mail.berlios.de Sun Oct 7 16:52:54 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sun, 7 Oct 2007 16:52:54 +0200 Subject: [Haiku-commits] r22470 - in haiku/trunk: headers/private/storage src/kits/storage Message-ID: <200710071452.l97EqsdC008609@sheep.berlios.de> Author: bonefish Date: 2007-10-07 16:52:54 +0200 (Sun, 07 Oct 2007) New Revision: 22470 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22470&view=rev Modified: haiku/trunk/headers/private/storage/Partition.h haiku/trunk/src/kits/storage/Partition.cpp Log: Added [Content]Parameters() getters. Modified: haiku/trunk/headers/private/storage/Partition.h =================================================================== --- haiku/trunk/headers/private/storage/Partition.h 2007-10-07 14:50:25 UTC (rev 22469) +++ haiku/trunk/headers/private/storage/Partition.h 2007-10-07 14:52:54 UTC (rev 22470) @@ -48,6 +48,9 @@ const char *ContentType() const; // See DiskDeviceTypes.h partition_id ID() const; + const char* Parameters() const; + const char* ContentParameters() const; + status_t GetDiskSystem(BDiskSystem *diskSystem) const; virtual status_t GetPath(BPath *path) const; Modified: haiku/trunk/src/kits/storage/Partition.cpp =================================================================== --- haiku/trunk/src/kits/storage/Partition.cpp 2007-10-07 14:50:25 UTC (rev 22469) +++ haiku/trunk/src/kits/storage/Partition.cpp 2007-10-07 14:52:54 UTC (rev 22470) @@ -295,6 +295,23 @@ return (fPartitionData ? fPartitionData->id : -1); } + +// Parameters +const char* +BPartition::Parameters() const +{ + return fPartitionData ? fPartitionData->parameters : NULL; +} + + +// ContentParameters +const char* +BPartition::ContentParameters() const +{ + return fPartitionData ? fPartitionData->content_parameters : NULL; +} + + // GetDiskSystem status_t BPartition::GetDiskSystem(BDiskSystem *diskSystem) const From bonefish at mail.berlios.de Sun Oct 7 16:56:27 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sun, 7 Oct 2007 16:56:27 +0200 Subject: [Haiku-commits] r22471 - in haiku/trunk: headers/private/storage src/kits/storage Message-ID: <200710071456.l97EuRw9008956@sheep.berlios.de> Author: bonefish Date: 2007-10-07 16:56:26 +0200 (Sun, 07 Oct 2007) New Revision: 22471 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22471&view=rev Modified: haiku/trunk/headers/private/storage/DiskDevice.h haiku/trunk/src/kits/storage/DiskDevice.cpp Log: Clear the user_partition_data::user_data fields before updating the BPartition structure with the data retrieved from the kernel. For new partitions the field is not set in the next step and later code would use an initialized pointer. Modified: haiku/trunk/headers/private/storage/DiskDevice.h =================================================================== --- haiku/trunk/headers/private/storage/DiskDevice.h 2007-10-07 14:52:54 UTC (rev 22470) +++ haiku/trunk/headers/private/storage/DiskDevice.h 2007-10-07 14:56:26 UTC (rev 22471) @@ -52,6 +52,8 @@ status_t _Update(bool shadow, bool *updated); status_t _Update(user_disk_device_data *data, bool *updated); + static void _ClearUserData(user_partition_data* data); + virtual bool _AcceptVisitor(BDiskDeviceVisitor *visitor, int32 level); user_disk_device_data *fDeviceData; Modified: haiku/trunk/src/kits/storage/DiskDevice.cpp =================================================================== --- haiku/trunk/src/kits/storage/DiskDevice.cpp 2007-10-07 14:52:54 UTC (rev 22470) +++ haiku/trunk/src/kits/storage/DiskDevice.cpp 2007-10-07 14:56:26 UTC (rev 22471) @@ -377,11 +377,16 @@ if (!updated) updated = &_updated; *updated = false; + + // clear the user_data fields first + _ClearUserData(&data->device_partition_data); + // remove obsolete partitions status_t error = _RemoveObsoleteDescendants(&data->device_partition_data, - updated); + updated); if (error != B_OK) return error; + // update existing partitions and add new ones error = BPartition::_Update(&data->device_partition_data, updated); if (error == B_OK) { @@ -404,3 +409,14 @@ return visitor->Visit(this); } + +// _ClearUserData +void +BDiskDevice::_ClearUserData(user_partition_data* data) +{ + data->user_data = NULL; + + // recurse + for (int i = 0; i < data->child_count; i++) + _ClearUserData(data->children[i]); +} From bonefish at mail.berlios.de Sun Oct 7 17:11:37 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sun, 7 Oct 2007 17:11:37 +0200 Subject: [Haiku-commits] r22472 - in haiku/trunk: headers/os/drivers src/system/kernel/disk_device_manager Message-ID: <200710071511.l97FBbPW009905@sheep.berlios.de> Author: bonefish Date: 2007-10-07 17:11:37 +0200 (Sun, 07 Oct 2007) New Revision: 22472 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22472&view=rev Modified: haiku/trunk/headers/os/drivers/disk_device_manager.h haiku/trunk/src/system/kernel/disk_device_manager/disk_device_manager.cpp Log: * Added get_physical_partition() function, which always retrieves the physical partition, unlike get_partition() which returns the shadow partition, if it exists. * Added B_PARTITION_SHADOW[_CHILD] partition pseudo operation values for the shadow_changed() hook, notifying a disk system, that a shadow partition has been created. Modified: haiku/trunk/headers/os/drivers/disk_device_manager.h =================================================================== --- haiku/trunk/headers/os/drivers/disk_device_manager.h 2007-10-07 14:56:26 UTC (rev 22471) +++ haiku/trunk/headers/os/drivers/disk_device_manager.h 2007-10-07 15:11:37 UTC (rev 22472) @@ -57,6 +57,8 @@ // operations on partitions enum { + B_PARTITION_SHADOW, // indicates creation of a shadow partition + B_PARTITION_SHADOW_CHILD, // B_PARTITION_DEFRAGMENT, B_PARTITION_REPAIR, B_PARTITION_RESIZE, @@ -95,6 +97,7 @@ // disk device/partition read access // (read lock required) disk_device_data *get_disk_device(partition_id partitionID); +partition_data *get_physical_partition(partition_id partitionID); partition_data *get_partition(partition_id partitionID); partition_data *get_parent_partition(partition_id partitionID); partition_data *get_child_partition(partition_id partitionID, int32 index); @@ -106,7 +109,7 @@ // childID is an optional input parameter -- -1 to be ignored bool delete_partition(partition_id partitionID); void partition_modified(partition_id partitionID); - // tells the disk device manager, that the parition has been modified + // tells the disk device manager, that the partition has been modified status_t scan_partition(partition_id partitionID); // Service method for disks systems: Synchronously scans the partition. Modified: haiku/trunk/src/system/kernel/disk_device_manager/disk_device_manager.cpp =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/disk_device_manager.cpp 2007-10-07 14:56:26 UTC (rev 22471) +++ haiku/trunk/src/system/kernel/disk_device_manager/disk_device_manager.cpp 2007-10-07 15:11:37 UTC (rev 22472) @@ -12,11 +12,13 @@ #include "KDiskSystem.h" #include "KPartition.h" + // debugging //#define DBG(x) #define DBG(x) x #define OUT dprintf + // write_lock_disk_device disk_device_data * write_lock_disk_device(partition_id partitionID) @@ -32,6 +34,7 @@ return NULL; } + // write_unlock_disk_device void write_unlock_disk_device(partition_id partitionID) @@ -47,6 +50,7 @@ } } + // read_lock_disk_device disk_device_data * read_lock_disk_device(partition_id partitionID) @@ -62,6 +66,7 @@ return NULL; } + // read_unlock_disk_device void read_unlock_disk_device(partition_id partitionID) @@ -77,6 +82,7 @@ } } + // find_disk_device int32 find_disk_device(const char *path) @@ -90,6 +96,7 @@ return id; } + // find_partition int32 find_partition(const char *path) @@ -103,6 +110,7 @@ return id; } + // get_disk_device disk_device_data * get_disk_device(partition_id partitionID) @@ -112,15 +120,27 @@ return (device ? device->DeviceData() : NULL); } + +// get_physical_partition +partition_data* +get_physical_partition(partition_id partitionID) +{ + KDiskDeviceManager* manager = KDiskDeviceManager::Default(); + KPartition* partition = manager->FindPartition(partitionID, true); + return (partition ? partition->PartitionData() : NULL); +} + + // get_partition partition_data * get_partition(partition_id partitionID) { KDiskDeviceManager *manager = KDiskDeviceManager::Default(); - KPartition *partition = manager->FindPartition(partitionID); + KPartition *partition = manager->FindPartition(partitionID, false); return (partition ? partition->PartitionData() : NULL); } + // get_parent_partition partition_data * get_parent_partition(partition_id partitionID) @@ -132,6 +152,7 @@ return NULL; } + // get_child_partition partition_data * get_child_partition(partition_id partitionID, int32 index) @@ -144,6 +165,21 @@ return NULL; } + +// compare_partition_data_offset +static int +compare_partition_data_offset(const void* _a, const void* _b) +{ + const partition_data* a = *(const partition_data**)_a; + const partition_data* b = *(const partition_data**)_b; + + if (a->offset == b->offset) + return 0; + + return a->offset < b->offset ? -1 : 1; +} + + // create_child_partition partition_data * create_child_partition(partition_id partitionID, int32 index, @@ -162,6 +198,7 @@ return NULL; } + // delete_partition bool delete_partition(partition_id partitionID) @@ -174,6 +211,7 @@ return false; } + // partition_modified void partition_modified(partition_id partitionID) @@ -210,6 +248,7 @@ return -1; } + // update_disk_device_job_progress bool update_disk_device_job_progress(disk_job_id jobID, float progress) @@ -224,6 +263,7 @@ return false; } + // update_disk_device_job_extra_progress bool update_disk_device_job_extra_progress(disk_job_id jobID, const char *info) @@ -238,6 +278,7 @@ return false; } + // set_disk_device_job_error_message bool set_disk_device_job_error_message(disk_job_id jobID, const char *message) @@ -252,6 +293,7 @@ return false; } + // update_disk_device_job_interrupt_properties uint32 update_disk_device_job_interrupt_properties(disk_job_id jobID, From bonefish at mail.berlios.de Sun Oct 7 17:14:55 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sun, 7 Oct 2007 17:14:55 +0200 Subject: [Haiku-commits] r22473 - haiku/trunk/src/system/kernel/disk_device_manager Message-ID: <200710071514.l97FEtO8010042@sheep.berlios.de> Author: bonefish Date: 2007-10-07 17:14:54 +0200 (Sun, 07 Oct 2007) New Revision: 22473 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22473&view=rev Modified: haiku/trunk/src/system/kernel/disk_device_manager/ddm_operation_validation.cpp Log: The index parameter to validate_create_child_partition() is optional, but it is mandatory to the KDiskSystem::ValidateCreateChild(), which is invoked, so we need to use a stack variable. Modified: haiku/trunk/src/system/kernel/disk_device_manager/ddm_operation_validation.cpp =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/ddm_operation_validation.cpp 2007-10-07 15:11:37 UTC (rev 22472) +++ haiku/trunk/src/system/kernel/disk_device_manager/ddm_operation_validation.cpp 2007-10-07 15:14:54 UTC (rev 22473) @@ -430,23 +430,30 @@ status_t BPrivate::DiskDevice::validate_create_child_partition(KPartition *partition, int32 changeCounter, off_t *offset, off_t *size, const char *type, - const char *parameters, int32 *index, bool requireShadow) + const char *parameters, int32 *_index, bool requireShadow) { if (!partition || !offset || !size || !type) return B_BAD_VALUE; + // check the partition status_t error = check_partition(partition, changeCounter, requireShadow); if (error != B_OK) return error; + // get the disk system KDiskSystem *diskSystem = partition->DiskSystem(); if (!diskSystem) return B_ENTRY_NOT_FOUND; + // get the info + int32 index; if (diskSystem->ValidateCreateChild(partition, offset, size, type, - parameters, index)) { + parameters, &index)) { + if (_index) + *_index = index; return B_OK; } + return B_ERROR; } From bonefish at mail.berlios.de Sun Oct 7 17:17:39 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sun, 7 Oct 2007 17:17:39 +0200 Subject: [Haiku-commits] r22474 - haiku/trunk/headers/private/kernel/disk_device_manager Message-ID: <200710071517.l97FHd2P010187@sheep.berlios.de> Author: bonefish Date: 2007-10-07 17:17:38 +0200 (Sun, 07 Oct 2007) New Revision: 22474 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22474&view=rev Modified: haiku/trunk/headers/private/kernel/disk_device_manager/ddm_userland_interface.h Log: Fixed comment. Modified: haiku/trunk/headers/private/kernel/disk_device_manager/ddm_userland_interface.h =================================================================== --- haiku/trunk/headers/private/kernel/disk_device_manager/ddm_userland_interface.h 2007-10-07 15:14:54 UTC (rev 22473) +++ haiku/trunk/headers/private/kernel/disk_device_manager/ddm_userland_interface.h 2007-10-07 15:17:38 UTC (rev 22474) @@ -46,7 +46,7 @@ user_partition_data device_partition_data; } user_disk_device_data; -// userland partitionable space representation +// userland disk system representation typedef struct user_disk_system_info { disk_system_id id; char name[B_FILE_NAME_LENGTH]; // better B_PATH_NAME_LENGTH? From bonefish at mail.berlios.de Sun Oct 7 17:39:36 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sun, 7 Oct 2007 17:39:36 +0200 Subject: [Haiku-commits] r22475 - in haiku/trunk: headers/os/drivers headers/private/fs_shell headers/private/kernel/disk_device_manager src/add-ons/kernel/partitioning_systems/intel src/system/kernel/disk_device_manager Message-ID: <200710071539.l97FdaBH011152@sheep.berlios.de> Author: bonefish Date: 2007-10-07 17:39:35 +0200 (Sun, 07 Oct 2007) New Revision: 22475 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22475&view=rev Modified: haiku/trunk/headers/os/drivers/fs_interface.h haiku/trunk/headers/private/fs_shell/fssh_fs_interface.h haiku/trunk/headers/private/kernel/disk_device_manager/KDiskSystem.h haiku/trunk/headers/private/kernel/disk_device_manager/KFileSystem.h haiku/trunk/headers/private/kernel/disk_device_manager/KPartitioningSystem.h haiku/trunk/headers/private/kernel/disk_device_manager/ddm_modules.h haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMap.cpp haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMap.h haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/intel.cpp haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/intel.h haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/write_support.cpp haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/write_support.h haiku/trunk/src/system/kernel/disk_device_manager/KDiskSystem.cpp haiku/trunk/src/system/kernel/disk_device_manager/KFileSystem.cpp haiku/trunk/src/system/kernel/disk_device_manager/KPartition.cpp haiku/trunk/src/system/kernel/disk_device_manager/KPartitioningSystem.cpp haiku/trunk/src/system/kernel/disk_device_manager/KPhysicalPartition.cpp haiku/trunk/src/system/kernel/disk_device_manager/ddm_userland_interface.cpp Log: * The shadow_changed() FS and partitioning system hooks take an additional partition_data* child parameter now. * _user_get_partitionable_spaces() doesn't need to copy the buffer into the kernel, since it is no input parameter. It also copies back the actual partitionable spaces count on error, now -- B_BUFFER_OVERFLOW is returned when the buffer was too small, but then the count must be returned too. * Fixed several instances of syscall implementations that unloaded a disk system, although they didn't load it in the first place. This screwed up the load count with undesirable consequences. * _user_create_child_partition() would set the size to the supplied offset. * Fixed broken loop in KPhysicalPartition::CreateShadowPartition(). * KPartition::RemoveChild() notified the listeners about the wrong event. * Intel partitioning module: - The *_get_partitionable_spaces() correctly return B_BUFFER_OVERFLOW now, if the supplied buffer is too small. - Implemented a part of pm_shadow_changed(), which creates and updates the PartitionMap, so that the validate_*() hooks have a chance to work at all. Modified: haiku/trunk/headers/os/drivers/fs_interface.h =================================================================== --- haiku/trunk/headers/os/drivers/fs_interface.h 2007-10-07 15:17:38 UTC (rev 22474) +++ haiku/trunk/headers/os/drivers/fs_interface.h 2007-10-07 15:39:35 UTC (rev 22475) @@ -219,7 +219,7 @@ /* shadow partition modification (device is write locked) */ status_t (*shadow_changed)(partition_data *partition, - uint32 operation); + partition_data *child, uint32 operation); /* writing (the device is NOT locked) */ status_t (*defragment)(int fd, partition_id partition, Modified: haiku/trunk/headers/private/fs_shell/fssh_fs_interface.h =================================================================== --- haiku/trunk/headers/private/fs_shell/fssh_fs_interface.h 2007-10-07 15:17:38 UTC (rev 22474) +++ haiku/trunk/headers/private/fs_shell/fssh_fs_interface.h 2007-10-07 15:39:35 UTC (rev 22475) @@ -257,7 +257,7 @@ /* shadow partition modification (device is write locked) */ fssh_status_t (*shadow_changed)(fssh_partition_data *partition, - uint32_t operation); + fssh_partition_data *child, uint32_t operation); /* writing (the device is NOT locked) */ fssh_status_t (*defragment)(int fd, fssh_partition_id partition, Modified: haiku/trunk/headers/private/kernel/disk_device_manager/KDiskSystem.h =================================================================== --- haiku/trunk/headers/private/kernel/disk_device_manager/KDiskSystem.h 2007-10-07 15:17:38 UTC (rev 22474) +++ haiku/trunk/headers/private/kernel/disk_device_manager/KDiskSystem.h 2007-10-07 15:39:35 UTC (rev 22475) @@ -100,7 +100,7 @@ // Device must be write locked. virtual status_t ShadowPartitionChanged(KPartition *partition, - uint32 operation); + KPartition *child, uint32 operation); // Writing // Device should not be locked. Modified: haiku/trunk/headers/private/kernel/disk_device_manager/KFileSystem.h =================================================================== --- haiku/trunk/headers/private/kernel/disk_device_manager/KFileSystem.h 2007-10-07 15:17:38 UTC (rev 22474) +++ haiku/trunk/headers/private/kernel/disk_device_manager/KFileSystem.h 2007-10-07 15:39:35 UTC (rev 22475) @@ -48,7 +48,7 @@ // Shadow partition modification virtual status_t ShadowPartitionChanged(KPartition *partition, - uint32 operation); + KPartition *child, uint32 operation); // Writing Modified: haiku/trunk/headers/private/kernel/disk_device_manager/KPartitioningSystem.h =================================================================== --- haiku/trunk/headers/private/kernel/disk_device_manager/KPartitioningSystem.h 2007-10-07 15:17:38 UTC (rev 22474) +++ haiku/trunk/headers/private/kernel/disk_device_manager/KPartitioningSystem.h 2007-10-07 15:39:35 UTC (rev 22475) @@ -74,7 +74,7 @@ // Shadow partition modification virtual status_t ShadowPartitionChanged(KPartition *partition, - uint32 operation); + KPartition *child, uint32 operation); // Writing Modified: haiku/trunk/headers/private/kernel/disk_device_manager/ddm_modules.h =================================================================== --- haiku/trunk/headers/private/kernel/disk_device_manager/ddm_modules.h 2007-10-07 15:17:38 UTC (rev 22474) +++ haiku/trunk/headers/private/kernel/disk_device_manager/ddm_modules.h 2007-10-07 15:39:35 UTC (rev 22475) @@ -68,7 +68,8 @@ // shadow partition modification // (device is write locked) - status_t (*shadow_changed)(partition_data* partition, uint32 operation); + status_t (*shadow_changed)(partition_data* partition, + partition_data *child, uint32 operation); // writing Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMap.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMap.cpp 2007-10-07 15:17:38 UTC (rev 22474) +++ haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMap.cpp 2007-10-07 15:39:35 UTC (rev 22475) @@ -386,17 +386,6 @@ { } -// constructor -PrimaryPartition::PrimaryPartition(const partition_descriptor *descriptor, - off_t ptsOffset) - : Partition(), - fHead(NULL), - fTail(NULL), - fLogicalPartitionCount(0) -{ - SetTo(descriptor, ptsOffset); -} - // SetTo void PrimaryPartition::SetTo(const partition_descriptor *descriptor, off_t ptsOffset) @@ -419,6 +408,34 @@ Partition::Unset(); } + +// Assign +status_t +PrimaryPartition::Assign(const PrimaryPartition& other) +{ + partition_descriptor descriptor; + other.GetPartitionDescriptor(&descriptor, 0); + SetTo(&descriptor, 0); + + const LogicalPartition* otherLogical = other.fHead; + while (otherLogical) { + off_t ptsOffset = otherLogical->PTSOffset(); + otherLogical->GetPartitionDescriptor(&descriptor, ptsOffset); + + LogicalPartition* logical = new(nothrow) LogicalPartition( + &descriptor, ptsOffset, this); + if (!logical) + return B_NO_MEMORY; + + AddLogicalPartition(logical); + + otherLogical = otherLogical->Next(); + } + + return B_OK; +} + + // LogicalPartitionAt LogicalPartition * PrimaryPartition::LogicalPartitionAt(int32 index) const @@ -527,6 +544,8 @@ // constructor PartitionMap::PartitionMap() { + for (int32 i = 0; i < 4; i++) + fPrimaries[i].SetIndex(i); } // destructor @@ -542,6 +561,21 @@ fPrimaries[i].Unset(); } + +// Assign +status_t +PartitionMap::Assign(const PartitionMap& other) +{ + for (int32 i = 0; i < 4; i++) { + status_t error = fPrimaries[i].Assign(other.fPrimaries[i]); + if (error != B_OK) + return error; + } + + return B_OK; +} + + // PrimaryPartitionAt PrimaryPartition * PartitionMap::PrimaryPartitionAt(int32 index) @@ -562,6 +596,7 @@ return partition; } + // CountPartitions int32 PartitionMap::CountPartitions() const Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMap.h =================================================================== --- haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMap.h 2007-10-07 15:17:38 UTC (rev 22474) +++ haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMap.h 2007-10-07 15:39:35 UTC (rev 22475) @@ -165,11 +165,16 @@ class PrimaryPartition : public Partition { public: PrimaryPartition(); - PrimaryPartition(const partition_descriptor *descriptor, off_t ptsOffset); void SetTo(const partition_descriptor *descriptor, off_t ptsOffset); void Unset(); + status_t Assign(const PrimaryPartition& other); + + int32 Index() const { return fIndex; } + void SetIndex(int32 index) { fIndex = index; } + // private + // only if extended int32 CountLogicalPartitions() const { return fLogicalPartitionCount; } LogicalPartition *LogicalPartitionAt(int32 index) const; @@ -180,6 +185,7 @@ LogicalPartition *fHead; LogicalPartition *fTail; int32 fLogicalPartitionCount; + int32 fIndex; }; // LogicalPartition @@ -216,8 +222,11 @@ void Unset(); + status_t Assign(const PartitionMap& other); + PrimaryPartition *PrimaryPartitionAt(int32 index); const PrimaryPartition *PrimaryPartitionAt(int32 index) const; + int32 IndexOfPrimaryPartition(const PrimaryPartition* partition) const; int32 CountPartitions() const; int32 CountNonEmptyPartitions() const; Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/intel.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/intel.cpp 2007-10-07 15:17:38 UTC (rev 22474) +++ haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/intel.cpp 2007-10-07 15:39:35 UTC (rev 22475) @@ -131,7 +131,6 @@ PartitionMapCookie *map = new(nothrow) PartitionMapCookie; if (!map) return -1; - map->ref_count = 1; // read the partition structure PartitionMapParser parser(fd, 0, partition->size); Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/intel.h =================================================================== --- haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/intel.h 2007-10-07 15:17:38 UTC (rev 22474) +++ haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/intel.h 2007-10-07 15:39:35 UTC (rev 22475) @@ -13,6 +13,8 @@ // A PartitionMap with reference count. struct PartitionMapCookie : PartitionMap { + PartitionMapCookie() : ref_count(1) {} + int32 ref_count; }; Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/write_support.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/write_support.cpp 2007-10-07 15:17:38 UTC (rev 22474) +++ haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/write_support.cpp 2007-10-07 15:39:35 UTC (rev 22475) @@ -77,7 +77,8 @@ int32 countSpaces = 0; if (partition->child_count < 4 // free space check - && pm_get_partitionable_spaces(partition, NULL, 0, &countSpaces) == B_OK + && pm_get_partitionable_spaces(partition, NULL, 0, &countSpaces) + == B_BUFFER_OVERFLOW && countSpaces > 0) { flags |= B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD; } @@ -661,8 +662,12 @@ if (positions) delete[] positions; + TRACE(("intel: get_partitionable_spaces - found: %ld\n", actualCount)); + *_actualCount = actualCount; - TRACE(("intel: get_partitionable_spaces - found: %ld\n", actualCount)); + + if (count < actualCount) + return B_BUFFER_OVERFLOW; return B_OK; } @@ -725,15 +730,162 @@ // pm_shadow_changed status_t -pm_shadow_changed(partition_data *partition, uint32 operation) +pm_shadow_changed(partition_data *partition, partition_data *child, + uint32 operation) { - TRACE(("intel: pm_shadow_changed\n")); + TRACE(("intel: pm_shadow_changed(%p, %p, %lu)\n", partition, child, + operation)); - if (!partition) - return B_BAD_VALUE; + switch (operation) { + case B_PARTITION_SHADOW: + { + // get the physical partition + partition_data* physicalPartition = get_physical_partition( + partition->id); + if (!physicalPartition) { + dprintf("intel: pm_shadow_changed(B_PARTITION_SHADOW): no " + "physical partition with ID %ld\n", partition->id); + return B_ERROR; + } - // nothing to do here - return B_OK; + // clone the map + if (!physicalPartition->content_cookie) { + dprintf("intel: pm_shadow_changed(B_PARTITION_SHADOW): no " + "content cookie, physical partition: %ld\n", partition->id); + return B_ERROR; + } + + PartitionMapCookie* map = new(nothrow) PartitionMapCookie; + if (!map) + return B_NO_MEMORY; + + status_t error = map->Assign( + *(PartitionMapCookie*)physicalPartition->content_cookie); + if (error != B_OK) { + delete map; + return error; + } + + partition->content_cookie = map; + + return B_OK; + } + + case B_PARTITION_SHADOW_CHILD: + { + // get the physical child partition + partition_data* physical = get_physical_partition(child->id); + if (!physical) { + dprintf("intel: pm_shadow_changed(B_PARTITION_SHADOW_CHILD): " + "no physical partition with ID %ld\n", child->id); + return B_ERROR; + } + + if (!physical->cookie) { + dprintf("intel: pm_shadow_changed(B_PARTITION_SHADOW_CHILD): " + "no cookie, physical partition: %ld\n", child->id); + return B_ERROR; + } + + // primary partition index + int32 index = ((PrimaryPartition*)physical->cookie)->Index(); + + if (!partition->content_cookie) { + dprintf("intel: pm_shadow_changed(B_PARTITION_SHADOW_CHILD): " + "no content cookie, physical partition: %ld\n", + partition->id); + return B_ERROR; + } + + // get the primary partition + PartitionMapCookie* map + = ((PartitionMapCookie*)partition->content_cookie); + PrimaryPartition* primary = map->PrimaryPartitionAt(index); + + if (!primary || primary->IsEmpty()) { + dprintf("intel: pm_shadow_changed(B_PARTITION_SHADOW_CHILD): " + "partition %ld is empty, primary index: %ld\n", child->id, + index); + return B_BAD_VALUE; + } + + child->cookie = primary; + + return B_OK; + } + + case B_PARTITION_INITIALIZE: + { + // create an empty partition map + PartitionMapCookie* map = new(nothrow) PartitionMapCookie; + if (!map) + return B_NO_MEMORY; + + partition->content_cookie = map; + + return B_OK; + } + + case B_PARTITION_CREATE_CHILD: + { + if (!partition->content_cookie) { + dprintf("intel: pm_shadow_changed(B_PARTITION_CREATE_CHILD): " + "no content cookie, partition: %ld\n", partition->id); + return B_ERROR; + } + + PartitionMapCookie* map + = ((PartitionMapCookie*)partition->content_cookie); + + // find an empty primary partition slot + PrimaryPartition* primary = NULL; + for (int32 i = 0; i < 4; i++) { + if (map->PrimaryPartitionAt(i)->IsEmpty()) { + primary = map->PrimaryPartitionAt(i); + break; + } + } + + if (!primary) { + dprintf("intel: pm_shadow_changed(B_PARTITION_CREATE_CHILD): " + "no empty primary slot, partition: %ld\n", partition->id); + return B_ERROR; + } + + // apply type + PartitionType type; + type.SetType(child->type); + if (!type.IsValid()) { + dprintf("intel: pm_shadow_changed(B_PARTITION_CREATE_CHILD): " + "invalid partition type, partition: %ld\n", partition->id); + return B_ERROR; + } + + primary->SetType(type.Type()); + + // TODO: Apply parameters! + + child->cookie = primary; + + return B_OK; + } + + case B_PARTITION_DEFRAGMENT: + case B_PARTITION_REPAIR: + case B_PARTITION_RESIZE: + case B_PARTITION_RESIZE_CHILD: + case B_PARTITION_MOVE: + case B_PARTITION_MOVE_CHILD: + case B_PARTITION_SET_NAME: + case B_PARTITION_SET_CONTENT_NAME: + case B_PARTITION_SET_TYPE: + case B_PARTITION_SET_PARAMETERS: + case B_PARTITION_SET_CONTENT_PARAMETERS: + case B_PARTITION_DELETE_CHILD: + break; + } + + return B_ERROR; } @@ -1249,7 +1401,8 @@ // creating child int32 countSpaces = 0; - if (pm_get_partitionable_spaces(partition, NULL, 0, &countSpaces) == B_OK + if (pm_get_partitionable_spaces(partition, NULL, 0, &countSpaces) + == B_BUFFER_OVERFLOW && countSpaces > 0) { flags |= B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD; } @@ -1500,7 +1653,8 @@ // ep_shadow_changed status_t -ep_shadow_changed(partition_data *partition, uint32 operation) +ep_shadow_changed(partition_data *partition, partition_data *child, + uint32 operation) { TRACE(("intel: ep_shadow_changed\n")); Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/write_support.h =================================================================== --- haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/write_support.h 2007-10-07 15:17:38 UTC (rev 22474) +++ haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/write_support.h 2007-10-07 15:39:35 UTC (rev 22475) @@ -33,7 +33,8 @@ int32 *actualCount); status_t pm_get_next_supported_type(partition_data *partition, int32 *cookie, char *_type); -status_t pm_shadow_changed(partition_data *partition, uint32 operation); +status_t pm_shadow_changed(partition_data *partition, partition_data *child, + uint32 operation); status_t pm_resize(int fd, partition_id partitionID, off_t size, disk_job_id job); @@ -77,7 +78,8 @@ int32 *actualCount); status_t ep_get_next_supported_type(partition_data *partition, int32 *cookie, char *_type); -status_t ep_shadow_changed(partition_data *partition, uint32 operation); +status_t ep_shadow_changed(partition_data *partition, partition_data *child, + uint32 operation); status_t ep_resize(int fd, partition_id partitionID, off_t size, disk_job_id job); Modified: haiku/trunk/src/system/kernel/disk_device_manager/KDiskSystem.cpp =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/KDiskSystem.cpp 2007-10-07 15:17:38 UTC (rev 22474) +++ haiku/trunk/src/system/kernel/disk_device_manager/KDiskSystem.cpp 2007-10-07 15:39:35 UTC (rev 22475) @@ -118,6 +118,7 @@ KDiskSystem::Load() { ManagerLocker locker(KDiskDeviceManager::Default()); +dprintf("KDiskSystem::Load(): %s -> %ld\n", Name(), fLoadCounter + 1); status_t error = B_OK; if (fLoadCounter == 0) error = LoadModule(); @@ -132,6 +133,7 @@ KDiskSystem::Unload() { ManagerLocker locker(KDiskDeviceManager::Default()); +dprintf("KDiskSystem::Unload(): %s -> %ld\n", Name(), fLoadCounter - 1); if (fLoadCounter > 0 && --fLoadCounter == 0) UnloadModule(); } @@ -361,7 +363,8 @@ // ShadowPartitionChanged status_t -KDiskSystem::ShadowPartitionChanged(KPartition *partition, uint32 operation) +KDiskSystem::ShadowPartitionChanged(KPartition *partition, KPartition *child, + uint32 operation) { // to be implemented by derived classes return B_ENTRY_NOT_FOUND; Modified: haiku/trunk/src/system/kernel/disk_device_manager/KFileSystem.cpp =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/KFileSystem.cpp 2007-10-07 15:17:38 UTC (rev 22474) +++ haiku/trunk/src/system/kernel/disk_device_manager/KFileSystem.cpp 2007-10-07 15:39:35 UTC (rev 22475) @@ -173,7 +173,8 @@ // ShadowPartitionChanged status_t -KFileSystem::ShadowPartitionChanged(KPartition *partition, uint32 operation) +KFileSystem::ShadowPartitionChanged(KPartition *partition, KPartition *child, + uint32 operation) { if (!partition) return B_BAD_VALUE; @@ -183,7 +184,8 @@ // make any additional changes. if (!fModule->shadow_changed) return B_OK; - return fModule->shadow_changed(partition->PartitionData(), operation); + return fModule->shadow_changed(partition->PartitionData(), + child ? child->PartitionData() : NULL, operation); } Modified: haiku/trunk/src/system/kernel/disk_device_manager/KPartition.cpp =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/KPartition.cpp 2007-10-07 15:17:38 UTC (rev 22474) +++ haiku/trunk/src/system/kernel/disk_device_manager/KPartition.cpp 2007-10-07 15:39:35 UTC (rev 22475) @@ -680,7 +680,7 @@ partition->SetParent(NULL); partition->SetDevice(NULL); // notify listeners - FireChildAdded(partition, index); + FireChildRemoved(partition, index); return true; } return false; Modified: haiku/trunk/src/system/kernel/disk_device_manager/KPartitioningSystem.cpp =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/KPartitioningSystem.cpp 2007-10-07 15:17:38 UTC (rev 22474) +++ haiku/trunk/src/system/kernel/disk_device_manager/KPartitioningSystem.cpp 2007-10-07 15:39:35 UTC (rev 22475) @@ -408,7 +408,7 @@ //! Calls for additional modifications when shadow partition is changed status_t KPartitioningSystem::ShadowPartitionChanged(KPartition *partition, - uint32 operation) + KPartition *child, uint32 operation) { if (!partition) return B_BAD_VALUE; @@ -418,7 +418,8 @@ // have to make any additional changes. if (!fModule->shadow_changed) return B_OK; - return fModule->shadow_changed(partition->PartitionData(), operation); + return fModule->shadow_changed(partition->PartitionData(), + child ? child->PartitionData() : NULL, operation); } Modified: haiku/trunk/src/system/kernel/disk_device_manager/KPhysicalPartition.cpp =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/KPhysicalPartition.cpp 2007-10-07 15:17:38 UTC (rev 22474) +++ haiku/trunk/src/system/kernel/disk_device_manager/KPhysicalPartition.cpp 2007-10-07 15:39:35 UTC (rev 22475) @@ -167,27 +167,54 @@ { if (fShadowPartition) return B_BAD_VALUE; + KDiskDeviceManager *manager = KDiskDeviceManager::Default(); if (ManagerLocker locker = manager) { // create shadow partition fShadowPartition = new(nothrow) KShadowPartition(this); if (!fShadowPartition) return B_NO_MEMORY; + // make it known to the manager if (!manager->PartitionAdded(fShadowPartition)) { delete fShadowPartition; fShadowPartition = NULL; return B_NO_MEMORY; } + + // notify the disk systems + // parent disk system + status_t error; + if (Parent()) { + error = Parent()->DiskSystem()->ShadowPartitionChanged( + Parent()->ShadowPartition(), fShadowPartition, + B_PARTITION_SHADOW_CHILD); + if (error != B_OK) { + UnsetShadowPartition(true); + return error; + } + } + + // this partition's disk system + if (fShadowPartition->DiskSystem()) { + error = fShadowPartition->DiskSystem()->ShadowPartitionChanged( + fShadowPartition, NULL, B_PARTITION_SHADOW); + if (error != B_OK) { + UnsetShadowPartition(true); + return error; + } + } } + // create shadows for children for (int32 i = 0; KPartition *child = ChildAt(i); i++) { status_t error = child->CreateShadowPartition(); if (error == B_OK) error = fShadowPartition->AddChild(child->ShadowPartition(), i); + // cleanup on error if (error != B_OK) { - for (int32 k = 0; k <= i; i++) + for (int32 k = 0; k <= i; k++) ChildAt(k)->UnsetShadowPartition(true); UnsetShadowPartition(true); return error; Modified: haiku/trunk/src/system/kernel/disk_device_manager/ddm_userland_interface.cpp =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/ddm_userland_interface.cpp 2007-10-07 15:17:38 UTC (rev 22474) +++ haiku/trunk/src/system/kernel/disk_device_manager/ddm_userland_interface.cpp 2007-10-07 15:39:35 UTC (rev 22475) @@ -26,6 +26,10 @@ // debugging #define ERROR(x) + +// TODO: Add user address checks and check return values of user_memcpy()! + + // ddm_strlcpy /*! \brief Wrapper around user_strlcpy() that returns a status_t indicating appropriate success or failure. @@ -70,7 +74,7 @@ KDiskSystem *diskSystem = partition->DiskSystem(); if (diskSystem || partition->AlgorithmData()) { status_t error = diskSystem->ShadowPartitionChanged(partition, - B_PARTITION_RESIZE); + NULL, B_PARTITION_MOVE); if (error != B_OK) return error; } @@ -284,46 +288,58 @@ _user_get_partitionable_spaces(partition_id partitionID, int32 changeCounter, partitionable_space_data *_buffer, int32 count, int32 *_actualCount) { - if (!_buffer && count > 0) + if (count > 0 && !_buffer) return B_BAD_VALUE; - // copy in + + if (count > 0 && !IS_USER_ADDRESS(_buffer) + || _actualCount && !IS_USER_ADDRESS(_actualCount)) { + return B_BAD_ADDRESS; + } + + // allocate buffer int32 bufferSize = count * sizeof(partitionable_space_data); - partitionable_space_data *buffer = count > 0 - ? reinterpret_cast(malloc(bufferSize)) - : NULL; - if (buffer) - user_memcpy(buffer, _buffer, bufferSize); + partitionable_space_data *buffer = NULL; + MemoryDeleter bufferDeleter; + if (count > 0) { + buffer = (partitionable_space_data*)malloc(bufferSize); + if (!buffer) + return B_NO_MEMORY; + bufferDeleter.SetTo(buffer); + } + status_t error = B_OK; + // get the partition KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KPartition *partition = manager->ReadLockPartition(partitionID); - error = partition ? (status_t)B_OK : (status_t)B_ENTRY_NOT_FOUND; - if (!error) { - PartitionRegistrar registrar1(partition, true); - PartitionRegistrar registrar2(partition->Device(), true); - DeviceReadLocker locker(partition->Device(), true); - error = check_shadow_partition(partition, changeCounter) - ? B_OK : B_BAD_VALUE; - if (!error) { - // get the disk system - KDiskSystem *diskSystem = partition->DiskSystem(); - error = diskSystem ? (status_t)B_OK : (status_t)B_ENTRY_NOT_FOUND; - if (!error) { - // get the info - int32 actualCount; - error = diskSystem->GetPartitionableSpaces(partition, buffer, - count, &actualCount); - if (!error && _actualCount) { - user_memcpy(_actualCount, &actualCount, - sizeof(actualCount)); - } - } - } - } + if (!partition) + return B_ENTRY_NOT_FOUND; + + PartitionRegistrar registrar1(partition, true); + PartitionRegistrar registrar2(partition->Device(), true); + DeviceReadLocker locker(partition->Device(), true); + + if (!check_shadow_partition(partition, changeCounter)) + return B_BAD_VALUE; + + // get the disk system + KDiskSystem *diskSystem = partition->DiskSystem(); + if (!diskSystem) + return B_ENTRY_NOT_FOUND; + + // get the info + int32 actualCount; + error = diskSystem->GetPartitionableSpaces(partition, buffer, count, + &actualCount); + // copy out - if (!error && buffer) + if (_actualCount) + user_memcpy(_actualCount, &actualCount, sizeof(actualCount)); + // copy even on error + + if (error == B_OK && buffer) user_memcpy(_buffer, buffer, bufferSize); - free(buffer); + return error; } @@ -376,7 +392,6 @@ KDiskDeviceManager *manager = KDiskDeviceManager::Default(); if (ManagerLocker locker = manager) { if (KDiskSystem *diskSystem = manager->FindDiskSystem(id)) { - DiskSystemLoader _(diskSystem, true); user_disk_system_info info; diskSystem->GetInfo(&info); user_memcpy(_info, &info, sizeof(info)); @@ -399,7 +414,6 @@ KDiskDeviceManager *manager = KDiskDeviceManager::Default(); if (ManagerLocker locker = manager) { if (KDiskSystem *diskSystem = manager->NextDiskSystem(&cookie)) { - DiskSystemLoader _(diskSystem, true); user_disk_system_info info; diskSystem->GetInfo(&info); user_memcpy(_info, &info, sizeof(info)); @@ -424,7 +438,6 @@ KDiskDeviceManager *manager = KDiskDeviceManager::Default(); if (ManagerLocker locker = manager) { if (KDiskSystem *diskSystem = manager->FindDiskSystem(name)) { - DiskSystemLoader _(diskSystem, true); user_disk_system_info info; diskSystem->GetInfo(&info); user_memcpy(_info, &info, sizeof(info)); @@ -1146,9 +1159,8 @@ char type[B_DISK_DEVICE_TYPE_LENGTH]; error = diskSystem->GetNextSupportedType(partition, &cookie, type); - if (!error) { + if (!error) error = ddm_strlcpy(_type, type, B_DISK_DEVICE_TYPE_LENGTH); - } } } } @@ -1352,13 +1364,13 @@ partition->Changed(B_PARTITION_CHANGED_SIZE); // implicit partitioning system changes error = partition->Parent()->DiskSystem()->ShadowPartitionChanged( - partition, B_PARTITION_RESIZE_CHILD); + partition->Parent(), partition, B_PARTITION_RESIZE_CHILD); if (error != B_OK) return error; // implicit content disk system changes if (partition->DiskSystem()) { error = partition->DiskSystem()->ShadowPartitionChanged( - partition, B_PARTITION_RESIZE); + partition, NULL, B_PARTITION_RESIZE); } return error; } @@ -1393,7 +1405,7 @@ partition->Changed(B_PARTITION_CHANGED_OFFSET); // implicit partitioning system changes error = partition->Parent()->DiskSystem()->ShadowPartitionChanged( - partition, B_PARTITION_MOVE_CHILD); + partition->Parent(), partition, B_PARTITION_MOVE_CHILD); if (error != B_OK) return error; // implicit descendants' content disk system changes @@ -1435,7 +1447,7 @@ partition->Changed(B_PARTITION_CHANGED_NAME); // implicit partitioning system changes return partition->Parent()->DiskSystem()->ShadowPartitionChanged( - partition, B_PARTITION_SET_NAME); + partition->Parent(), partition, B_PARTITION_SET_NAME); } @@ -1474,7 +1486,7 @@ partition->Changed(B_PARTITION_CHANGED_CONTENT_NAME); // implicit content disk system changes return partition->DiskSystem()->ShadowPartitionChanged( - partition, B_PARTITION_SET_CONTENT_NAME); + partition, NULL, B_PARTITION_SET_CONTENT_NAME); } @@ -1508,7 +1520,7 @@ partition->Changed(B_PARTITION_CHANGED_TYPE); // implicit partitioning system changes return partition->Parent()->DiskSystem()->ShadowPartitionChanged( - partition, B_PARTITION_SET_TYPE); + partition->Parent(), partition, B_PARTITION_SET_TYPE); } @@ -1545,7 +1557,7 @@ partition->Changed(B_PARTITION_CHANGED_PARAMETERS); // implicit partitioning system changes error = partition->Parent()->DiskSystem() - ->ShadowPartitionChanged(partition, + ->ShadowPartitionChanged(partition->Parent(), partition, B_PARTITION_SET_PARAMETERS); } } @@ -1588,7 +1600,7 @@ partition->Changed(B_PARTITION_CHANGED_CONTENT_PARAMETERS); // implicit content disk system changes error = partition->DiskSystem()->ShadowPartitionChanged( - partition, B_PARTITION_SET_CONTENT_PARAMETERS); + partition, NULL, B_PARTITION_SET_CONTENT_PARAMETERS); } } } @@ -1679,7 +1691,7 @@ // implicit content disk system changes return partition->DiskSystem()->ShadowPartitionChanged( - partition, B_PARTITION_INITIALIZE); + partition, NULL, B_PARTITION_INITIALIZE); } @@ -1749,16 +1761,16 @@ } // set the parameters child->SetOffset(offset); - child->SetSize(offset); + child->SetSize(size); error = child->SetType(type); } if (!error) { - error = partition->SetParameters(parameters); + error = child->SetParameters(parameters); } if (!error) { // implicit partitioning system changes error = partition->DiskSystem()->ShadowPartitionChanged( - partition, B_PARTITION_CREATE_CHILD); + partition, child, B_PARTITION_CREATE_CHILD); } } } From axeld at mail.berlios.de Sun Oct 7 19:20:29 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sun, 7 Oct 2007 19:20:29 +0200 Subject: [Haiku-commits] r22476 - haiku/trunk/src/kits/interface Message-ID: <200710071720.l97HKTvb000824@sheep.berlios.de> Author: axeld Date: 2007-10-07 19:20:28 +0200 (Sun, 07 Oct 2007) New Revision: 22476 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22476&view=rev Modified: haiku/trunk/src/kits/interface/MenuItem.cpp Log: fTriggerIndex was still a byte index in BMenuItem::SetTrigger() - this one fixes bug #1506 once and for all :-) Modified: haiku/trunk/src/kits/interface/MenuItem.cpp =================================================================== --- haiku/trunk/src/kits/interface/MenuItem.cpp 2007-10-07 15:39:35 UTC (rev 22475) +++ haiku/trunk/src/kits/interface/MenuItem.cpp 2007-10-07 17:20:28 UTC (rev 22476) @@ -265,7 +265,7 @@ pos = strchr(Label(), trigger); } if (pos != NULL) { - fTriggerIndex = pos - Label(); + fTriggerIndex = UTF8CountChars(Label(), pos - Label()); fTrigger = tolower(UTF8ToCharCode(&pos)); } else { fTrigger = 0; From axeld at mail.berlios.de Sun Oct 7 19:22:31 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sun, 7 Oct 2007 19:22:31 +0200 Subject: [Haiku-commits] r22477 - haiku/trunk/src/tests/kits/interface Message-ID: <200710071722.l97HMVsv000912@sheep.berlios.de> Author: axeld Date: 2007-10-07 19:22:30 +0200 (Sun, 07 Oct 2007) New Revision: 22477 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22477&view=rev Modified: haiku/trunk/src/tests/kits/interface/MenuTriggerTest.cpp Log: Added another test case to the menu trigger test that could reproduce the last problem of BMenuItem::SetTrigger() that got fixed in r22476 (see bug #1506 for the details). Modified: haiku/trunk/src/tests/kits/interface/MenuTriggerTest.cpp =================================================================== --- haiku/trunk/src/tests/kits/interface/MenuTriggerTest.cpp 2007-10-07 17:20:28 UTC (rev 22476) +++ haiku/trunk/src/tests/kits/interface/MenuTriggerTest.cpp 2007-10-07 17:22:30 UTC (rev 22477) @@ -29,10 +29,10 @@ : BWindow(BRect(100, 100, 400, 400), "Menu Trigger Test", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS) { - BMenuBar *bar = new BMenuBar(BRect(0, 0, 10, 10), "menuBar"); + BMenuBar* bar = new BMenuBar(BRect(0, 0, 10, 10), "menuBar"); AddChild(bar); - BMenu *menu = new BMenu("File"); + BMenu* menu = new BMenu("File"); menu->AddItem(new BMenuItem("Bart", NULL)); menu->AddItem(new BMenuItem("bart", NULL)); menu->AddItem(new BMenuItem("bart", NULL)); @@ -51,7 +51,12 @@ menu->AddItem(new BMenuItem("3 a", NULL)); menu->AddItem(new BMenuItem("3 a?a", NULL)); bar->AddItem(menu); - + + menu = new BMenu("Extra"); + BMenuItem* item = new BMenuItem("\xe3\x81\x82 haiku", NULL); + item->SetTrigger('h'); + menu->AddItem(item); + bar->AddItem(menu); } Window::~Window() From korli at mail.berlios.de Sun Oct 7 21:52:25 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Sun, 7 Oct 2007 21:52:25 +0200 Subject: [Haiku-commits] r22478 - haiku/trunk/src/system/boot/platform/openfirmware Message-ID: <200710071952.l97JqPtV008707@sheep.berlios.de> Author: korli Date: 2007-10-07 21:52:24 +0200 (Sun, 07 Oct 2007) New Revision: 22478 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22478&view=rev Modified: haiku/trunk/src/system/boot/platform/openfirmware/Jamfile haiku/trunk/src/system/boot/platform/openfirmware/debug.c Log: added BOOT_MODE define instead of adding dprintf_no_syslog() Modified: haiku/trunk/src/system/boot/platform/openfirmware/Jamfile =================================================================== --- haiku/trunk/src/system/boot/platform/openfirmware/Jamfile 2007-10-07 17:22:30 UTC (rev 22477) +++ haiku/trunk/src/system/boot/platform/openfirmware/Jamfile 2007-10-07 19:52:24 UTC (rev 22478) @@ -1,6 +1,6 @@ SubDir HAIKU_TOP src system boot platform openfirmware ; -SubDirC++Flags -fno-rtti ; +SubDirC++Flags -D_BOOT_MODE -fno-rtti ; KernelMergeObject boot_platform_openfirmware.o : console.cpp Modified: haiku/trunk/src/system/boot/platform/openfirmware/debug.c =================================================================== --- haiku/trunk/src/system/boot/platform/openfirmware/debug.c 2007-10-07 17:22:30 UTC (rev 22477) +++ haiku/trunk/src/system/boot/platform/openfirmware/debug.c 2007-10-07 19:52:24 UTC (rev 22478) @@ -39,14 +39,3 @@ va_end(list); } - -void -dprintf_no_syslog(const char *format, ...) -{ - va_list list; - - va_start(list, format); - vprintf(format, list); - va_end(list); -} - From korli at users.berlios.de Sun Oct 7 21:53:17 2007 From: korli at users.berlios.de (=?ISO-8859-1?Q?J=E9r=F4me_Duval?=) Date: Sun, 7 Oct 2007 21:53:17 +0200 Subject: [Haiku-commits] r22464 - haiku/trunk/src/system/boot/platform/openfirmware In-Reply-To: <20071006211143.1512.2@cs.tu-berlin.de> References: <200710061840.l96IeXnD005209@sheep.berlios.de> <20071006211143.1512.2@cs.tu-berlin.de> Message-ID: 2007/10/6, Ingo Weinhold : > > It should not be needed. If it is, that part is apparently not compiled with > the _BOOT_MODE macro defined. > It is used here : src/system/boot/platform/openfirmware/devices.cpp It was fixed in 22478. Bye, J?rome From bonefish at mail.berlios.de Mon Oct 8 00:43:42 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Mon, 8 Oct 2007 00:43:42 +0200 Subject: [Haiku-commits] r22479 - haiku/trunk/src/system/libroot/posix/unistd Message-ID: <200710072243.l97Mhg8e016123@sheep.berlios.de> Author: bonefish Date: 2007-10-08 00:43:41 +0200 (Mon, 08 Oct 2007) New Revision: 22479 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22479&view=rev Modified: haiku/trunk/src/system/libroot/posix/unistd/lseek.c Log: POSIX functions return their error codes via errno and so does lseek(). Modified: haiku/trunk/src/system/libroot/posix/unistd/lseek.c =================================================================== --- haiku/trunk/src/system/libroot/posix/unistd/lseek.c 2007-10-07 19:52:24 UTC (rev 22478) +++ haiku/trunk/src/system/libroot/posix/unistd/lseek.c 2007-10-07 22:43:41 UTC (rev 22479) @@ -4,11 +4,19 @@ */ #include + +#include + #include off_t lseek(int fd, off_t pos, int whence) { - return _kern_seek(fd, pos, whence); + off_t result = _kern_seek(fd, pos, whence); + if (result < 0) { + errno = result; + return -1; + } + return result; } From bonefish at mail.berlios.de Mon Oct 8 00:51:42 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Mon, 8 Oct 2007 00:51:42 +0200 Subject: [Haiku-commits] r22480 - haiku/trunk/src/system/kernel/fs Message-ID: <200710072251.l97MpgxG022613@sheep.berlios.de> Author: bonefish Date: 2007-10-08 00:51:41 +0200 (Mon, 08 Oct 2007) New Revision: 22480 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22480&view=rev Modified: haiku/trunk/src/system/kernel/fs/vfs.cpp Log: Some types of files cannot be seeked and we need to fail in those cases. We actually need to fail for sockets, too, but until I'm mistaken, we can't identify them in the VFS. Fixes bug #1539. Modified: haiku/trunk/src/system/kernel/fs/vfs.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/vfs.cpp 2007-10-07 22:43:41 UTC (rev 22479) +++ haiku/trunk/src/system/kernel/fs/vfs.cpp 2007-10-07 22:51:41 UTC (rev 22480) @@ -3842,8 +3842,33 @@ off_t offset; FUNCTION(("file_seek(pos = %Ld, seekType = %d)\n", pos, seekType)); - // ToDo: seek should fail for pipes and FIFOs... + // stat() the node + struct vnode *vnode = descriptor->u.vnode; + if (FS_CALL(vnode, read_stat) == NULL) + return EOPNOTSUPP; + + struct stat stat; + status_t status = FS_CALL(vnode, read_stat)(vnode->mount->cookie, + vnode->private_node, &stat); + if (status < B_OK) + return status; + + // some kinds of files are not seekable + switch (stat.st_mode & S_IFMT) { + case S_IFIFO: + return ESPIPE; +// TODO: We don't catch sockets here, but they are not seekable either (ESPIPE)! + // The Open Group Base Specs don't mention any file types besides pipes, + // fifos, and sockets specially, so we allow seeking them. + case S_IFREG: + case S_IFBLK: + case S_IFDIR: + case S_IFLNK: + case S_IFCHR: + break; + } + switch (seekType) { case SEEK_SET: offset = 0; @@ -3852,21 +3877,8 @@ offset = descriptor->pos; break; case SEEK_END: - { - struct vnode *vnode = descriptor->u.vnode; - struct stat stat; - status_t status; - - if (FS_CALL(vnode, read_stat) == NULL) - return EOPNOTSUPP; - - status = FS_CALL(vnode, read_stat)(vnode->mount->cookie, vnode->private_node, &stat); - if (status < B_OK) - return status; - offset = stat.st_size; break; - } default: return B_BAD_VALUE; } From bonefish at mail.berlios.de Mon Oct 8 03:33:47 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Mon, 8 Oct 2007 03:33:47 +0200 Subject: [Haiku-commits] r22481 - in haiku/trunk: headers/private/storage src/kits/storage Message-ID: <200710080133.l981XlCC008927@sheep.berlios.de> Author: bonefish Date: 2007-10-08 03:33:46 +0200 (Mon, 08 Oct 2007) New Revision: 22481 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22481&view=rev Added: haiku/trunk/headers/private/storage/DiskSystemAddOn.h haiku/trunk/src/kits/storage/DiskSystemAddOn.cpp Modified: haiku/trunk/src/kits/storage/Jamfile Log: First draft of the userland disk system add-on interface. A good deal of functionality of the kernel add-ons will be moved into userland, which will simplify the kernel-side significantly. Added: haiku/trunk/headers/private/storage/DiskSystemAddOn.h =================================================================== --- haiku/trunk/headers/private/storage/DiskSystemAddOn.h 2007-10-07 22:51:41 UTC (rev 22480) +++ haiku/trunk/headers/private/storage/DiskSystemAddOn.h 2007-10-08 01:33:46 UTC (rev 22481) @@ -0,0 +1,121 @@ +/* + * Copyright 2007, Ingo Weinhold, bonefish at users.sf.net. + * Distributed under the terms of the MIT License. + */ +#ifndef _DISK_SYSTEM_ADD_ON_H +#define _DISK_SYSTEM_ADD_ON_H + +#include +#include + + +class BList; +class BMutablePartition; +class BPartitionHandle; +class BPartitioningInfo; + + +class BDiskSystemAddOn { +public: + BDiskSystemAddOn(const char* name, + uint32 flags); + virtual ~BDiskSystemAddOn(); + + const char* Name() const; + uint32 Flags() const; + + virtual status_t CreatePartitionHandle( + BMutablePartition* partition, + BPartitionHandle** handle) = 0; + + virtual bool CanInitialize(BMutablePartition* partition); + virtual bool ValidateInitialize(BMutablePartition* partition, + BString* name, const char* parameters); + virtual status_t Initialize(BMutablePartition* partition, + const char* name, const char* parameters, + BPartitionHandle** handle); + +private: + BString fName; + uint32 fFlags; +}; + + +class BPartitionHandle { +public: + BPartitionHandle(BMutablePartition* partition); + virtual ~BPartitionHandle(); + + BMutablePartition* Partition() const; + + virtual uint32 SupportedOperations(uint32 mask); + virtual uint32 SupportedChildOperations( + BMutablePartition* child, uint32 mask); + + virtual bool SupportsInitializingChild( + BMutablePartition* child, + const char* diskSystem); + virtual bool IsSubSystemFor(BMutablePartition* child); + + virtual status_t GetNextSupportedType(BMutablePartition* child, + int32* cookie, BString* type); + // child can be NULL + virtual status_t GetTypeForContentType(const char* contentType, + BString* type); + + virtual status_t GetPartitioningInfo(BPartitioningInfo* info); + + + virtual status_t Repair(bool checkOnly); + // TODO: How is this supposed to work? + + virtual bool ValidateResize(off_t* size); + virtual bool ValidateResizeChild(BMutablePartition* child, + off_t* size); + virtual status_t Resize(off_t size); + virtual status_t ResizeChild(BMutablePartition* child, + off_t size); + + virtual bool ValidateMove(off_t* offset); + virtual bool ValidateMoveChild(BMutablePartition* child, + off_t* offset); + virtual status_t Move(off_t offset); + virtual status_t MoveChild(BMutablePartition* child, + off_t offset); + + virtual bool ValidateSetContentName(BString* name); + virtual bool ValidateSetName(BMutablePartition* child, + BString* name); + virtual status_t SetContentName(const char* name); + virtual status_t SetName(BMutablePartition* child, + const char* name); + + virtual bool ValidateSetType(BMutablePartition* child, + const char* type); + virtual status_t SetType(BMutablePartition* child, + const char* type); + + virtual bool ValidateSetContentParameters( + const char* parameters); + virtual bool ValidateSetParameters(BMutablePartition* child, + const char* parameters); + virtual status_t SetContentParameters(const char* parameters); + virtual status_t SetParameters(BMutablePartition* child, + const char* parameters); + + virtual bool ValidateCreateChild(off_t* offset, + off_t* size, const char* type, + const char* parameters); + virtual status_t CreateChild(BMutablePartition* child); + + virtual status_t DeleteChild(BMutablePartition* child); + +private: + BMutablePartition* fPartition; +}; + + +extern "C" status_t get_disk_system_add_ons(BList* addOns); + // Implemented in the add-on + +#endif // _DISK_SYSTEM_ADD_ON_H Added: haiku/trunk/src/kits/storage/DiskSystemAddOn.cpp =================================================================== --- haiku/trunk/src/kits/storage/DiskSystemAddOn.cpp 2007-10-07 22:51:41 UTC (rev 22480) +++ haiku/trunk/src/kits/storage/DiskSystemAddOn.cpp 2007-10-08 01:33:46 UTC (rev 22481) @@ -0,0 +1,333 @@ +/* + * Copyright 2007, Ingo Weinhold, bonefish at users.sf.net. + * Distributed under the terms of the MIT License. + */ + +#include + +#include + + +// #pragma mark - BDiskSystemAddOn + + +// constructor +BDiskSystemAddOn::BDiskSystemAddOn(const char* name, uint32 flags) + : fName(name), + fFlags(flags) +{ +} + + +// destructor +BDiskSystemAddOn::~BDiskSystemAddOn() +{ +} + + +// Name +const char* +BDiskSystemAddOn::Name() const +{ + return fName.String(); +} + + +// Flags +uint32 +BDiskSystemAddOn::Flags() const +{ + return fFlags; +} + + +// CanInitialize +bool +BDiskSystemAddOn::CanInitialize(BMutablePartition* partition) +{ + return false; +} + + +// ValidateInitialize +bool +BDiskSystemAddOn::ValidateInitialize(BMutablePartition* partition, + BString* name, const char* parameters) +{ + return false; +} + + +// Initialize +status_t +BDiskSystemAddOn::Initialize(BMutablePartition* partition, const char* name, + const char* parameters, BPartitionHandle** handle) +{ + return B_NOT_SUPPORTED; +} + + +// #pragma mark - BPartitionHandle + + +// constructor +BPartitionHandle::BPartitionHandle(BMutablePartition* partition) + : fPartition(partition) +{ +} + + +// destructor +BPartitionHandle::~BPartitionHandle() +{ +} + + +// Partition +BMutablePartition* +BPartitionHandle::Partition() const +{ + return fPartition; +} + + +// SupportedOperations +uint32 +BPartitionHandle::SupportedOperations(uint32 mask) +{ + return 0; +} + + +// SupportedChildOperations +uint32 +BPartitionHandle::SupportedChildOperations(BMutablePartition* child, + uint32 mask) +{ + return 0; +} + + +// SupportsInitializingChild +bool +BPartitionHandle::SupportsInitializingChild(BMutablePartition* child, + const char* diskSystem) +{ + return false; +} + + +// IsSubSystemFor +bool +BPartitionHandle::IsSubSystemFor(BMutablePartition* child) +{ + return false; +} + + +// GetNextSupportedType +status_t +BPartitionHandle::GetNextSupportedType(BMutablePartition* child, int32* cookie, + BString* type) +{ + return B_ENTRY_NOT_FOUND; +} + + +// GetTypeForContentType +status_t +BPartitionHandle::GetTypeForContentType(const char* contentType, BString* type) +{ + return B_NOT_SUPPORTED; +} + + +// GetPartitioningInfo +status_t +BPartitionHandle::GetPartitioningInfo(BPartitioningInfo* info) +{ + return B_NOT_SUPPORTED; +} + + +// Repair +status_t +BPartitionHandle::Repair(bool checkOnly) +{ + return B_NOT_SUPPORTED; +} + + +// ValidateResize +bool +BPartitionHandle::ValidateResize(off_t* size) +{ + return false; +} + + +// ValidateResizeChild +bool +BPartitionHandle::ValidateResizeChild(BMutablePartition* child, off_t* size) +{ + return false; +} + + +// Resize +status_t +BPartitionHandle::Resize(off_t size) +{ + return B_NOT_SUPPORTED; +} + + +// ResizeChild +status_t +BPartitionHandle::ResizeChild(BMutablePartition* child, off_t size) +{ + return B_NOT_SUPPORTED; +} + + +// ValidateMove +bool +BPartitionHandle::ValidateMove(off_t* offset) +{ + // Usually moving a disk system is a no-op for the content disk system, + // so we default to true here. + return true; +} + + +// ValidateMoveChild +bool +BPartitionHandle::ValidateMoveChild(BMutablePartition* child, off_t* offset) +{ + return false; +} + + +// Move +status_t +BPartitionHandle::Move(off_t offset) +{ + // Usually moving a disk system is a no-op for the content disk system, + // so we default to OK here. + return B_OK; +} + + +// MoveChild +status_t +BPartitionHandle::MoveChild(BMutablePartition* child, off_t offset) +{ + return B_NOT_SUPPORTED; +} + + +// ValidateSetContentName +bool +BPartitionHandle::ValidateSetContentName(BString* name) +{ + return false; +} + + +// ValidateSetName +bool +BPartitionHandle::ValidateSetName(BMutablePartition* child, BString* name) +{ + return false; +} + + +// SetContentName +status_t +BPartitionHandle::SetContentName(const char* name) +{ + return B_NOT_SUPPORTED; +} + + +// SetName +status_t +BPartitionHandle::SetName(BMutablePartition* child, const char* name) +{ + return B_NOT_SUPPORTED; +} + + +// ValidateSetType +bool +BPartitionHandle::ValidateSetType(BMutablePartition* child, const char* type) +{ + return false; +} + + +// SetType +status_t +BPartitionHandle::SetType(BMutablePartition* child, const char* type) +{ + return B_NOT_SUPPORTED; +} + + +// ValidateSetContentParameters +bool +BPartitionHandle::ValidateSetContentParameters(const char* parameters) +{ + return false; +} + + +// ValidateSetParameters +bool +BPartitionHandle::ValidateSetParameters(BMutablePartition* child, + const char* parameters) +{ + return false; +} + + +// SetContentParameters +status_t +BPartitionHandle::SetContentParameters(const char* parameters) +{ + return B_NOT_SUPPORTED; +} + + +// SetParameters +status_t +BPartitionHandle::SetParameters(BMutablePartition* child, + const char* parameters) +{ + return B_NOT_SUPPORTED; +} + + +// ValidateCreateChild +bool +BPartitionHandle::ValidateCreateChild(off_t* offset, off_t* size, + const char* type, const char* parameters) +{ + return false; +} + + +// CreateChild +status_t +BPartitionHandle::CreateChild(BMutablePartition* child) +{ + return B_NOT_SUPPORTED; +} + + +// DeleteChild +status_t +BPartitionHandle::DeleteChild(BMutablePartition* child) +{ + return B_NOT_SUPPORTED; +} Modified: haiku/trunk/src/kits/storage/Jamfile =================================================================== --- haiku/trunk/src/kits/storage/Jamfile 2007-10-07 22:51:41 UTC (rev 22480) +++ haiku/trunk/src/kits/storage/Jamfile 2007-10-08 01:33:46 UTC (rev 22481) @@ -78,6 +78,7 @@ DiskDeviceTypes.cpp DiskDeviceVisitor.cpp DiskSystem.cpp + DiskSystemAddOn.cpp Partition.cpp PartitioningInfo.cpp ; From axeld at mail.berlios.de Mon Oct 8 10:25:48 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 8 Oct 2007 10:25:48 +0200 Subject: [Haiku-commits] r22482 - haiku/trunk/src/system/kernel/cache Message-ID: <200710080825.l988PmTS011097@sheep.berlios.de> Author: axeld Date: 2007-10-08 10:25:47 +0200 (Mon, 08 Oct 2007) New Revision: 22482 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22482&view=rev Modified: haiku/trunk/src/system/kernel/cache/block_allocator.cpp Log: The block allocator needs to reserve pages, too, when it maps pages. Modified: haiku/trunk/src/system/kernel/cache/block_allocator.cpp =================================================================== --- haiku/trunk/src/system/kernel/cache/block_allocator.cpp 2007-10-08 01:33:46 UTC (rev 22481) +++ haiku/trunk/src/system/kernel/cache/block_allocator.cpp 2007-10-08 08:25:47 UTC (rev 22482) @@ -363,6 +363,10 @@ vm_address_space *addressSpace = vm_kernel_address_space(); vm_translation_map *map = &addressSpace->translation_map; + size_t reservePages = map->ops->map_max_pages_need(map, + 0, numPages * B_PAGE_SIZE); + + vm_page_reserve_pages(reservePages); map->ops->lock(map); for (uint32 i = 0; i < numPages; i++) { @@ -372,6 +376,7 @@ } map->ops->unlock(map); + vm_page_unreserve_pages(reservePages); chunks[chunk].mapped = true; } From axeld at pinc-software.de Mon Oct 8 14:08:24 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Mon, 08 Oct 2007 14:08:24 +0200 CEST Subject: [Haiku-commits] =?iso-8859-15?q?r22481_-_in_haiku/trunk=3A_header?= =?iso-8859-15?q?s/private/storage_src/kits/storage?= In-Reply-To: <200710080133.l981XlCC008927@sheep.berlios.de> Message-ID: <15672817992-BeMail@zon> bonefish at BerliOS wrote: > +class BPartitionHandle { BPartitionHandle? Isn't there a better distinction between this and BPartition? Or is this only a temporary name? Bye, Axel. From korli at users.berlios.de Mon Oct 8 14:36:17 2007 From: korli at users.berlios.de (=?ISO-8859-1?Q?J=E9r=F4me_Duval?=) Date: Mon, 8 Oct 2007 14:36:17 +0200 Subject: [Haiku-commits] r22480 - haiku/trunk/src/system/kernel/fs In-Reply-To: <200710072251.l97MpgxG022613@sheep.berlios.de> References: <200710072251.l97MpgxG022613@sheep.berlios.de> Message-ID: Hi Ingo, 2007/10/8, bonefish at BerliOS : > We actually need to fail for sockets, too, but until I'm mistaken, we > can't identify them in the VFS. Fixes bug #1539. > Sockets should be typed S_IFSOCK in the POSIX extension. http://www.opengroup.org/onlinepubs/009695399/basedefs/sys/stat.h.html Bye, J?r?me From bonefish at cs.tu-berlin.de Mon Oct 8 15:05:11 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Mon, 08 Oct 2007 15:05:11 +0200 Subject: [Haiku-commits] r22481 - in haiku/trunk: headers/private/storage src/kits/storage In-Reply-To: <15672817992-BeMail@zon> References: <15672817992-BeMail@zon> Message-ID: <20071008150511.519.1@cs.tu-berlin.de> On 2007-10-08 at 14:08:24 [+0200], Axel D?rfler wrote: > bonefish at BerliOS wrote: > > +class BPartitionHandle { > > BPartitionHandle? Isn't there a better distinction between this and > BPartition? Or is this only a temporary name? It's the disk system's representation of a partition. If you have a better name, I'll be glad to change it. BTW, the name chaos will increase even more. I plan to use a delegate-like approach for BPartition. It won't implement much functionality by itself anymore, but delegate it to another object. Normally, when representing the actual state in the kernel, this will be a BImmutablePartition object. When switching to editing mode (I would require to do that explicitly -- that would be the point when the user add-ons can be loaded) it will be replaced by a BMutablePartition object, which will interface with the disk system add-ons. Alas, a name for the base class is needed, and I'm considering BPartitionDelegate and BPartitionBase. Name suggestions are welcome. :-) CU, Ingo From bonefish at cs.tu-berlin.de Mon Oct 8 15:13:43 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Mon, 08 Oct 2007 15:13:43 +0200 Subject: [Haiku-commits] r22480 - haiku/trunk/src/system/kernel/fs In-Reply-To: References: <200710072251.l97MpgxG022613@sheep.berlios.de> Message-ID: <20071008151343.1155.2@cs.tu-berlin.de> On 2007-10-08 at 14:36:17 [+0200], J?r?me Duval wrote: > 2007/10/8, bonefish at BerliOS : > > We actually need to fail for sockets, too, but until I'm mistaken, we > > can't identify them in the VFS. Fixes bug #1539. > > Sockets should be typed S_IFSOCK in the POSIX extension. Yep, the problem is though, that our sockets are actually FDs to the net stack driver device. Consequently the devfs will report them to be S_IFCHR or S_IFBLK. There's a mechanism missing for device drivers to report different stats. CU, Ingo From axeld at mail.berlios.de Mon Oct 8 15:56:50 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 8 Oct 2007 15:56:50 +0200 Subject: [Haiku-commits] r22483 - haiku/trunk/src/system/kernel/vm Message-ID: <200710081356.l98Duo6a018034@sheep.berlios.de> Author: axeld Date: 2007-10-08 15:56:49 +0200 (Mon, 08 Oct 2007) New Revision: 22483 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22483&view=rev Modified: haiku/trunk/src/system/kernel/vm/vm_low_memory.cpp Log: * B_LOW_MEMORY_NOTE now starts earlier, at 8 MB left. * vm_low_memory_state() now periodically recomputes the state in case the low memory thread is waiting for something. Modified: haiku/trunk/src/system/kernel/vm/vm_low_memory.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_low_memory.cpp 2007-10-08 08:25:47 UTC (rev 22482) +++ haiku/trunk/src/system/kernel/vm/vm_low_memory.cpp 2007-10-08 13:56:49 UTC (rev 22483) @@ -40,12 +40,13 @@ static const bigtime_t kWarnMemoryInterval = 500000; // 0.5 secs // page limits -static const size_t kNoteLimit = 1024; +static const size_t kNoteLimit = 2048; static const size_t kWarnLimit = 256; static const size_t kCriticalLimit = 32; static int32 sLowMemoryState = B_NO_LOW_MEMORY; +static bigtime_t sLastMeasurement; static mutex sLowMemoryMutex; static sem_id sLowMemoryWaitSem; @@ -69,6 +70,8 @@ static int32 compute_state(void) { + sLastMeasurement = system_time(); + uint32 freePages = vm_page_num_free_pages(); if (freePages >= kNoteLimit) return B_NO_LOW_MEMORY; @@ -148,6 +151,9 @@ int32 vm_low_memory_state(void) { + if (system_time() - sLastMeasurement > 500000) + sLowMemoryState = compute_state(); + return sLowMemoryState; } From korli at users.berlios.de Mon Oct 8 16:37:59 2007 From: korli at users.berlios.de (=?ISO-8859-1?Q?J=E9r=F4me_Duval?=) Date: Mon, 8 Oct 2007 16:37:59 +0200 Subject: [Haiku-commits] r22480 - haiku/trunk/src/system/kernel/fs In-Reply-To: <20071008151343.1155.2@cs.tu-berlin.de> References: <200710072251.l97MpgxG022613@sheep.berlios.de> <20071008151343.1155.2@cs.tu-berlin.de> Message-ID: 2007/10/8, Ingo Weinhold : > > On 2007-10-08 at 14:36:17 [+0200], J?r?me Duval > wrote: > > 2007/10/8, bonefish at BerliOS : > > > We actually need to fail for sockets, too, but until I'm mistaken, we > > > can't identify them in the VFS. Fixes bug #1539. > > > > Sockets should be typed S_IFSOCK in the POSIX extension. > > Yep, the problem is though, that our sockets are actually FDs to the net > stack driver device. Consequently the devfs will report them to be S_IFCHR > or S_IFBLK. There's a mechanism missing for device drivers to report > different stats. > Then this deserves an enhancement request :) Bye, J?r?me From bonefish at mail.berlios.de Mon Oct 8 17:32:02 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Mon, 8 Oct 2007 17:32:02 +0200 Subject: [Haiku-commits] r22484 - haiku/trunk/src/system/libroot/posix/unistd Message-ID: <200710081532.l98FW2D0010454@sheep.berlios.de> Author: bonefish Date: 2007-10-08 17:32:02 +0200 (Mon, 08 Oct 2007) New Revision: 22484 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22484&view=rev Modified: haiku/trunk/src/system/libroot/posix/unistd/alarm.c Log: Patch by Vasilis Kaoutsis: Return error code via errno. Modified: haiku/trunk/src/system/libroot/posix/unistd/alarm.c =================================================================== --- haiku/trunk/src/system/libroot/posix/unistd/alarm.c 2007-10-08 13:56:49 UTC (rev 22483) +++ haiku/trunk/src/system/libroot/posix/unistd/alarm.c 2007-10-08 15:32:02 UTC (rev 22484) @@ -15,12 +15,17 @@ alarm(unsigned int sec) { struct itimerval value, oldValue; + int result; value.it_interval.tv_sec = value.it_interval.tv_usec = 0; value.it_value.tv_sec = sec; value.it_value.tv_usec = 0; - if (setitimer(ITIMER_REAL, &value, &oldValue) < 0) + + result = setitimer(ITIMER_REAL, &value, &oldValue); + if (result < 0) { + errno = result; return -1; + } if (oldValue.it_value.tv_usec) oldValue.it_value.tv_sec++; From axeld at mail.berlios.de Mon Oct 8 18:06:33 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 8 Oct 2007 18:06:33 +0200 Subject: [Haiku-commits] r22485 - in haiku/trunk: headers/private/kernel src/system/kernel/cache src/system/kernel/fs Message-ID: <200710081606.l98G6Xtj012742@sheep.berlios.de> Author: axeld Date: 2007-10-08 18:06:32 +0200 (Mon, 08 Oct 2007) New Revision: 22485 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22485&view=rev Modified: haiku/trunk/headers/private/kernel/vfs.h haiku/trunk/src/system/kernel/cache/file_cache.cpp haiku/trunk/src/system/kernel/cache/vnode_store.cpp haiku/trunk/src/system/kernel/fs/vfs.cpp Log: * Added a "canWait" argument to vfs_get_vnode() - you can use this to ignore busy vnodes. * dir_create_entry_ref() used get_vnode() incorrectly (and could therefore potentially prevent a file system from doing proper locking when called from the kernel). * The vnode_store now uses this for its acquire_unreferenced_ref() implementation (and therefore for the page writer). * read_into_cache() and write_to_cache() were still marked inline. * The system will now wait 10 secs for a busy vnode before returning an error. * It will also no longer panic in that case. Modified: haiku/trunk/headers/private/kernel/vfs.h =================================================================== --- haiku/trunk/headers/private/kernel/vfs.h 2007-10-08 15:32:02 UTC (rev 22484) +++ haiku/trunk/headers/private/kernel/vfs.h 2007-10-08 16:06:32 UTC (rev 22485) @@ -81,7 +81,8 @@ int vfs_get_vnode_from_fd(int fd, bool kernel, struct vnode **_vnode); status_t vfs_get_vnode_from_path(const char *path, bool kernel, struct vnode **_vnode); -status_t vfs_get_vnode(dev_t mountID, ino_t vnodeID, struct vnode **_vnode); +status_t vfs_get_vnode(dev_t mountID, ino_t vnodeID, bool canWait, + struct vnode **_vnode); status_t vfs_entry_ref_to_vnode(dev_t mountID, ino_t directoryID, const char *name, struct vnode **_vnode); void vfs_vnode_to_node_ref(struct vnode *vnode, dev_t *_mountID, Modified: haiku/trunk/src/system/kernel/cache/file_cache.cpp =================================================================== --- haiku/trunk/src/system/kernel/cache/file_cache.cpp 2007-10-08 15:32:02 UTC (rev 22484) +++ haiku/trunk/src/system/kernel/cache/file_cache.cpp 2007-10-08 16:06:32 UTC (rev 22485) @@ -518,13 +518,13 @@ The cache_ref lock must be hold when calling this function; during operation it will unlock the cache, though. */ -static inline status_t +static status_t read_into_cache(file_cache_ref *ref, off_t offset, size_t numBytes, int32 pageOffset, addr_t buffer, size_t bufferSize, size_t lastReservedPages, size_t reservePages) { TRACE(("read_into_cache(offset = %Ld, size = %lu, pageOffset = %ld, buffer " - "= %#lx, bufferSize = %lu\n", offset, size, pageOffset, buffer, + "= %#lx, bufferSize = %lu\n", offset, numBytes, pageOffset, buffer, bufferSize)); vm_cache *cache = ref->cache; @@ -630,7 +630,7 @@ though, if only a partial page gets written. The same restrictions apply. */ -static inline status_t +static status_t write_to_cache(file_cache_ref *ref, off_t offset, size_t numBytes, int32 pageOffset, addr_t buffer, size_t bufferSize, size_t lastReservedPages, size_t reservePages) @@ -1086,7 +1086,7 @@ // get the vnode for the object, this also grabs a ref to it struct vnode *vnode; - if (vfs_get_vnode(mountID, vnodeID, &vnode) != B_OK) + if (vfs_get_vnode(mountID, vnodeID, true, &vnode) != B_OK) return; cache_prefetch_vnode(vnode, offset, size); Modified: haiku/trunk/src/system/kernel/cache/vnode_store.cpp =================================================================== --- haiku/trunk/src/system/kernel/cache/vnode_store.cpp 2007-10-08 15:32:02 UTC (rev 22484) +++ haiku/trunk/src/system/kernel/cache/vnode_store.cpp 2007-10-08 16:06:32 UTC (rev 22485) @@ -88,7 +88,7 @@ { vnode_store *store = (vnode_store *)_store; struct vnode *vnode; - return vfs_get_vnode(store->device, store->inode, &vnode); + return vfs_get_vnode(store->device, store->inode, false, &vnode); } Modified: haiku/trunk/src/system/kernel/fs/vfs.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/vfs.cpp 2007-10-08 15:32:02 UTC (rev 22484) +++ haiku/trunk/src/system/kernel/fs/vfs.cpp 2007-10-08 16:06:32 UTC (rev 22485) @@ -825,21 +825,22 @@ \return \c B_OK, if everything when fine, an error code otherwise. */ static status_t -get_vnode(dev_t mountID, ino_t vnodeID, struct vnode **_vnode, int reenter) +get_vnode(dev_t mountID, ino_t vnodeID, struct vnode **_vnode, bool canWait, + int reenter) { FUNCTION(("get_vnode: mountid %ld vnid 0x%Lx %p\n", mountID, vnodeID, _vnode)); mutex_lock(&sVnodeMutex); - int32 tries = 300; - // try for 3 secs + int32 tries = 1000; + // try for 10 secs restart: struct vnode *vnode = lookup_vnode(mountID, vnodeID); if (vnode && vnode->busy) { mutex_unlock(&sVnodeMutex); - if (--tries < 0) { + if (!canWait || --tries < 0) { // vnode doesn't seem to become unbusy - panic("vnode %ld:%Ld is not becoming unbusy!\n", mountID, vnodeID); + dprintf("vnode %ld:%Ld is not becoming unbusy!\n", mountID, vnodeID); return B_BUSY; } snooze(10000); // 10 ms @@ -867,7 +868,8 @@ vnode->busy = true; mutex_unlock(&sVnodeMutex); - status = FS_CALL(vnode, get_vnode)(vnode->mount->cookie, vnodeID, &vnode->private_node, reenter); + status = FS_CALL(vnode, get_vnode)(vnode->mount->cookie, vnodeID, + &vnode->private_node, reenter); if (status == B_OK && vnode->private_node == NULL) status = B_BAD_VALUE; @@ -1422,7 +1424,7 @@ { // get the node struct vnode *node; - status_t error = get_vnode(mountID, nodeID, &node, false); + status_t error = get_vnode(mountID, nodeID, &node, true, false); if (error != B_OK) return error; @@ -1534,7 +1536,7 @@ // get the directory vnode and let vnode_path_to_vnode() do the rest struct vnode *directory; - status_t status = get_vnode(mountID, directoryID, &directory, false); + status_t status = get_vnode(mountID, directoryID, &directory, true, false); if (status < 0) return status; @@ -2532,7 +2534,7 @@ #endif // ADD_DEBUGGER_COMMANDS -// #pragma mark - public VFS API +// #pragma mark - public API for file systems extern "C" status_t @@ -2603,7 +2605,7 @@ { struct vnode *vnode; - status_t status = get_vnode(mountID, vnodeID, &vnode, true); + status_t status = get_vnode(mountID, vnodeID, &vnode, true, true); if (status < B_OK) return status; @@ -2771,11 +2773,11 @@ extern "C" status_t -vfs_get_vnode(dev_t mountID, ino_t vnodeID, struct vnode **_vnode) +vfs_get_vnode(dev_t mountID, ino_t vnodeID, bool canWait, struct vnode **_vnode) { struct vnode *vnode; - status_t status = get_vnode(mountID, vnodeID, &vnode, false); + status_t status = get_vnode(mountID, vnodeID, &vnode, canWait, false); if (status < B_OK) return status; @@ -3068,7 +3070,7 @@ { struct vnode *vnode; - status_t status = get_vnode(mountID, vnodeID, &vnode, true); + status_t status = get_vnode(mountID, vnodeID, &vnode, true, true); if (status < B_OK) return status; @@ -3697,7 +3699,7 @@ FUNCTION(("file_create_entry_ref: name = '%s', omode %x, perms %d, kernel %d\n", name, openMode, perms, kernel)); // get directory to put the new file in - status = get_vnode(mountID, directoryID, &directory, false); + status = get_vnode(mountID, directoryID, &directory, true, false); if (status < B_OK) return status; @@ -3938,7 +3940,7 @@ FUNCTION(("dir_create_entry_ref(dev = %ld, ino = %Ld, name = '%s', perms = %d)\n", mountID, parentID, name, perms)); - status = get_vnode(mountID, parentID, &vnode, kernel); + status = get_vnode(mountID, parentID, &vnode, true, false); if (status < B_OK) return status; @@ -3991,7 +3993,7 @@ if (name) status = entry_ref_to_vnode(mountID, parentID, name, &vnode); else - status = get_vnode(mountID, parentID, &vnode, false); + status = get_vnode(mountID, parentID, &vnode, true, false); if (status < B_OK) return status; @@ -4088,7 +4090,8 @@ } else { // resolve mount points struct vnode *vnode = NULL; - status_t status = get_vnode(entry->d_dev, entry->d_ino, &vnode, false); + status_t status = get_vnode(entry->d_dev, entry->d_ino, &vnode, true, + false); if (status != B_OK) return; @@ -5725,7 +5728,7 @@ // acquire a reference to the vnode - if (get_vnode(mount->id, id, &vnode, true) == B_OK) { + if (get_vnode(mount->id, id, &vnode, true, false) == B_OK) { if (previousVnode != NULL) put_vnode(previousVnode); @@ -6773,7 +6776,7 @@ status = entry_ref_to_vnode(device, inode, leaf, &vnode); leaf = NULL; } else - status = get_vnode(device, inode, &vnode, false); + status = get_vnode(device, inode, &vnode, true, false); if (status < B_OK) return status; From axeld at mail.berlios.de Mon Oct 8 18:15:56 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 8 Oct 2007 18:15:56 +0200 Subject: [Haiku-commits] r22486 - haiku/trunk/src/system/kernel/vm Message-ID: <200710081615.l98GFuEO013210@sheep.berlios.de> Author: axeld Date: 2007-10-08 18:15:56 +0200 (Mon, 08 Oct 2007) New Revision: 22486 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22486&view=rev Modified: haiku/trunk/src/system/kernel/vm/vm_daemons.cpp haiku/trunk/src/system/kernel/vm/vm_page.cpp Log: * Fixed the page_thief(): it never noticed it could not get a page. * The page_thief() will no longer steal any pages in B_LOW_MEMORY_NOTE state, only in the more serious cases. * I've disabled stealing active pages for now again; there seem to be some problems with it (either with how we do it, or with other stuff). * vm_page_schedule_write_page() now always releases the page writer semaphore, resulting in many more written pages - this isn't optimal as long as there is no I/O scheduler, but before it was much too rare when there are many dirty pages. * Customized the thread priorities a bit to make the page scanner/thief/writer experience a bit nicer with our current scheduler. * vm_page_reserve_pages() would return too early, it did not test if really enough pages are free. * Under certain circumstances, the wakeup from vm_page_reserve_pages() did not work - we now always notify in vm_page_unreserve_pages() to work around that problem. * Checked if the page reservations are done when needed and are always balanced for the whole kernel. * vm_page_allocate_page() now panics if it can't deliver a reserved page. * vm_page_allocate_page_run() can no longer steal reserved pages. * With all of those changes, I could finally copy a file in emulation, ie. the Luposian bug should finally be fixed, even though the system might still not be perfectly stable under low memory. Will do some more testing. * write_page() no longer prints something on failure. * Dumping a whole page queue will now also write the cache type of each page. Modified: haiku/trunk/src/system/kernel/vm/vm_daemons.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_daemons.cpp 2007-10-08 16:06:32 UTC (rev 22485) +++ haiku/trunk/src/system/kernel/vm/vm_daemons.cpp 2007-10-08 16:15:56 UTC (rev 22486) @@ -223,7 +223,7 @@ // create a kernel thread to select pages for pageout thread_id thread = spawn_kernel_thread(&page_daemon, "page daemon", - B_LOW_PRIORITY, NULL); + B_LOW_PRIORITY + 1, NULL); send_signal_etc(thread, SIGCONT, B_DO_NOT_RESCHEDULE); return B_OK; Modified: haiku/trunk/src/system/kernel/vm/vm_page.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_page.cpp 2007-10-08 16:06:32 UTC (rev 22485) +++ haiku/trunk/src/system/kernel/vm/vm_page.cpp 2007-10-08 16:15:56 UTC (rev 22486) @@ -375,12 +375,30 @@ if (argc == 3) { struct vm_page *page = queue->head; + const char *type = "unknown"; int i; - kprintf("page cache state wired usage\n"); + switch (page->cache->type) { + case CACHE_TYPE_RAM: + type = "RAM"; + break; + case CACHE_TYPE_DEVICE: + type = "device"; + break; + case CACHE_TYPE_VNODE: + type = "vnode"; + break; + case CACHE_TYPE_NULL: + type = "null"; + break; + default: + break; + } + + kprintf("page cache type state wired usage\n"); for (i = 0; page; i++, page = page->queue_next) { - kprintf("%p %p %8s %5d %5d\n", page, page->cache, - page_state_to_string(page->state), + kprintf("%p %p %-7s %8s %5d %5d\n", page, page->cache, + type, page_state_to_string(page->state), page->wired_count, page->usage_count); } } @@ -411,16 +429,16 @@ kprintf("wired: %lu\nmodified: %lu\nfree: %lu\nclear: %lu\n", counter[PAGE_STATE_WIRED], counter[PAGE_STATE_MODIFIED], counter[PAGE_STATE_FREE], counter[PAGE_STATE_CLEAR]); + kprintf("reserved pages: %lu\n", sReservedPages); - kprintf("\nfree_queue: %p, count = %ld\n", &sFreePageQueue, + kprintf("\nfree queue: %p, count = %ld\n", &sFreePageQueue, sFreePageQueue.count); - kprintf("clear_queue: %p, count = %ld\n", &sClearPageQueue, + kprintf("clear queue: %p, count = %ld\n", &sClearPageQueue, sClearPageQueue.count); - kprintf("modified_queue: %p, count = %ld\n", &sModifiedPageQueue, + kprintf("modified queue: %p, count = %ld\n", &sModifiedPageQueue, sModifiedPageQueue.count); - kprintf("active_queue: %p, count = %ld\n", &sActivePageQueue, + kprintf("active queue: %p, count = %ld\n", &sActivePageQueue, sActivePageQueue.count); - return 0; } @@ -612,12 +630,12 @@ vecs, 1, &length, mayBlock, fsReenter); vm_put_physical_page((addr_t)vecs[0].iov_base); - +#if 0 if (status < B_OK) { dprintf("write_page(page = %p): offset = %lx, status = %ld\n", page, page->cache_offset, status); } - +#endif return status; } @@ -751,12 +769,10 @@ default: timeout = B_INFINITE_TIMEOUT; continue; - case B_LOW_MEMORY_NOTE: - steal = 10; - score = -20; timeout = 1000000; - break; + continue; + case B_LOW_MEMORY_WARNING: steal = 50; score = -5; @@ -768,7 +784,6 @@ timeout = 100000; break; } - //dprintf("page thief running - target %ld...\n", steal); vm_page* page = NULL; bool stealActive = false, desperate = false; @@ -780,7 +795,8 @@ // find a candidate to steal from the inactive queue - for (int32 i = sActivePageQueue.count; i-- > 0;) { + int32 i = sActivePageQueue.count; + while (i-- > 0) { // move page to the tail of the queue so that we don't // scan it again directly page = dequeue_page(&sActivePageQueue); @@ -793,7 +809,7 @@ break; } - if (page == NULL) { + if (i < 0) { if (score == 0) { if (state != B_LOW_MEMORY_CRITICAL) break; @@ -805,6 +821,8 @@ score = 127; desperate = true; } else { + // TODO: for now, we never steal active pages + break; stealActive = true; score = 5; steal = 5; @@ -965,7 +983,7 @@ /*! Schedules the page writer to write back the specified \a page. - Note, however, that it doesn't do this immediately, and it might + Note, however, that it might not do this immediately, and it can well take several seconds until the page is actually written out. */ void @@ -975,8 +993,7 @@ vm_page_requeue(page, false); - release_sem_etc(sWriterWaitSem, 1, - B_RELEASE_IF_WAITING_ONLY | B_DO_NOT_RESCHEDULE); + release_sem_etc(sWriterWaitSem, 1, B_DO_NOT_RESCHEDULE); } @@ -1103,7 +1120,7 @@ sThiefWaitSem = create_sem(0, "page thief"); thread = spawn_kernel_thread(&page_writer, "page writer", - B_LOW_PRIORITY, NULL); + B_LOW_PRIORITY + 2, NULL); send_signal_etc(thread, SIGCONT, B_DO_NOT_RESCHEDULE); thread = spawn_kernel_thread(&page_thief, "page thief", @@ -1187,7 +1204,9 @@ sReservedPages -= count; - if (vm_page_num_free_pages() <= sReservedPages) + // TODO: find out why the line below won't work correctly + //if (vm_page_num_free_pages() <= sReservedPages + count) + if (!kernel_startup) sFreePageCondition.NotifyAll(); } @@ -1207,17 +1226,23 @@ sReservedPages += count; size_t freePages = vm_page_num_free_pages(); - if (sReservedPages < freePages) + if (sReservedPages <= freePages) return; ConditionVariableEntry freeConditionEntry; - freeConditionEntry.Add(&sFreePageQueue); vm_low_memory(sReservedPages - freePages); - // we need to wait until new pages become available - locker.Unlock(); + while (true) { + // we need to wait until new pages become available + freeConditionEntry.Add(&sFreePageQueue); + locker.Unlock(); + + freeConditionEntry.Wait(); - freeConditionEntry.Wait(); + locker.Lock(); + if (sReservedPages <= vm_page_num_free_pages()) + break; + } } @@ -1260,6 +1285,8 @@ } if (page == NULL) { + if (reserved) + panic("Had reserved page, but there is none!"); #ifdef DEBUG if (otherQueue->count != 0) { panic("other queue %p corrupted, count = %d\n", otherQueue, @@ -1329,13 +1356,16 @@ vm_page * vm_page_allocate_page_run(int pageState, addr_t length) { - // TODO: make sure this one doesn't steal reserved pages! vm_page *firstPage = NULL; uint32 start = 0; - cpu_status state = disable_interrupts(); - acquire_spinlock(&sPageLock); + InterruptsSpinLocker locker(sPageLock); + if (sFreePageQueue.count + sClearPageQueue.count - sReservedPages < length) { + // no free space + return NULL; + } + for (;;) { bool foundRun = true; if (start + length > sNumPages) @@ -1364,9 +1394,9 @@ start += i; } } - release_spinlock(&sPageLock); - restore_interrupts(state); + locker.Unlock(); + if (firstPage != NULL && pageState == PAGE_STATE_CLEAR) { for (uint32 i = 0; i < length; i++) { if (!sPages[start + i].is_cleared) { From axeld at pinc-software.de Mon Oct 8 18:23:37 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Mon, 08 Oct 2007 18:23:37 +0200 CEST Subject: [Haiku-commits] r22484 - haiku/trunk/src/system/libroot/posix/unistd In-Reply-To: <200710081532.l98FW2D0010454@sheep.berlios.de> Message-ID: <30985698368-BeMail@zon> bonefish at BerliOS wrote: > Log: > Patch by Vasilis Kaoutsis: Return error code via errno. setitimer() is already supposed to set errno; it's superfluous to do it again in alarm(). Bye, Axel. From revol at free.fr Mon Oct 8 18:36:39 2007 From: revol at free.fr (=?windows-1252?q?Fran=E7ois?= Revol) Date: Mon, 08 Oct 2007 18:36:39 +0200 CEST Subject: [Haiku-commits] r22480 - haiku/trunk/src/system/kernel/fs In-Reply-To: <200710072251.l97MpgxG022613@sheep.berlios.de> Message-ID: <965840831-BeMail@laptop> > Author: bonefish > Date: 2007-10-08 00:51:41 +0200 (Mon, 08 Oct 2007) > New Revision: 22480 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22480&view=rev > > Modified: > haiku/trunk/src/system/kernel/fs/vfs.cpp > Log: > Some types of files cannot be seeked and we need to fail in those > cases. > We actually need to fail for sockets, too, but until I'm mistaken, we > can't identify them in the VFS. Fixes bug #1539. Not until we get a sockfs, no. :) Fran?ois. From revol at free.fr Mon Oct 8 18:52:17 2007 From: revol at free.fr (=?windows-1252?q?Fran=E7ois?= Revol) Date: Mon, 08 Oct 2007 18:52:17 +0200 CEST Subject: [Haiku-commits] r22480 - haiku/trunk/src/system/kernel/fs In-Reply-To: Message-ID: <1903870590-BeMail@laptop> > 2007/10/8, bonefish at BerliOS : > > We actually need to fail for sockets, too, but until I'm mistaken, > > we > > can't identify them in the VFS. Fixes bug #1539. > > > > Sockets should be typed S_IFSOCK in the POSIX extension. > > http://www.opengroup.org/onlinepubs/009695399/basedefs/sys/stat.h.html > Yes but we can't do that from the api driver. We'll need a sockfs for that. I'll dig the one I wrote for BONE... Fran?ois. From kaoutsis at sch.gr Tue Oct 9 00:23:06 2007 From: kaoutsis at sch.gr (Kaoutsis) Date: Tue, 09 Oct 2007 00:23:06 Subject: [Haiku-commits] r22484 - haiku/trunk/src/system/libroot/posix/unistd In-Reply-To: <30985698368-BeMail@zon> Message-ID: <33037554218-BeMail@zoidberg> > bonefish at BerliOS wrote: > > Log: > > Patch by Vasilis Kaoutsis: Return error code via errno. > Axel wrote: > setitimer() is already supposed to set errno; it's superfluous to do > it > again in alarm(). > Yes, you are right. I check the src/system/libroot/posix/sys/itimer.c It doesn't set errno. So i guess the proper file is the itimer.c for "errno" handling, and my addition to the alarm.c should be removed. good bye, Vasilis From bonefish at cs.tu-berlin.de Mon Oct 8 21:03:07 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Mon, 08 Oct 2007 21:03:07 +0200 Subject: [Haiku-commits] r22480 - haiku/trunk/src/system/kernel/fs In-Reply-To: <1903870590-BeMail@laptop> References: <1903870590-BeMail@laptop> Message-ID: <20071008210307.2542.5@cs.tu-berlin.de> On 2007-10-08 at 18:52:17 [+0200], Fran?ois Revol wrote: > > 2007/10/8, bonefish at BerliOS : > > > We actually need to fail for sockets, too, but until I'm mistaken, > > > we > > > can't identify them in the VFS. Fixes bug #1539. > > > > > > > Sockets should be typed S_IFSOCK in the POSIX extension. > > > > http://www.opengroup.org/onlinepubs/009695399/basedefs/sys/stat.h.html > > > Yes but we can't do that from the api driver. > We'll need a sockfs for that. > I'll dig the one I wrote for BONE... It sounds a bit like overkill to do it just for that reason. I'd probably simply add an ioctl, that drivers can implement when they have special stat() requirements. CU, Ingo From axeld at pinc-software.de Mon Oct 8 21:23:53 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Mon, 08 Oct 2007 21:23:53 +0200 CEST Subject: [Haiku-commits] r22480 - haiku/trunk/src/system/kernel/fs In-Reply-To: <20071008210307.2542.5@cs.tu-berlin.de> Message-ID: <41801029623-BeMail@zon> Ingo Weinhold wrote: > On 2007-10-08 at 18:52:17 [+0200], Fran?ois Revol > wrote: > > > Sockets should be typed S_IFSOCK in the POSIX extension. > > > > > > http://www.opengroup.org/onlinepubs/009695399/basedefs/sys/stat.h.html > > > > > Yes but we can't do that from the api driver. > > We'll need a sockfs for that. > > I'll dig the one I wrote for BONE... > It sounds a bit like overkill to do it just for that reason. I'd > probably > simply add an ioctl, that drivers can implement when they have > special > stat() requirements. That would be a pretty simple solution, +1. Bye, Axel. From bonefish at mail.berlios.de Mon Oct 8 21:58:54 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Mon, 8 Oct 2007 21:58:54 +0200 Subject: [Haiku-commits] r22487 - haiku/trunk/src/system/libroot/posix/unistd Message-ID: <200710081958.l98JwsI1015915@sheep.berlios.de> Author: bonefish Date: 2007-10-08 21:58:54 +0200 (Mon, 08 Oct 2007) New Revision: 22487 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22487&view=rev Modified: haiku/trunk/src/system/libroot/posix/unistd/alarm.c Log: Reverted r22484. setitimer() already sets errno, if necessary. Modified: haiku/trunk/src/system/libroot/posix/unistd/alarm.c =================================================================== --- haiku/trunk/src/system/libroot/posix/unistd/alarm.c 2007-10-08 16:15:56 UTC (rev 22486) +++ haiku/trunk/src/system/libroot/posix/unistd/alarm.c 2007-10-08 19:58:54 UTC (rev 22487) @@ -15,17 +15,12 @@ alarm(unsigned int sec) { struct itimerval value, oldValue; - int result; value.it_interval.tv_sec = value.it_interval.tv_usec = 0; value.it_value.tv_sec = sec; value.it_value.tv_usec = 0; - - result = setitimer(ITIMER_REAL, &value, &oldValue); - if (result < 0) { - errno = result; + if (setitimer(ITIMER_REAL, &value, &oldValue) < 0) return -1; - } if (oldValue.it_value.tv_usec) oldValue.it_value.tv_sec++; From bonefish at cs.tu-berlin.de Mon Oct 8 22:05:24 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Mon, 08 Oct 2007 22:05:24 +0200 Subject: [Haiku-commits] r22484 - haiku/trunk/src/system/libroot/posix/unistd In-Reply-To: <33037554218-BeMail@zoidberg> References: <33037554218-BeMail@zoidberg> Message-ID: <20071008220524.6672.6@cs.tu-berlin.de> On 2007-10-09 at 00:23:06 [+0200], Kaoutsis wrote: > > bonefish at BerliOS wrote: > > > Log: > > > Patch by Vasilis Kaoutsis: Return error code via errno. > > > > Axel wrote: > > setitimer() is already supposed to set errno; it's superfluous to do > > it > > again in alarm(). > > > Yes, you are right. I check the src/system/libroot/posix/sys/itimer.c > It doesn't set errno. So i guess the proper file is the itimer.c for > "errno" handling, > and my addition to the alarm.c should be removed. As it looks the current implementation of setitimer() cannot fail, so it doesn't need to set errno. CU, Ingo From revol at free.fr Mon Oct 8 22:27:37 2007 From: revol at free.fr (=?windows-1252?q?Fran=E7ois?= Revol) Date: Mon, 08 Oct 2007 22:27:37 +0200 CEST Subject: [Haiku-commits] r22480 - haiku/trunk/src/system/kernel/fs In-Reply-To: <20071008210307.2542.5@cs.tu-berlin.de> Message-ID: <514030561-BeMail@laptop> > > > > > Yes but we can't do that from the api driver. > > We'll need a sockfs for that. > > I'll dig the one I wrote for BONE... > > It sounds a bit like overkill to do it just for that reason. I'd > probably > simply add an ioctl, that drivers can implement when they have > special > stat() requirements. Not more than pipefs... It's cleaner by design, no ioctl hack needed. It could also simplify later if we want to move the socket calls to their own syscall(s) (linux has a single one muxing them), we'll just add a hook in the fs api. Fran?ois. From axeld at mail.berlios.de Mon Oct 8 23:18:19 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 8 Oct 2007 23:18:19 +0200 Subject: [Haiku-commits] r22488 - haiku/trunk/src/bin/bash/lib/readline Message-ID: <200710082118.l98LIJuq021061@sheep.berlios.de> Author: axeld Date: 2007-10-08 23:18:19 +0200 (Mon, 08 Oct 2007) New Revision: 22488 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22488&view=rev Modified: haiku/trunk/src/bin/bash/lib/readline/keymaps.c haiku/trunk/src/bin/bash/lib/readline/readline.c Log: Changed defaults in readline to be more useful. This fixes bug #1540. Alternatively, we could add an inputrc file - this would have the advantage that other apps using readline built-in would have those, too. OTOH this really should be in the defaults, too, IMO (ie. we could do both). Opinions welcome :-) Modified: haiku/trunk/src/bin/bash/lib/readline/keymaps.c =================================================================== --- haiku/trunk/src/bin/bash/lib/readline/keymaps.c 2007-10-08 19:58:54 UTC (rev 22487) +++ haiku/trunk/src/bin/bash/lib/readline/keymaps.c 2007-10-08 21:18:19 UTC (rev 22488) @@ -105,7 +105,7 @@ newmap[i].function = rl_insert; newmap[TAB].function = rl_insert; - newmap[RUBOUT].function = rl_rubout; /* RUBOUT == 127 */ + newmap[RUBOUT].function = rl_delete; /* RUBOUT == 127 */ newmap[CTRL('H')].function = rl_rubout; #if KEYMAP_SIZE > 128 Modified: haiku/trunk/src/bin/bash/lib/readline/readline.c =================================================================== --- haiku/trunk/src/bin/bash/lib/readline/readline.c 2007-10-08 19:58:54 UTC (rev 22487) +++ haiku/trunk/src/bin/bash/lib/readline/readline.c 2007-10-08 21:18:19 UTC (rev 22488) @@ -885,12 +885,23 @@ _rl_keymap = xkeymap; } +/* Bind some default keys in the standard keymap. */ +static void +bind_default_keys_internal () +{ + _rl_bind_if_unbound ("\033[[", rl_end_of_line); + _rl_bind_if_unbound ("\033[@", rl_beg_of_line); + _rl_bind_if_unbound ("\033[5~", rl_history_search_backward); + _rl_bind_if_unbound ("\033[6~", rl_history_search_forward); +} + /* Try and bind the common arrow key prefixes after giving termcap and the inputrc file a chance to bind them and create `real' keymaps for the arrow key prefix. */ static void bind_arrow_keys () { + bind_default_keys_internal (); bind_arrow_keys_internal (emacs_standard_keymap); #if defined (VI_MODE) From jackburton at mail.berlios.de Mon Oct 8 23:46:36 2007 From: jackburton at mail.berlios.de (jackburton at BerliOS) Date: Mon, 8 Oct 2007 23:46:36 +0200 Subject: [Haiku-commits] r22489 - in haiku/trunk: headers/os/interface src/kits/interface Message-ID: <200710082146.l98LkaTO022521@sheep.berlios.de> Author: jackburton Date: 2007-10-08 23:46:35 +0200 (Mon, 08 Oct 2007) New Revision: 22489 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22489&view=rev Modified: haiku/trunk/headers/os/interface/TextView.h haiku/trunk/src/kits/interface/TextView.cpp Log: I was wrong after all. InsertText() doesn't call SetRunArray() (and hence CancelInputMethod()), but it implements part of it. To avoid code duplication, I added a private _SetRunArray() call, which does most of the work, except cancelling the input method, and calling Refresh(). Removed some unneeded code from CancelInputMethod(), some small changes in HandleInputMethodChanged. -Questa linea, e quelle sotto di essa, saranno ignorate-- M src/kits/interface/TextView.cpp M headers/os/interface/TextView.h Modified: haiku/trunk/headers/os/interface/TextView.h =================================================================== --- haiku/trunk/headers/os/interface/TextView.h 2007-10-08 21:18:19 UTC (rev 22488) +++ haiku/trunk/headers/os/interface/TextView.h 2007-10-08 21:46:35 UTC (rev 22489) @@ -359,7 +359,7 @@ void PerformAutoScrolling(); void UpdateScrollbars(); - void AutoResize(bool doredraw=true); + void AutoResize(bool doRedraw = true); void NewOffscreen(float padding = 0.0F); void DeleteOffscreen(); @@ -369,6 +369,9 @@ void NormalizeFont(BFont *font); + void _SetRunArray(int32 startOffset, int32 endOffset, + const text_run_array *inRuns); + uint32 CharClassification(int32 offset) const; int32 NextInitialByte(int32 offset) const; int32 PreviousInitialByte(int32 offset) const; Modified: haiku/trunk/src/kits/interface/TextView.cpp =================================================================== --- haiku/trunk/src/kits/interface/TextView.cpp 2007-10-08 21:18:19 UTC (rev 22488) +++ haiku/trunk/src/kits/interface/TextView.cpp 2007-10-08 21:46:35 UTC (rev 22489) @@ -1506,44 +1506,12 @@ BTextView::SetRunArray(int32 startOffset, int32 endOffset, const text_run_array *inRuns) { CALLED(); - if (startOffset > endOffset) - return; CancelInputMethod(); - - const int32 textLength = fText->Length(); - - // pin offsets at reasonable values - if (startOffset < 0) - startOffset = 0; - else if (startOffset > textLength) - startOffset = textLength; - if (endOffset < 0) - endOffset = 0; - else if (endOffset > textLength) - endOffset = textLength; - - long numStyles = inRuns->count; - if (numStyles > 0) { - const text_run *theRun = &inRuns->runs[0]; - for (long index = 0; index < numStyles; index++) { - long fromOffset = theRun->offset + startOffset; - long toOffset = endOffset; - if (index + 1 < numStyles) { - toOffset = (theRun + 1)->offset + startOffset; - toOffset = (toOffset > endOffset) ? endOffset : toOffset; - } + _SetRunArray(startOffset, endOffset, inRuns); - fStyles->SetStyleRange(fromOffset, toOffset, textLength, - B_FONT_ALL, &theRun->font, &theRun->color); - - theRun++; - } - fStyles->InvalidateNullStyle(); - - Refresh(startOffset, endOffset, true, false); - } + Refresh(startOffset, endOffset, true, false); } @@ -2604,9 +2572,9 @@ // update the style runs fStyles->BumpOffset(inLength, fStyles->OffsetToRun(inOffset - 1) + 1); - if (inRuns != NULL) - SetRunArray(inOffset, inOffset + inLength, inRuns); - else { + if (inRuns != NULL) { + _SetRunArray(inOffset, inOffset + inLength, inRuns); + } else { // apply nullStyle to inserted text fStyles->SyncNullStyle(inOffset); fStyles->SetStyleRange(inOffset, inOffset + inLength, @@ -4227,6 +4195,48 @@ } +void +BTextView::_SetRunArray(int32 startOffset, int32 endOffset, const text_run_array *inRuns) +{ + if (startOffset > endOffset) + return; + + const int32 textLength = fText->Length(); + + // pin offsets at reasonable values + if (startOffset < 0) + startOffset = 0; + else if (startOffset > textLength) + startOffset = textLength; + + if (endOffset < 0) + endOffset = 0; + else if (endOffset > textLength) + endOffset = textLength; + + const int32 numStyles = inRuns->count; + if (numStyles > 0) { + const text_run *theRun = &inRuns->runs[0]; + for (int32 index = 0; index < numStyles; index++) { + int32 fromOffset = theRun->offset + startOffset; + int32 toOffset = endOffset; + if (index + 1 < numStyles) { + toOffset = (theRun + 1)->offset + startOffset; + toOffset = (toOffset > endOffset) ? endOffset : toOffset; + } + + BFont font = theRun->font; + NormalizeFont(&font); + fStyles->SetStyleRange(fromOffset, toOffset, textLength, + B_FONT_ALL, &theRun->font, &theRun->color); + + theRun++; + } + fStyles->InvalidateNullStyle(); + } +} + + /*! \brief Returns a value which tells if the given character is a separator character or not. \param offset The offset where the wanted character can be found. @@ -4412,10 +4422,14 @@ // TODO: block input if not editable (Andrew) ASSERT(fInline != NULL); + printf("HandleInputMethodChanged()\n"); + message->PrintToStream(); const char *string = NULL; if (message->FindString("be:string", &string) < B_OK || string == NULL) return; + _HideCaret(); + be_app->ObscureCursor(); // If we find the "be:confirmed" boolean (and the boolean is true), @@ -4428,20 +4442,22 @@ // Delete the previously inserted text (if any) if (fInline->IsActive()) { - int32 oldOffset = fInline->Offset(); - BTextView::DeleteText(oldOffset, oldOffset + fInline->Length()); - fClickOffset = fSelStart = fSelEnd = oldOffset; - + const int32 oldOffset = fInline->Offset(); + DeleteText(oldOffset, oldOffset + fInline->Length()); if (confirmed) fInline->SetActive(false); + fClickOffset = fSelStart = fSelEnd = oldOffset; } - int32 stringLen = strlen(string); + const int32 stringLen = strlen(string); fInline->SetOffset(fSelStart); fInline->SetLength(stringLen); fInline->ResetClauses(); + if (!confirmed && !fInline->IsActive()) + fInline->SetActive(true); + // Get the clauses, and pass them to the _BInlineInput_ object // TODO: Find out if what we did it's ok, currently we don't consider clauses // at all, while the bebook says we should; though the visual effect we obtained @@ -4464,21 +4480,14 @@ fInline->SetSelectionOffset(selectionStart); fInline->SetSelectionLength(selectionEnd - selectionStart); - // Insert the new text - // We call the base InsertText(), because inherited method could do bad things: - // Mail, for example, does call InsertText() with a runarray parameter - // (even if we pass NULL here). That causes SetRunArray() to be called, - // which in turn calls CancelInputMethod(), which would destroy fInline - // (and we call some of its functions later). Bug #1022. - // TODO: Check if R5 really does this - BTextView::InsertText(string, stringLen, fSelStart, NULL); + const int32 inlineOffset = fInline->Offset(); + InsertText(string, stringLen, fSelStart, NULL); fSelStart += stringLen; fClickOffset = fSelEnd = fSelStart; - if (!confirmed && !fInline->IsActive()) - fInline->SetActive(true); - - Refresh(fInline->Offset(), fSelEnd, true, false); + Refresh(inlineOffset, fSelEnd, true, true); + + _ShowCaret(); } @@ -4519,19 +4528,13 @@ if (!fInline) return; + printf("CancelInputMethod()\n"); _BInlineInput_ *inlineInput = fInline; fInline = NULL; - // Delete the previously inserted text (if any) - if (inlineInput->IsActive()) { - int32 oldOffset = inlineInput->Offset(); - DeleteText(oldOffset, oldOffset + inlineInput->Length()); - fClickOffset = fSelStart = fSelEnd = oldOffset; - } + if (inlineInput->IsActive() && Window()) + Refresh(inlineInput->Offset(), fText->Length() - inlineInput->Offset(), true, false); - if (Window()) - Refresh(0, fText->Length(), true, false); - BMessage message(B_INPUT_METHOD_EVENT); message.AddInt32("be:opcode", B_INPUT_METHOD_STOPPED); inlineInput->Method()->SendMessage(&message); From jackburton at mail.berlios.de Mon Oct 8 23:48:49 2007 From: jackburton at mail.berlios.de (jackburton at BerliOS) Date: Mon, 8 Oct 2007 23:48:49 +0200 Subject: [Haiku-commits] r22490 - haiku/trunk/src/kits/interface Message-ID: <200710082148.l98LmnEl022694@sheep.berlios.de> Author: jackburton Date: 2007-10-08 23:48:49 +0200 (Mon, 08 Oct 2007) New Revision: 22490 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22490&view=rev Modified: haiku/trunk/src/kits/interface/TextView.cpp Log: and there, the usual commit which removes the forgotten debug output... Modified: haiku/trunk/src/kits/interface/TextView.cpp =================================================================== --- haiku/trunk/src/kits/interface/TextView.cpp 2007-10-08 21:46:35 UTC (rev 22489) +++ haiku/trunk/src/kits/interface/TextView.cpp 2007-10-08 21:48:49 UTC (rev 22490) @@ -4422,8 +4422,6 @@ // TODO: block input if not editable (Andrew) ASSERT(fInline != NULL); - printf("HandleInputMethodChanged()\n"); - message->PrintToStream(); const char *string = NULL; if (message->FindString("be:string", &string) < B_OK || string == NULL) return; @@ -4528,7 +4526,6 @@ if (!fInline) return; - printf("CancelInputMethod()\n"); _BInlineInput_ *inlineInput = fInline; fInline = NULL; From bonefish at cs.tu-berlin.de Tue Oct 9 00:09:00 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Tue, 09 Oct 2007 00:09:00 +0200 Subject: [Haiku-commits] r22488 - haiku/trunk/src/bin/bash/lib/readline In-Reply-To: <200710082118.l98LIJuq021061@sheep.berlios.de> References: <200710082118.l98LIJuq021061@sheep.berlios.de> Message-ID: <20071009000900.8049.8@cs.tu-berlin.de> On 2007-10-08 at 23:18:19 [+0200], axeld at BerliOS wrote: > Author: axeld > Date: 2007-10-08 23:18:19 +0200 (Mon, 08 Oct 2007) > New Revision: 22488 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22488&view=rev > > Modified: > haiku/trunk/src/bin/bash/lib/readline/keymaps.c > haiku/trunk/src/bin/bash/lib/readline/readline.c > Log: > Changed defaults in readline to be more useful. This fixes bug #1540. > Alternatively, we could add an inputrc file - this would have the advantage > that other apps using readline built-in would have those, too. > OTOH this really should be in the defaults, too, IMO (ie. we could do both). > Opinions welcome :-) Given that there are like 5 more copies of readline in our repository I would have voted for the inputrc solution. CU, Ingo From axeld at mail.berlios.de Tue Oct 9 02:12:30 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 9 Oct 2007 02:12:30 +0200 Subject: [Haiku-commits] r22491 - haiku/trunk/src/system/kernel/debug Message-ID: <200710090012.l990CUdx016307@sheep.berlios.de> Author: axeld Date: 2007-10-09 02:12:29 +0200 (Tue, 09 Oct 2007) New Revision: 22491 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22491&view=rev Modified: haiku/trunk/src/system/kernel/debug/blue_screen.cpp haiku/trunk/src/system/kernel/debug/blue_screen.h haiku/trunk/src/system/kernel/debug/debug.c Log: panic() could hang in the early boot process in case it was called before the blue screen was initialized - blue_screen_enter() now returns wether or not it has been initialized already (there will only be serial output in that case). Modified: haiku/trunk/src/system/kernel/debug/blue_screen.cpp =================================================================== --- haiku/trunk/src/system/kernel/debug/blue_screen.cpp 2007-10-08 21:48:49 UTC (rev 22490) +++ haiku/trunk/src/system/kernel/debug/blue_screen.cpp 2007-10-09 00:12:29 UTC (rev 22491) @@ -1,5 +1,5 @@ /* - * Copyright 2005-2006, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Copyright 2005-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. * Distributed under the terms of the MIT License. */ @@ -486,7 +486,7 @@ } -void +status_t blue_screen_enter(bool debugOutput) { sScreen.attr = debugOutput ? 0xf0 : 0x0f; @@ -494,12 +494,16 @@ sScreen.x = sScreen.y = 0; sScreen.state = CONSOLE_STATE_NORMAL; + if (sModule == NULL) + return B_NO_INIT; + sModule->get_size(&sScreen.columns, &sScreen.rows); #if !NO_CLEAR sModule->clear(sScreen.attr); #else sModule->fill_glyph(0, sScreen.y, sScreen.columns, 3, ' ', sScreen.attr); #endif + return B_OK; } Modified: haiku/trunk/src/system/kernel/debug/blue_screen.h =================================================================== --- haiku/trunk/src/system/kernel/debug/blue_screen.h 2007-10-08 21:48:49 UTC (rev 22490) +++ haiku/trunk/src/system/kernel/debug/blue_screen.h 2007-10-09 00:12:29 UTC (rev 22491) @@ -1,5 +1,5 @@ /* - * Copyright 2005-2006, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Copyright 2005-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. * Distributed under the terms of the MIT License. */ #ifndef BLUE_SCREEN_H @@ -14,7 +14,7 @@ #endif status_t blue_screen_init(void); -void blue_screen_enter(bool debugOutput); +status_t blue_screen_enter(bool debugOutput); char blue_screen_getchar(void); void blue_screen_putchar(char c); Modified: haiku/trunk/src/system/kernel/debug/debug.c =================================================================== --- haiku/trunk/src/system/kernel/debug/debug.c 2007-10-08 21:48:49 UTC (rev 22490) +++ haiku/trunk/src/system/kernel/debug/debug.c 2007-10-09 00:12:29 UTC (rev 22491) @@ -893,8 +893,8 @@ } if (sBlueScreenOutput) { - sBlueScreenEnabled = true; - blue_screen_enter(false); + if (blue_screen_enter(false) == B_OK) + sBlueScreenEnabled = true; } if (message) From axeld at mail.berlios.de Tue Oct 9 03:36:19 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 9 Oct 2007 03:36:19 +0200 Subject: [Haiku-commits] r22492 - in haiku/trunk/src/system/libroot/posix: sys unistd Message-ID: <200710090136.l991aJn1021330@sheep.berlios.de> Author: axeld Date: 2007-10-09 03:36:18 +0200 (Tue, 09 Oct 2007) New Revision: 22492 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22492&view=rev Added: haiku/trunk/src/system/libroot/posix/unistd/hostname.cpp Removed: haiku/trunk/src/system/libroot/posix/unistd/hostname.c Modified: haiku/trunk/src/system/libroot/posix/sys/uname.c haiku/trunk/src/system/libroot/posix/unistd/Jamfile Log: * Implemented gethostname() and sethostname(). * uname() now calls gethostname() instead of using a hard-coded value. * This fixes bug #1250. Modified: haiku/trunk/src/system/libroot/posix/sys/uname.c =================================================================== --- haiku/trunk/src/system/libroot/posix/sys/uname.c 2007-10-09 00:12:29 UTC (rev 22491) +++ haiku/trunk/src/system/libroot/posix/sys/uname.c 2007-10-09 01:36:18 UTC (rev 22492) @@ -1,17 +1,19 @@ /* - * Copyright 2004, J?r?me Duval jerome.duval at free.fr. All rights reserved. + * Copyright 2004-2007, J?r?me Duval jerome.duval at free.fr. All rights reserved. * Distributed under the terms of the MIT License. */ -#include +#include -#include #include #include #include +#include +#include + // Haiku SVN revision. Will be set when copying libroot.so to the image. // Lives in a separate section so that it can easily be found. static uint32 sHaikuRevision __attribute__((section("_haiku_revision"))); @@ -61,8 +63,8 @@ } strlcpy(info->machine, platform, sizeof(info->machine)); - // TODO fill nodename field when we have hostname info - strlcpy(info->nodename, "unknown", sizeof(info->nodename)); + if (gethostname(info->nodename, sizeof(info->nodename)) != 0) + strlcpy(info->nodename, "unknown", sizeof(info->nodename)); return 0; } Modified: haiku/trunk/src/system/libroot/posix/unistd/Jamfile =================================================================== --- haiku/trunk/src/system/libroot/posix/unistd/Jamfile 2007-10-09 00:12:29 UTC (rev 22491) +++ haiku/trunk/src/system/libroot/posix/unistd/Jamfile 2007-10-09 01:36:18 UTC (rev 22492) @@ -14,7 +14,7 @@ _exit.c fcntl.c fork.c - hostname.c + hostname.cpp ioctl.c link.c lseek.c Deleted: haiku/trunk/src/system/libroot/posix/unistd/hostname.c Copied: haiku/trunk/src/system/libroot/posix/unistd/hostname.cpp (from rev 22481, haiku/trunk/src/system/libroot/posix/unistd/hostname.c) =================================================================== --- haiku/trunk/src/system/libroot/posix/unistd/hostname.c 2007-10-08 01:33:46 UTC (rev 22481) +++ haiku/trunk/src/system/libroot/posix/unistd/hostname.cpp 2007-10-09 01:36:18 UTC (rev 22492) @@ -0,0 +1,89 @@ +/* + * Copyright 2002-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ + + +#include +#include +#include +#include + +#include +#include + + +static status_t +get_path(char *path, bool create) +{ + status_t status = find_directory(B_COMMON_SETTINGS_DIRECTORY, -1, create, + path, B_PATH_NAME_LENGTH); + if (status != B_OK) + return status; + + strlcat(path, "/network", B_PATH_NAME_LENGTH); + if (create) + mkdir(path, 0755); + strlcat(path, "/hostname", B_PATH_NAME_LENGTH); + return B_OK; +} + + +extern "C" int +sethostname(const char *hostName, size_t nameSize) +{ + char path[B_PATH_NAME_LENGTH]; + if (get_path(path, false) != B_OK) { + errno = B_ERROR; + return -1; + } + + int file = open(path, O_WRONLY | O_CREAT, 0644); + if (file < 0) + return -1; + + nameSize = min_c(nameSize, MAXHOSTNAMELEN); + + if (write(file, hostName, nameSize) != (ssize_t)nameSize + || write(file, "\n", 1) != 1) { + close(file); + return -1; + } + + close(file); + return 0; +} + + +extern "C" int +gethostname(char *hostName, size_t nameSize) +{ + // look up hostname from network settings hostname file + + char path[B_PATH_NAME_LENGTH]; + if (get_path(path, false) != B_OK) { + errno = B_ERROR; + return -1; + } + + int file = open(path, O_RDONLY); + if (file < 0) + return -1; + + nameSize = min_c(nameSize, MAXHOSTNAMELEN); + + int length = read(file, hostName, nameSize - 1); + close(file); + + if (length < 0) + return -1; + + hostName[length] = '\0'; + + char *end = strpbrk(hostName, "\r\n\t"); + if (end != NULL) + end[0] = '\0'; + + return 0; +} + From axeld at mail.berlios.de Tue Oct 9 04:02:51 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 9 Oct 2007 04:02:51 +0200 Subject: [Haiku-commits] r22493 - haiku/trunk/src/system/kernel/lib Message-ID: <200710090202.l9922pkK022542@sheep.berlios.de> Author: axeld Date: 2007-10-09 04:02:50 +0200 (Tue, 09 Oct 2007) New Revision: 22493 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22493&view=rev Modified: haiku/trunk/src/system/kernel/lib/Jamfile Log: Removed gethostname() and sethostname() from the kernel. Modified: haiku/trunk/src/system/kernel/lib/Jamfile =================================================================== --- haiku/trunk/src/system/kernel/lib/Jamfile 2007-10-09 01:36:18 UTC (rev 22492) +++ haiku/trunk/src/system/kernel/lib/Jamfile 2007-10-09 02:02:50 UTC (rev 22493) @@ -72,7 +72,6 @@ directory.c dup.c fcntl.c - hostname.c ioctl.c link.c lseek.c From axeld at mail.berlios.de Tue Oct 9 04:04:36 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 9 Oct 2007 04:04:36 +0200 Subject: [Haiku-commits] r22494 - haiku/trunk/src/system/kernel/cache Message-ID: <200710090204.l9924aUi022622@sheep.berlios.de> Author: axeld Date: 2007-10-09 04:04:36 +0200 (Tue, 09 Oct 2007) New Revision: 22494 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22494&view=rev Modified: haiku/trunk/src/system/kernel/cache/file_cache.cpp Log: * satisfy_cache_io() was using the wrong value to compute the number of pages to reserve, which could result in to few being reserved in certain situations. * Use MutexLocker where appropriate. * Reordered includes following the new rules. Modified: haiku/trunk/src/system/kernel/cache/file_cache.cpp =================================================================== --- haiku/trunk/src/system/kernel/cache/file_cache.cpp 2007-10-09 02:02:50 UTC (rev 22493) +++ haiku/trunk/src/system/kernel/cache/file_cache.cpp 2007-10-09 02:04:36 UTC (rev 22494) @@ -6,23 +6,24 @@ #include "vnode_store.h" +#include +#include +#include + #include #include #include #include #include +#include #include #include #include #include #include -#include -#include -#include - //#define TRACE_FILE_CACHE #ifdef TRACE_FILE_CACHE # define TRACE(x) dprintf x @@ -221,7 +222,7 @@ // we don't yet have the map of this file, so let's grab it // (ordered by offset, so that we can do a binary search on them) - mutex_lock(&ref->cache->lock); + MutexLocker _(ref->cache->lock); // the file map could have been requested in the mean time if (ref->map.count == 0) { @@ -231,10 +232,8 @@ while (true) { status = vfs_get_file_map(ref->vnode, mapOffset, ~0UL, vecs, &vecCount); - if (status < B_OK && status != B_BUFFER_OVERFLOW) { - mutex_unlock(&ref->cache->lock); + if (status < B_OK && status != B_BUFFER_OVERFLOW) return status; - } status_t addStatus = ref->map.Add(vecs, vecCount, mapOffset); if (addStatus != B_OK) { @@ -250,8 +249,6 @@ vecCount = maxVecs; } } - - mutex_unlock(&ref->cache->lock); } if (status != B_OK) { @@ -776,7 +773,7 @@ size_t requestSize = buffer - lastBuffer; reservePages = min_c(MAX_IO_VECS, - (bytesLeft - requestSize + B_PAGE_SIZE - 1) >> PAGE_SHIFT); + (lastLeft - requestSize + B_PAGE_SIZE - 1) >> PAGE_SHIFT); status_t status; if (doWrite) { @@ -844,7 +841,7 @@ size_t reservePages = 0; vm_page_reserve_pages(lastReservedPages); - mutex_lock(&cache->lock); + MutexLocker locker(cache->lock); while (bytesLeft > 0) { // check if this page is already in memory @@ -857,17 +854,15 @@ status_t status = satisfy_cache_io(ref, offset, buffer, pageOffset, bytesLeft, reservePages, lastOffset, lastBuffer, lastPageOffset, lastLeft, lastReservedPages, doWrite); - if (status != B_OK) { - mutex_unlock(&cache->lock); + if (status != B_OK) return status; - } if (page->state == PAGE_STATE_BUSY) { ConditionVariableEntry entry; entry.Add(page); - mutex_unlock(&cache->lock); + locker.Unlock(); entry.Wait(); - mutex_lock(&cache->lock); + locker.Lock(); continue; } } @@ -903,7 +898,7 @@ if (bytesLeft <= bytesInPage) { // we've read the last page, so we're done! - mutex_unlock(&cache->lock); + locker.Unlock(); vm_page_unreserve_pages(lastReservedPages); return B_OK; } @@ -927,10 +922,8 @@ status_t status = satisfy_cache_io(ref, offset, buffer, pageOffset, bytesLeft, reservePages, lastOffset, lastBuffer, lastPageOffset, lastLeft, lastReservedPages, doWrite); - if (status != B_OK) { - mutex_unlock(&cache->lock); + if (status != B_OK) return status; - } } } @@ -945,7 +938,6 @@ lastBuffer, lastLeft, lastReservedPages, 0); } - mutex_unlock(&cache->lock); return status; } @@ -1333,8 +1325,7 @@ TRACE(("file_cache_invalidate_file_map(offset = %Ld, size = %Ld)\n", offset, size)); - mutex_lock(&ref->cache->lock); + MutexLocker _(ref->cache->lock); ref->map.Free(); - mutex_unlock(&ref->cache->lock); return B_OK; } From axeld at mail.berlios.de Tue Oct 9 13:05:51 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 9 Oct 2007 13:05:51 +0200 Subject: [Haiku-commits] r22495 - in haiku/trunk: headers/private/kernel src/system/kernel/vm Message-ID: <200710091105.l99B5pYS019752@sheep.berlios.de> Author: axeld Date: 2007-10-09 13:05:50 +0200 (Tue, 09 Oct 2007) New Revision: 22495 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22495&view=rev Modified: haiku/trunk/headers/private/kernel/vm.h haiku/trunk/src/system/kernel/vm/vm.cpp haiku/trunk/src/system/kernel/vm/vm_page.cpp Log: * vm_set_area_protection() would remap the whole area instead of just the page it intended to. That resulted in more writable pages where you wouldn't want them (ie. allowing the area to change pages in lower caches). * We were losing modified pages: vm_unmap_pages() sometimes has to preserve the modified flag (eg. when called from page fault). * Both of these were responsible that stealing active pages would crash applications - even if less likely, this could also have happened when stealing inactive pages. Therefore, I've activated stealing active pages again. * The page writer now pushes the pages of busy vnodes to the end of the queue, so that it won't pick them up again too soon (the vnode destruction would be in the process of writing those pages back, anyway). * The page thief now triggers the page writer to run once it has to steal active pages. This might be a bit too aggressive, though. Modified: haiku/trunk/headers/private/kernel/vm.h =================================================================== --- haiku/trunk/headers/private/kernel/vm.h 2007-10-09 02:04:36 UTC (rev 22494) +++ haiku/trunk/headers/private/kernel/vm.h 2007-10-09 11:05:50 UTC (rev 22495) @@ -131,7 +131,8 @@ int32 vm_test_map_activation(struct vm_page *page, bool *_modified); void vm_clear_map_flags(struct vm_page *page, uint32 flags); void vm_remove_all_page_mappings(struct vm_page *page, uint32 *_flags); -status_t vm_unmap_pages(struct vm_area *area, addr_t base, size_t length); +status_t vm_unmap_pages(struct vm_area *area, addr_t base, size_t length, + bool preserveModified); status_t vm_map_page(struct vm_area *area, struct vm_page *page, addr_t address, uint32 protection); status_t vm_get_physical_page(addr_t paddr, addr_t *vaddr, uint32 flags); Modified: haiku/trunk/src/system/kernel/vm/vm.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm.cpp 2007-10-09 02:04:36 UTC (rev 22494) +++ haiku/trunk/src/system/kernel/vm/vm.cpp 2007-10-09 11:05:50 UTC (rev 22495) @@ -2061,10 +2061,10 @@ // still exists in the area list. // Unmap the virtual address space the area occupied - vm_unmap_pages(area, area->base, area->size); + vm_unmap_pages(area, area->base, area->size, !area->cache->temporary); - // TODO: do that only for vnode stores - vm_cache_write_modified(area->cache, false); + if (!area->cache->temporary) + vm_cache_write_modified(area->cache, false); arch_vm_unset_memory_type(area); remove_area_from_address_space(addressSpace, area); @@ -2333,7 +2333,7 @@ while (page) { addr_t address = area->base + (page->cache_offset << PAGE_SHIFT); - map->ops->protect(map, area->base, area->base + area->size, + map->ops->protect(map, address, address - 1 + B_PAGE_SIZE, newProtection); page = page->cache_next; } @@ -2505,7 +2505,7 @@ status_t -vm_unmap_pages(vm_area *area, addr_t base, size_t size) +vm_unmap_pages(vm_area *area, addr_t base, size_t size, bool preserveModified) { vm_translation_map *map = &area->address_space->translation_map; addr_t end = base + (size - 1); @@ -2535,6 +2535,29 @@ } map->ops->unmap(map, base, end); + if (preserveModified) { + map->ops->flush(map); + + for (addr_t virtualAddress = base; virtualAddress < end; + virtualAddress += B_PAGE_SIZE) { + addr_t physicalAddress; + uint32 flags; + status_t status = map->ops->query(map, virtualAddress, + &physicalAddress, &flags); + if (status < B_OK || (flags & PAGE_PRESENT) == 0) + continue; + + vm_page *page = vm_lookup_page(physicalAddress / B_PAGE_SIZE); + if (page == NULL) { + panic("area %p looking up page failed for pa 0x%lx\n", area, + physicalAddress); + } + + if ((flags & PAGE_MODIFIED) != 0 + && page->state != PAGE_STATE_MODIFIED) + vm_page_set_state(page, PAGE_STATE_MODIFIED); + } + } map->ops->unlock(map); if (area->wiring == B_NO_LOCK) { @@ -4251,7 +4274,7 @@ // In case this is a copy-on-write page, we need to unmap it from the area now if (isWrite && page->cache == topCache) - vm_unmap_pages(area, address, B_PAGE_SIZE); + vm_unmap_pages(area, address, B_PAGE_SIZE, true); // TODO: there is currently no mechanism to prevent a page being mapped // more than once in case of a second page fault! @@ -4907,8 +4930,10 @@ current->size = newSize; // we also need to unmap all pages beyond the new size, if the area has shrinked - if (newSize < oldSize) - vm_unmap_pages(current, current->base + newSize, oldSize - newSize); + if (newSize < oldSize) { + vm_unmap_pages(current, current->base + newSize, oldSize - newSize, + false); + } } if (status == B_OK) Modified: haiku/trunk/src/system/kernel/vm/vm_page.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_page.cpp 2007-10-09 02:04:36 UTC (rev 22494) +++ haiku/trunk/src/system/kernel/vm/vm_page.cpp 2007-10-09 11:05:50 UTC (rev 22495) @@ -688,8 +688,14 @@ // we need our own reference to the store, as it might // currently be destructed if (cache->store->ops->acquire_unreferenced_ref(cache->store) - != B_OK) + != B_OK) { + // put it to the tail of the queue, then, so that we + // won't touch it too soon again + vm_page_requeue(page, true); + cacheLocker.Unlock(); + thread_yield(); continue; + } } locker.Lock(); @@ -821,12 +827,13 @@ score = 127; desperate = true; } else { - // TODO: for now, we never steal active pages - break; stealActive = true; score = 5; steal = 5; } + + // let the page writer clear some pages for reuse + release_sem_etc(sWriterWaitSem, 1, B_DO_NOT_RESCHEDULE); continue; } From revol at free.fr Tue Oct 9 15:27:48 2007 From: revol at free.fr (=?windows-1252?q?Fran=E7ois?= Revol) Date: Tue, 09 Oct 2007 15:27:48 +0200 CEST Subject: [Haiku-commits] r22488 - haiku/trunk/src/bin/bash/lib/readline In-Reply-To: <20071009000900.8049.8@cs.tu-berlin.de> Message-ID: <632283100-BeMail@laptop> > > Changed defaults in readline to be more useful. This fixes bug > > #1540. > > Alternatively, we could add an inputrc file - this would have the > > advantage > > that other apps using readline built-in would have those, too. > > OTOH this really should be in the defaults, too, IMO (ie. we could > > do both). > > Opinions welcome :-) > > Given that there are like 5 more copies of readline in our repository > I would > have voted for the inputrc solution. Here is the one I use in zeta... standard stuff, plus C-x p that pastes $PATH and allows editting it, and one I made, C-x q that changes foo into query '(name=="foo")'. Fran?ois. -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: inputrc URL: From bonefish at cs.tu-berlin.de Tue Oct 9 16:35:53 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Tue, 09 Oct 2007 16:35:53 +0200 Subject: [Haiku-commits] r22480 - haiku/trunk/src/system/kernel/fs In-Reply-To: <514030561-BeMail@laptop> References: <514030561-BeMail@laptop> Message-ID: <20071009163553.809.2@cs.tu-berlin.de> On 2007-10-08 at 22:27:37 [+0200], Fran?ois Revol wrote: > > > > > > > Yes but we can't do that from the api driver. > > > We'll need a sockfs for that. > > > I'll dig the one I wrote for BONE... > > > > It sounds a bit like overkill to do it just for that reason. I'd > > probably > > simply add an ioctl, that drivers can implement when they have > > special > > stat() requirements. > > Not more than pipefs... Compared to a simple driver that's quite a bit. You'd have to implement a dozen or so additional hooks for no real gain. > It's cleaner by design, no ioctl hack needed. "Hack" is a bit strong, IMHO. It would in fact also allow other drivers to report reasonable stat data (mode (S_IFCHR or S_IFBLK), size, and times). > It could also simplify later if we want to move the socket calls to > their own syscall(s) (linux has a single one muxing them), we'll just > add a hook in the fs api. Why would we want to switch to syscalls in the first place? CU, Ingo From mmu_man at mail.berlios.de Tue Oct 9 21:44:30 2007 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Tue, 9 Oct 2007 21:44:30 +0200 Subject: [Haiku-commits] r22496 - haiku/trunk/src/add-ons/kernel/debugger/hangman Message-ID: <200710091944.l99JiUi3016645@sheep.berlios.de> Author: mmu_man Date: 2007-10-09 21:44:29 +0200 (Tue, 09 Oct 2007) New Revision: 22496 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22496&view=rev Modified: haiku/trunk/src/add-ons/kernel/debugger/hangman/hangman.c Log: Fix warnings Modified: haiku/trunk/src/add-ons/kernel/debugger/hangman/hangman.c =================================================================== --- haiku/trunk/src/add-ons/kernel/debugger/hangman/hangman.c 2007-10-09 11:05:50 UTC (rev 22495) +++ haiku/trunk/src/add-ons/kernel/debugger/hangman/hangman.c 2007-10-09 19:44:29 UTC (rev 22496) @@ -5,8 +5,11 @@ #endif #include #include +#include #include #include +#include +#include #include /* as driver or module */ @@ -63,6 +66,10 @@ #define BIT_FROM_LETTER(l) (0x1 << (l - 'a')) status_t init_words(char *from); +void print_hangman(int fails); +void display_word(int current, uint32 tried_letters); +int play_hangman(void); +int kdlhangman(int argc, char **argv); #ifdef _KERNEL_MODE @@ -375,7 +382,7 @@ } # else /* as module */ - +status_t std_ops(int32 op, ...); status_t std_ops(int32 op, ...) { status_t err; From rudolfc at mail.berlios.de Tue Oct 9 22:05:43 2007 From: rudolfc at mail.berlios.de (rudolfc at BerliOS) Date: Tue, 9 Oct 2007 22:05:43 +0200 Subject: [Haiku-commits] r22497 - haiku/trunk/src/add-ons/kernel/drivers/graphics/nvidia Message-ID: <200710092005.l99K5hlx018230@sheep.berlios.de> Author: rudolfc Date: 2007-10-09 22:05:43 +0200 (Tue, 09 Oct 2007) New Revision: 22497 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22497&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/graphics/nvidia/driver.c Log: updated naming for some previous unknown cards, added 24 new cards for support/recognition in the kernel driver, being GF 6xxx, 7xxx and 8xxx types. Also two more nforce 6100 4x0 cards recognized now. NOTE: accelerant update will come at a later date (soon I hope), needs more investigation first. Modified: haiku/trunk/src/add-ons/kernel/drivers/graphics/nvidia/driver.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/graphics/nvidia/driver.c 2007-10-09 19:44:29 UTC (rev 22496) +++ haiku/trunk/src/add-ons/kernel/drivers/graphics/nvidia/driver.c 2007-10-09 20:05:43 UTC (rev 22497) @@ -4,7 +4,7 @@ Other authors: Mark Watson; - Rudolf Cornelissen 3/2002-4/2006. + Rudolf Cornelissen 3/2002-10/2007. */ @@ -108,9 +108,10 @@ 0x0040, /* Nvidia GeForce FX 6800 Ultra */ 0x0041, /* Nvidia GeForce FX 6800 */ 0x0042, /* Nvidia GeForce FX 6800LE */ - 0x0043, /* Nvidia unknown FX */ + 0x0043, /* Nvidia GeForce 6800 XE */ 0x0045, /* Nvidia GeForce FX 6800 GT */ 0x0046, /* Nvidia GeForce FX 6800 GT */ + 0x0047, /* Nvidia GeForce 6800 GS */ 0x0048, /* Nvidia GeForce FX 6800 XT */ 0x0049, /* Nvidia unknown FX */ 0x004d, /* Nvidia Quadro FX 4400 */ @@ -121,7 +122,7 @@ 0x0099, /* Nvidia Geforce 7800 GTX Go PCIe */ 0x009d, /* Nvidia Quadro FX 4500 */ 0x00a0, /* Nvidia Aladdin TNT2 */ - 0x00c0, /* Nvidia unknown FX */ + 0x00c0, /* Nvidia GeForce 6800 GS */ 0x00c1, /* Nvidia GeForce FX 6800 */ 0x00c2, /* Nvidia GeForce FX 6800LE */ 0x00c3, /* Nvidia GeForce FX 6800 XT */ @@ -134,7 +135,9 @@ 0x00f1, /* Nvidia GeForce FX 6600 GT AGP */ 0x00f2, /* Nvidia GeForce FX 6600 AGP */ 0x00f3, /* Nvidia GeForce 6200 */ + 0x00f4, /* Nvidia GeForce 6600 LE */ 0x00f5, /* Nvidia GeForce FX 7800 GS AGP */ + 0x00f6, /* Nvidia GeForce 6800 GS */ 0x00f8, /* Nvidia Quadro FX 3400/4400 PCIe */ 0x00f9, /* Nvidia GeForce PCX 6800 PCIe */ 0x00fa, /* Nvidia GeForce PCX 5750 PCIe */ @@ -154,7 +157,7 @@ 0x0140, /* Nvidia GeForce FX 6600 GT */ 0x0141, /* Nvidia GeForce FX 6600 */ 0x0142, /* Nvidia GeForce FX 6600LE */ - 0x0143, /* Nvidia unknown FX */ + 0x0143, /* Nvidia GeForce 6600 VE */ 0x0144, /* Nvidia GeForce FX 6600 Go */ 0x0145, /* Nvidia GeForce FX 6610 XL */ 0x0146, /* Nvidia GeForce FX 6600 TE Go / 6200 TE Go */ @@ -162,7 +165,7 @@ 0x0148, /* Nvidia GeForce FX 6600 Go */ 0x0149, /* Nvidia GeForce FX 6600 GT Go */ 0x014b, /* Nvidia unknown FX */ - 0x014c, /* Nvidia unknown FX */ + 0x014c, /* Nvidia Quadro FX 540 MXM */ 0x014d, /* Nvidia unknown FX */ 0x014e, /* Nvidia Quadro FX 540 */ 0x014f, /* Nvidia GeForce 6200 PCIe (128Mb) */ @@ -210,9 +213,13 @@ 0x018b, /* Nvidia Quadro4 380 XGL */ 0x018c, /* Nvidia Quadro4 NVS 50 PCI */ 0x018d, /* Nvidia GeForce4 448 Go */ + 0x0191, /* Nvidia GeForce 8800 GTX */ + 0x0193, /* Nvidia GeForce 8800 GTS */ 0x01a0, /* Nvidia GeForce2 Integrated GPU */ 0x01d1, /* Nvidia GeForce 7300 LE */ + 0x01d3, /* Nvidia GeForce 7300 SE */ 0x01d8, /* Nvidia GeForce 7400 GO */ + 0x01dd, /* Nvidia GeForce 7500 LE */ 0x01df, /* Nvidia GeForce 7300 GS */ 0x01f0, /* Nvidia GeForce4 MX Integrated GPU */ 0x0200, /* Nvidia GeForce3 */ @@ -222,6 +229,7 @@ 0x0211, /* Nvidia GeForce FX 6800 */ 0x0212, /* Nvidia GeForce FX 6800LE */ 0x0215, /* Nvidia GeForce FX 6800 GT */ + 0x0218, /* Nvidia GeForce 6800 XT */ 0x0220, /* Nvidia unknown FX */ 0x0221, /* Nvidia GeForce 6200 AGP (256Mb - 128bit) */ 0x0222, /* Nvidia unknown FX */ @@ -229,6 +237,7 @@ 0x0240, /* Nvidia GeForce 6150 (NFORCE4 Integr.GPU) */ 0x0241, /* Nvidia GeForce 6150 LE (NFORCE4 Integr.GPU) */ 0x0242, /* Nvidia GeForce 6100 (NFORCE4 Integr.GPU) */ + 0x0245, /* Nvidia Quadro NVS 210S / GeForce 6150LE */ 0x0250, /* Nvidia GeForce4 Ti 4600 */ 0x0251, /* Nvidia GeForce4 Ti 4400 */ 0x0252, /* Nvidia GeForce4 Ti 4600 */ @@ -245,6 +254,13 @@ 0x028c, /* Nvidia Quadro4 700 GoGL */ 0x0290, /* Nvidia GeForce 7900 GTX */ 0x0291, /* Nvidia GeForce 7900 GT */ + 0x0293, /* Nvidia GeForce 7900 GX2 */ + 0x0294, /* Nvidia GeForce 7950 GX2 */ + 0x0295, /* Nvidia GeForce 7950 GT */ + 0x0298, /* Nvidia GeForce Go 7900 GS */ + 0x0299, /* Nvidia GeForce Go 7900 GTX */ + 0x029c, /* Nvidia Quadro FX 5500 */ + 0x029f, /* Nvidia Quadro FX 4500 X2 */ 0x02a0, /* Nvidia GeForce3 Integrated GPU */ 0x02e1, /* Nvidia GeForce 7600 GS */ 0x0301, /* Nvidia GeForce FX 5800 Ultra */ @@ -301,26 +317,19 @@ 0x0391, /* Nvidia GeForce 7600 GT */ 0x0392, /* Nvidia GeForce 7600 GS */ 0x0393, /* Nvidia GeForce 7300 GT */ + 0x0394, /* Nvidia GeForce 7600 LE */ 0x0398, /* Nvidia GeForce 7600 GO */ + 0x03d0, /* Nvidia GeForce 6100 nForce 430 */ 0x03d1, /* Nvidia GeForce 6100 nForce 405 */ + 0x03d2, /* Nvidia GeForce 6100 nForce 400 */ + 0x0400, /* Nvidia GeForce 8600 GTS */ + 0x0402, /* Nvidia GeForce 8600 GT */ + 0x0421, /* Nvidia GeForce 8500 GT */ + 0x0422, /* Nvidia GeForce 8400 GS */ + 0x0423, /* Nvidia GeForce 8300 GS */ 0 }; -/* - not yet included nVidia ID's that are unknown, but used according to nvidia: - 0x0090 //g70 - 0x0093 //g70 - 0x0094 //g70 - 0x009c //g70 - 0x009e //g70 - 0x0210 //nv48 - 0x021d //nv48 (existing? not in nvidia list) - 0x021e //nv48 (existing? not in nvidia list) - The following ranges seem to exist as well, but no cards are defined yet: - 0x012x //nv41? - 0x023x //nv44 type 2? (0x022x is also type 2) -*/ - static uint16 elsa_device_list[] = { 0x0c60, /* Elsa Gladiac Geforce2 MX */ 0 From axeld at mail.berlios.de Wed Oct 10 11:58:26 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 10 Oct 2007 11:58:26 +0200 Subject: [Haiku-commits] r22498 - haiku/trunk/src/system/kernel/vm Message-ID: <200710100958.l9A9wQpa004169@sheep.berlios.de> Author: axeld Date: 2007-10-10 11:58:25 +0200 (Wed, 10 Oct 2007) New Revision: 22498 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22498&view=rev Modified: haiku/trunk/src/system/kernel/vm/vm.cpp Log: vm_test_map_{modification|activation}(), vm_clear_map_flags(), and vm_remove_all_page_mappings() all computed the wrong virtual address for the page in question, and would therefore return incorrect data! Introduced a virtual_page_address() function that is now used by all of them. So that's why we were still "losing" modified flags - it took me some hours to find those (sometimes processes died after stealing pages)... Modified: haiku/trunk/src/system/kernel/vm/vm.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm.cpp 2007-10-09 20:05:43 UTC (rev 22497) +++ haiku/trunk/src/system/kernel/vm/vm.cpp 2007-10-10 09:58:25 UTC (rev 22498) @@ -2379,6 +2379,14 @@ } +static inline addr_t +virtual_page_address(vm_area *area, vm_page *page) +{ + return area->base + + ((page->cache_offset << PAGE_SHIFT) - area->cache_offset); +} + + bool vm_test_map_modification(vm_page *page) { @@ -2393,8 +2401,8 @@ addr_t physicalAddress; uint32 flags; map->ops->lock(map); - addr_t address = area->base + (page->cache_offset << PAGE_SHIFT); - map->ops->query_interrupt(map, address, &physicalAddress, &flags); + map->ops->query(map, virtual_page_address(area, page), + &physicalAddress, &flags); map->ops->unlock(map); if (flags & PAGE_MODIFIED) @@ -2422,8 +2430,8 @@ addr_t physicalAddress; uint32 flags; map->ops->lock(map); - addr_t address = area->base + (page->cache_offset << PAGE_SHIFT); - map->ops->query_interrupt(map, address, &physicalAddress, &flags); + map->ops->query(map, virtual_page_address(area, page), + &physicalAddress, &flags); map->ops->unlock(map); if (flags & PAGE_ACCESSED) @@ -2451,8 +2459,7 @@ vm_translation_map *map = &area->address_space->translation_map; map->ops->lock(map); - addr_t address = area->base + (page->cache_offset << PAGE_SHIFT); - map->ops->clear_flags(map, address, flags); + map->ops->clear_flags(map, virtual_page_address(area, page), flags); map->ops->unlock(map); } } @@ -2480,10 +2487,10 @@ uint32 flags; map->ops->lock(map); - addr_t base = area->base + (page->cache_offset << PAGE_SHIFT); - map->ops->unmap(map, base, base + (B_PAGE_SIZE - 1)); + addr_t address = virtual_page_address(area, page); + map->ops->unmap(map, address, address + (B_PAGE_SIZE - 1)); map->ops->flush(map); - map->ops->query(map, base, &physicalAddress, &flags); + map->ops->query(map, address, &physicalAddress, &flags); map->ops->unlock(map); area->mappings.Remove(mapping); From bonefish at mail.berlios.de Wed Oct 10 16:13:34 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 10 Oct 2007 16:13:34 +0200 Subject: [Haiku-commits] r22499 - haiku/trunk/src/system/libroot/posix/sys Message-ID: <200710101413.l9AEDYp7014114@sheep.berlios.de> Author: bonefish Date: 2007-10-10 16:13:34 +0200 (Wed, 10 Oct 2007) New Revision: 22499 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22499&view=rev Modified: haiku/trunk/src/system/libroot/posix/sys/select.c Log: Patch by Vasilis Kaoutsis: select() and pselect() set errno correctly now. Modified: haiku/trunk/src/system/libroot/posix/sys/select.c =================================================================== --- haiku/trunk/src/system/libroot/posix/sys/select.c 2007-10-10 09:58:25 UTC (rev 22498) +++ haiku/trunk/src/system/libroot/posix/sys/select.c 2007-10-10 14:13:34 UTC (rev 22499) @@ -1,22 +1,34 @@ /* -** Copyright 2002-2004, Axel D?rfler, axeld at pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ + * Copyright 2002-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the OpenBeOS License. + */ +#include #include #include +#define RETURN_AND_SET_ERRNO(err) \ + if (err < 0) { \ + errno = err; \ + return -1; \ + } \ + return err; + + int pselect(int numBits, struct fd_set *readBits, struct fd_set *writeBits, struct fd_set *errorBits, const struct timespec *tv, const sigset_t *sigMask) { + int status; bigtime_t timeout = -1LL; if (tv) timeout = tv->tv_sec * 1000000LL + tv->tv_nsec / 1000LL; - return _kern_select(numBits, readBits, writeBits, errorBits, timeout, sigMask); + status = _kern_select(numBits, readBits, writeBits, errorBits, timeout, sigMask); + + RETURN_AND_SET_ERRNO(status); } @@ -24,10 +36,12 @@ select(int numBits, struct fd_set *readBits, struct fd_set *writeBits, struct fd_set *errorBits, struct timeval *tv) { + int status; bigtime_t timeout = -1LL; if (tv) timeout = tv->tv_sec * 1000000LL + tv->tv_usec; - return _kern_select(numBits, readBits, writeBits, errorBits, timeout, NULL); + status = _kern_select(numBits, readBits, writeBits, errorBits, timeout, NULL); + + RETURN_AND_SET_ERRNO(status); } - From axeld at mail.berlios.de Wed Oct 10 20:57:10 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 10 Oct 2007 20:57:10 +0200 Subject: [Haiku-commits] r22500 - haiku/trunk/src/system/kernel/arch/x86 Message-ID: <200710101857.l9AIvAZL014893@sheep.berlios.de> Author: axeld Date: 2007-10-10 20:57:10 +0200 (Wed, 10 Oct 2007) New Revision: 22500 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22500&view=rev Modified: haiku/trunk/src/system/kernel/arch/x86/arch_vm_translation_map.cpp Log: Corrected comment. Modified: haiku/trunk/src/system/kernel/arch/x86/arch_vm_translation_map.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/arch_vm_translation_map.cpp 2007-10-10 14:13:34 UTC (rev 22499) +++ haiku/trunk/src/system/kernel/arch/x86/arch_vm_translation_map.cpp 2007-10-10 18:57:10 UTC (rev 22500) @@ -527,7 +527,7 @@ *_physical = ADDR_REVERSE_SHIFT(pt[index].addr); - // read in the page state flags, clearing the modified and accessed flags in the process + // read in the page state flags if (pt[index].user) *_flags |= (pt[index].rw ? B_WRITE_AREA : 0) | B_READ_AREA; From mmlr at mail.berlios.de Wed Oct 10 22:47:17 2007 From: mmlr at mail.berlios.de (mmlr at BerliOS) Date: Wed, 10 Oct 2007 22:47:17 +0200 Subject: [Haiku-commits] r22501 - haiku/trunk/src/system/kernel/debug Message-ID: <200710102047.l9AKlHCU020996@sheep.berlios.de> Author: mmlr Date: 2007-10-10 22:47:16 +0200 (Wed, 10 Oct 2007) New Revision: 22501 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22501&view=rev Modified: haiku/trunk/src/system/kernel/debug/debug.c Log: Extended flushing repeat messages in kernel debug output. The repeat message is printed when there has been no repeat for more than 1 second and now also when the first repeat was more than 3 seconds ago. This ensures that repeat messages are sent when the repeated message is constantly output at a frequency of less than a second. Modified: haiku/trunk/src/system/kernel/debug/debug.c =================================================================== --- haiku/trunk/src/system/kernel/debug/debug.c 2007-10-10 18:57:10 UTC (rev 22500) +++ haiku/trunk/src/system/kernel/debug/debug.c 2007-10-10 20:47:16 UTC (rev 22501) @@ -74,7 +74,8 @@ static void flush_pending_repeats(void); static void check_pending_repeats(void *data, int iter); -static int64 sMessageRepeatTime = 0; +static int64 sMessageRepeatFirstTime = 0; +static int64 sMessageRepeatLastTime = 0; static int32 sMessageRepeatCount = 0; #define LINE_BUFFER_SIZE 1024 @@ -665,10 +666,12 @@ if (length >= OUTPUT_BUFFER_SIZE) length = OUTPUT_BUFFER_SIZE - 1; - if (strncmp(string, sLastOutputBuffer, length) == 0 - && length > 1 && string[length - 1] == '\n') { + if (length > 1 && string[length - 1] == '\n' + && strncmp(string, sLastOutputBuffer, length) == 0) { sMessageRepeatCount++; - sMessageRepeatTime = system_time(); + sMessageRepeatLastTime = system_time(); + if (sMessageRepeatFirstTime == 0) + sMessageRepeatFirstTime = sMessageRepeatLastTime; } else { flush_pending_repeats(); kputs(string); @@ -949,6 +952,7 @@ blue_screen_puts(sLastOutputBuffer); } + sMessageRepeatFirstTime = 0; sMessageRepeatCount = 0; } } @@ -960,7 +964,8 @@ (void)data; (void)iter; if (sMessageRepeatCount > 0 - && (system_time() - sMessageRepeatTime) > 1000000) { + && ((system_time() - sMessageRepeatLastTime) > 1000000 + || (system_time() - sMessageRepeatFirstTime) > 3000000)) { cpu_status state = disable_interrupts(); acquire_spinlock(&sSpinlock); @@ -990,10 +995,12 @@ if (length >= OUTPUT_BUFFER_SIZE) length = OUTPUT_BUFFER_SIZE - 1; - if (strncmp(sOutputBuffer, sLastOutputBuffer, length) == 0 - && length > 1 && sOutputBuffer[length - 1] == '\n') { + if (length > 1 && sOutputBuffer[length - 1] == '\n' + && strncmp(sOutputBuffer, sLastOutputBuffer, length) == 0) { sMessageRepeatCount++; - sMessageRepeatTime = system_time(); + sMessageRepeatLastTime = system_time(); + if (sMessageRepeatFirstTime == 0) + sMessageRepeatFirstTime = sMessageRepeatLastTime; } else { flush_pending_repeats(); From bonefish at mail.berlios.de Wed Oct 10 23:30:51 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 10 Oct 2007 23:30:51 +0200 Subject: [Haiku-commits] r22502 - in haiku/trunk: headers/private/app src/kits/app Message-ID: <200710102130.l9ALUph5023155@sheep.berlios.de> Author: bonefish Date: 2007-10-10 23:30:51 +0200 (Wed, 10 Oct 2007) New Revision: 22502 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22502&view=rev Modified: haiku/trunk/headers/private/app/AppMisc.h haiku/trunk/src/kits/app/AppMisc.cpp Log: Added global lock that can be used for lazy initializations. Modified: haiku/trunk/headers/private/app/AppMisc.h =================================================================== --- haiku/trunk/headers/private/app/AppMisc.h 2007-10-10 20:47:16 UTC (rev 22501) +++ haiku/trunk/headers/private/app/AppMisc.h 2007-10-10 21:30:51 UTC (rev 22502) @@ -1,33 +1,12 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, OpenBeOS -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: AppMisc.h -// Author: Ingo Weinhold (bonefish at users.sf.net) -// Description: Miscellaneous private functionality. -//------------------------------------------------------------------------------ - +/* + * Copyright 2002-2007, Ingo Weinhold, bonefish at users.sf.net. + * Distributed under the terms of the MIT License. + */ #ifndef _APP_MISC_H #define _APP_MISC_H #include +#include #include #include @@ -35,6 +14,9 @@ namespace BPrivate { +// Global lock that can be used e.g. to initialize singletons. +extern BLocker gInitializationLock; + status_t get_app_path(team_id team, char *buffer); status_t get_app_path(char *buffer); status_t get_app_ref(team_id team, entry_ref *ref, bool traverse = true); Modified: haiku/trunk/src/kits/app/AppMisc.cpp =================================================================== --- haiku/trunk/src/kits/app/AppMisc.cpp 2007-10-10 20:47:16 UTC (rev 22501) +++ haiku/trunk/src/kits/app/AppMisc.cpp 2007-10-10 21:30:51 UTC (rev 22502) @@ -18,6 +18,9 @@ namespace BPrivate { +BLocker gInitializationLock("global init lock"); + + // get_app_path /*! \brief Returns the path to an application's executable. \param team The application's team ID. From bonefish at mail.berlios.de Wed Oct 10 23:35:24 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 10 Oct 2007 23:35:24 +0200 Subject: [Haiku-commits] r22503 - in haiku/trunk: headers/private/storage src/kits/storage Message-ID: <200710102135.l9ALZO3r023390@sheep.berlios.de> Author: bonefish Date: 2007-10-10 23:35:22 +0200 (Wed, 10 Oct 2007) New Revision: 22503 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22503&view=rev Added: haiku/trunk/headers/private/storage/MutablePartition.h haiku/trunk/src/kits/storage/DiskSystemAddOnManager.cpp haiku/trunk/src/kits/storage/DiskSystemAddOnManager.h haiku/trunk/src/kits/storage/MutablePartition.cpp haiku/trunk/src/kits/storage/PartitionDelegate.cpp haiku/trunk/src/kits/storage/PartitionDelegate.h Modified: haiku/trunk/headers/private/storage/DiskSystemAddOn.h haiku/trunk/headers/private/storage/Partition.h haiku/trunk/src/kits/storage/DiskSystemAddOn.cpp haiku/trunk/src/kits/storage/Jamfile Log: More fleshing out the disk system add-on interface and related classes. Modified: haiku/trunk/headers/private/storage/DiskSystemAddOn.h =================================================================== --- haiku/trunk/headers/private/storage/DiskSystemAddOn.h 2007-10-10 21:30:51 UTC (rev 22502) +++ haiku/trunk/headers/private/storage/DiskSystemAddOn.h 2007-10-10 21:35:22 UTC (rev 22503) @@ -9,6 +9,7 @@ #include +class BDiskDeviceParameterEditor; class BList; class BMutablePartition; class BPartitionHandle; @@ -28,8 +29,13 @@ BMutablePartition* partition, BPartitionHandle** handle) = 0; - virtual bool CanInitialize(BMutablePartition* partition); - virtual bool ValidateInitialize(BMutablePartition* partition, + virtual bool CanInitialize( + const BMutablePartition* partition); + virtual status_t GetInitializationParameterEditor( + const BMutablePartition* partition, + BDiskDeviceParameterEditor** editor); + virtual bool ValidateInitialize( + const BMutablePartition* partition, BString* name, const char* parameters); virtual status_t Initialize(BMutablePartition* partition, const char* name, const char* parameters, @@ -50,14 +56,16 @@ virtual uint32 SupportedOperations(uint32 mask); virtual uint32 SupportedChildOperations( - BMutablePartition* child, uint32 mask); + const BMutablePartition* child, + uint32 mask); virtual bool SupportsInitializingChild( - BMutablePartition* child, + const BMutablePartition* child, const char* diskSystem); - virtual bool IsSubSystemFor(BMutablePartition* child); + virtual bool IsSubSystemFor(const BMutablePartition* child); - virtual status_t GetNextSupportedType(BMutablePartition* child, + virtual status_t GetNextSupportedType( + const BMutablePartition* child, int32* cookie, BString* type); // child can be NULL virtual status_t GetTypeForContentType(const char* contentType, @@ -66,47 +74,60 @@ virtual status_t GetPartitioningInfo(BPartitioningInfo* info); + virtual status_t Defragment(); virtual status_t Repair(bool checkOnly); - // TODO: How is this supposed to work? virtual bool ValidateResize(off_t* size); - virtual bool ValidateResizeChild(BMutablePartition* child, + virtual bool ValidateResizeChild( + const BMutablePartition* child, off_t* size); virtual status_t Resize(off_t size); virtual status_t ResizeChild(BMutablePartition* child, off_t size); virtual bool ValidateMove(off_t* offset); - virtual bool ValidateMoveChild(BMutablePartition* child, + virtual bool ValidateMoveChild( + const BMutablePartition* child, off_t* offset); virtual status_t Move(off_t offset); virtual status_t MoveChild(BMutablePartition* child, off_t offset); virtual bool ValidateSetContentName(BString* name); - virtual bool ValidateSetName(BMutablePartition* child, + virtual bool ValidateSetName(const BMutablePartition* child, BString* name); virtual status_t SetContentName(const char* name); virtual status_t SetName(BMutablePartition* child, const char* name); - virtual bool ValidateSetType(BMutablePartition* child, + virtual bool ValidateSetType(const BMutablePartition* child, const char* type); virtual status_t SetType(BMutablePartition* child, const char* type); + virtual status_t GetContentParameterEditor( + BDiskDeviceParameterEditor** editor); + virtual status_t GetParameterEditor( + const BMutablePartition* child, + BDiskDeviceParameterEditor** editor); virtual bool ValidateSetContentParameters( const char* parameters); - virtual bool ValidateSetParameters(BMutablePartition* child, + virtual bool ValidateSetParameters( + const BMutablePartition* child, const char* parameters); virtual status_t SetContentParameters(const char* parameters); virtual status_t SetParameters(BMutablePartition* child, const char* parameters); + virtual status_t GetChildCreationParameterEditor( + const char* type, + BDiskDeviceParameterEditor** editor); virtual bool ValidateCreateChild(off_t* offset, off_t* size, const char* type, const char* parameters); - virtual status_t CreateChild(BMutablePartition* child); + virtual status_t CreateChild(off_t offset, off_t size, + const char* type, const char* parameters, + BMutablePartition** child); virtual status_t DeleteChild(BMutablePartition* child); Added: haiku/trunk/headers/private/storage/MutablePartition.h =================================================================== --- haiku/trunk/headers/private/storage/MutablePartition.h 2007-10-10 21:30:51 UTC (rev 22502) +++ haiku/trunk/headers/private/storage/MutablePartition.h 2007-10-10 21:35:22 UTC (rev 22503) @@ -0,0 +1,88 @@ +/* + * Copyright 2007, Ingo Weinhold, bonefish at users.sf.net. + * Distributed under the terms of the MIT License. + */ +#ifndef _MUTABLE_PARTITION_H +#define _MUTABLE_PARTITION_H + +#include +#include + + +struct user_partition_data; + + +class BMutablePartition { +public: + off_t Offset() const; + void SetOffset(off_t offset); + + off_t Size() const; + void SetSize(off_t size); + + off_t ContentSize() const; + void SetContentSize(off_t size); + + off_t BlockSize() const; + void SetBlockSize(off_t blockSize); + + uint32 Status() const; + + uint32 Flags() const; + void SetFlags(uint32 flags); + + dev_t Volume() const; + + int32 Index() const; + + const char* Name() const; + status_t SetName(const char* name); + + const char* ContentName() const; + status_t SetContentName(const char* name); + + const char* Type() const; + status_t SetType(const char* type) const; + + const char* ContentType() const; + status_t SetContentType(const char* type) const; + + const char* Parameters() const; + status_t SetParameters(const char* parameters); + + const char* ContentParameters() const; + status_t SetContentParameters(const char* parameters); + + status_t CreateChild(int32 index, + BMutablePartition** child); + status_t DeleteChild(int32 index); + + BMutablePartition* ChildAt(int32 index) const; + int32 CountChildren() const; + + // for the partitioning system managing the parent + void* ChildCookie() const; + void SetChildCookie(void* cookie); + +private: + BMutablePartition( + BPartition::MutableDelegate* delegate); + ~BMutablePartition(); + + status_t Init(const user_partition_data* partitionData); + + const user_partition_data* PartitionData() const; + +private: + friend class BPartition::MutableDelegate; + + BPartition::MutableDelegate* GetDelegate() const; + + BPartition::MutableDelegate* fDelegate; + user_partition_data* fData; + BList fChildren; + void* fChildCookie; +}; + + +#endif // _MUTABLE_PARTITION_H Modified: haiku/trunk/headers/private/storage/Partition.h =================================================================== --- haiku/trunk/headers/private/storage/Partition.h 2007-10-10 21:30:51 UTC (rev 22502) +++ haiku/trunk/headers/private/storage/Partition.h 2007-10-10 21:35:22 UTC (rev 22503) @@ -140,6 +140,10 @@ status_t DeleteChild(int32 index); private: + class Delegate; + class ImmutableDelegate; + class MutableDelegate; + BPartition(); BPartition(const BPartition &); virtual ~BPartition(); Modified: haiku/trunk/src/kits/storage/DiskSystemAddOn.cpp =================================================================== --- haiku/trunk/src/kits/storage/DiskSystemAddOn.cpp 2007-10-10 21:30:51 UTC (rev 22502) +++ haiku/trunk/src/kits/storage/DiskSystemAddOn.cpp 2007-10-10 21:35:22 UTC (rev 22503) @@ -43,15 +43,24 @@ // CanInitialize bool -BDiskSystemAddOn::CanInitialize(BMutablePartition* partition) +BDiskSystemAddOn::CanInitialize(const BMutablePartition* partition) { return false; } +// GetInitializationParameterEditor +status_t +BDiskSystemAddOn::GetInitializationParameterEditor( + const BMutablePartition* partition, BDiskDeviceParameterEditor** editor) +{ + return B_NOT_SUPPORTED; +} + + // ValidateInitialize bool -BDiskSystemAddOn::ValidateInitialize(BMutablePartition* partition, +BDiskSystemAddOn::ValidateInitialize(const BMutablePartition* partition, BString* name, const char* parameters) { return false; @@ -101,7 +110,7 @@ // SupportedChildOperations uint32 -BPartitionHandle::SupportedChildOperations(BMutablePartition* child, +BPartitionHandle::SupportedChildOperations(const BMutablePartition* child, uint32 mask) { return 0; @@ -110,7 +119,7 @@ // SupportsInitializingChild bool -BPartitionHandle::SupportsInitializingChild(BMutablePartition* child, +BPartitionHandle::SupportsInitializingChild(const BMutablePartition* child, const char* diskSystem) { return false; @@ -119,7 +128,7 @@ // IsSubSystemFor bool -BPartitionHandle::IsSubSystemFor(BMutablePartition* child) +BPartitionHandle::IsSubSystemFor(const BMutablePartition* child) { return false; } @@ -127,8 +136,8 @@ // GetNextSupportedType status_t -BPartitionHandle::GetNextSupportedType(BMutablePartition* child, int32* cookie, - BString* type) +BPartitionHandle::GetNextSupportedType(const BMutablePartition* child, + int32* cookie, BString* type) { return B_ENTRY_NOT_FOUND; } @@ -150,6 +159,14 @@ } +// Defragment +status_t +BPartitionHandle::Defragment() +{ + return B_NOT_SUPPORTED; +} + + // Repair status_t BPartitionHandle::Repair(bool checkOnly) @@ -168,7 +185,8 @@ // ValidateResizeChild bool -BPartitionHandle::ValidateResizeChild(BMutablePartition* child, off_t* size) +BPartitionHandle::ValidateResizeChild(const BMutablePartition* child, + off_t* size) { return false; } @@ -202,7 +220,8 @@ // ValidateMoveChild bool -BPartitionHandle::ValidateMoveChild(BMutablePartition* child, off_t* offset) +BPartitionHandle::ValidateMoveChild(const BMutablePartition* child, + off_t* offset) { return false; } @@ -236,7 +255,8 @@ // ValidateSetName bool -BPartitionHandle::ValidateSetName(BMutablePartition* child, BString* name) +BPartitionHandle::ValidateSetName(const BMutablePartition* child, + BString* name) { return false; } @@ -260,7 +280,8 @@ // ValidateSetType bool -BPartitionHandle::ValidateSetType(BMutablePartition* child, const char* type) +BPartitionHandle::ValidateSetType(const BMutablePartition* child, + const char* type) { return false; } @@ -274,6 +295,23 @@ } +// GetContentParameterEditor +status_t +BPartitionHandle::GetContentParameterEditor(BDiskDeviceParameterEditor** editor) +{ + return B_NOT_SUPPORTED; +} + + +// GetParameterEditor +status_t +BPartitionHandle::GetParameterEditor(const BMutablePartition* child, + BDiskDeviceParameterEditor** editor) +{ + return B_NOT_SUPPORTED; +} + + // ValidateSetContentParameters bool BPartitionHandle::ValidateSetContentParameters(const char* parameters) @@ -284,7 +322,7 @@ // ValidateSetParameters bool -BPartitionHandle::ValidateSetParameters(BMutablePartition* child, +BPartitionHandle::ValidateSetParameters(const BMutablePartition* child, const char* parameters) { return false; @@ -308,6 +346,15 @@ } +// GetChildCreationParameterEditor +status_t +BPartitionHandle::GetChildCreationParameterEditor(const char* type, + BDiskDeviceParameterEditor** editor) +{ + return B_NOT_SUPPORTED; +} + + // ValidateCreateChild bool BPartitionHandle::ValidateCreateChild(off_t* offset, off_t* size, @@ -319,7 +366,8 @@ // CreateChild status_t -BPartitionHandle::CreateChild(BMutablePartition* child) +BPartitionHandle::CreateChild(off_t offset, off_t size, const char* type, + const char* parameters, BMutablePartition** child) { return B_NOT_SUPPORTED; } Added: haiku/trunk/src/kits/storage/DiskSystemAddOnManager.cpp =================================================================== --- haiku/trunk/src/kits/storage/DiskSystemAddOnManager.cpp 2007-10-10 21:30:51 UTC (rev 22502) +++ haiku/trunk/src/kits/storage/DiskSystemAddOnManager.cpp 2007-10-10 21:35:22 UTC (rev 22503) @@ -0,0 +1,175 @@ +/* + * Copyright 2007, Ingo Weinhold, bonefish at users.sf.net. + * Distributed under the terms of the MIT License. + */ + +#include "DiskSystemAddOnManager.h" + +#include + +#include +#include + +#include + + +// sManager +DiskSystemAddOnManager* DiskSystemAddOnManager::sManager = NULL; + + +// AddOnImage +struct DiskSystemAddOnManager::AddOnImage { + image_id image; + int32 refCount; +}; + + +// AddOn +struct DiskSystemAddOnManager::AddOn { + AddOnImage* image; + BDiskSystemAddOn* addOn; + int32 refCount; +}; + + +// Default +DiskSystemAddOnManager* +DiskSystemAddOnManager::Default() +{ + if (!sManager) { + DiskSystemAddOnManager* manager = new DiskSystemAddOnManager(); + + BPrivate::gInitializationLock.Lock(); + + // set manager, if no one beat us to it + if (!sManager) { + sManager = manager; + manager = NULL; + } + + BPrivate::gInitializationLock.Unlock(); + + // delete the object we created, if someone else was quicker + delete manager; + } + + return sManager; +} + + +// Lock +bool +DiskSystemAddOnManager::Lock() +{ + return fLock.Lock(); +} + + +// Unlock +void +DiskSystemAddOnManager::Unlock() +{ + fLock.Unlock(); +} + + +// LoadDiskSystems +void +DiskSystemAddOnManager::LoadDiskSystems() +{ + AutoLocker _(fLock); + + if (++fLoadCount > 1) + return; + + // TODO: Load the add-ons ... +} + + +// UnloadDiskSystems +void +DiskSystemAddOnManager::UnloadDiskSystems() +{ + AutoLocker _(fLock); + + if (--fLoadCount == 0) + return; + + // TODO: Unload the add-ons ... +} + + +// CountAddOns +int32 +DiskSystemAddOnManager::CountAddOns() const +{ + return fAddOns.CountItems(); +} + + +// AddOnAt +BDiskSystemAddOn* +DiskSystemAddOnManager::AddOnAt(int32 index) const +{ + AddOn* addOn = _AddOnAt(index); + return addOn ? addOn->addOn : NULL; +} + + +// GetAddOn +BDiskSystemAddOn* +DiskSystemAddOnManager::GetAddOn(const char* name) +{ + if (!name) + return NULL; + + AutoLocker _(fLock); + + for (int32 i = 0; AddOn* addOn = _AddOnAt(i); i++) { + if (strcmp(addOn->addOn->Name(), name) == 0) { + addOn->refCount++; + return addOn->addOn; + } + } + + return NULL; +} + + +// PutAddOn +void +DiskSystemAddOnManager::PutAddOn(BDiskSystemAddOn* _addOn) +{ + if (!_addOn) + return; + + AutoLocker _(fLock); + + for (int32 i = 0; AddOn* addOn = _AddOnAt(i); i++) { + if (_addOn == addOn->addOn) { + if (addOn->refCount == 0) + debugger("DiskSystemAddOnManager: unbalanced PutAddOn()"); + else + addOn->refCount--; + return; + } + } +} + + +// constructor +DiskSystemAddOnManager::DiskSystemAddOnManager() + : fLock("disk system add-ons manager"), + fAddOns(), + fLoadCount(0) +{ +} + + +// _AddOnAt +DiskSystemAddOnManager::AddOn* +DiskSystemAddOnManager::_AddOnAt(int32 index) const +{ + return (AddOn*)fAddOns.ItemAt(index); +} + Added: haiku/trunk/src/kits/storage/DiskSystemAddOnManager.h =================================================================== --- haiku/trunk/src/kits/storage/DiskSystemAddOnManager.h 2007-10-10 21:30:51 UTC (rev 22502) +++ haiku/trunk/src/kits/storage/DiskSystemAddOnManager.h 2007-10-10 21:35:22 UTC (rev 22503) @@ -0,0 +1,58 @@ +/* + * Copyright 2007, Ingo Weinhold, bonefish at users.sf.net. + * Distributed under the terms of the MIT License. + */ +#ifndef _DISK_SYSTEM_ADD_ON_MANAGER_H +#define _DISK_SYSTEM_ADD_ON_MANAGER_H + +#include +#include + + +class BDiskSystemAddOn; + + +namespace BPrivate { + + +class DiskSystemAddOnManager { +public: + static DiskSystemAddOnManager* Default(); + + bool Lock(); + void Unlock(); + + // load/unload all disk system add-ons + void LoadDiskSystems(); + void UnloadDiskSystems(); + + // manager must be locked + int32 CountAddOns() const; + BDiskSystemAddOn* AddOnAt(int32 index) const; + + // manager will be locked + BDiskSystemAddOn* GetAddOn(const char* name); + void PutAddOn(BDiskSystemAddOn* addOn); + +private: + struct AddOnImage; + struct AddOn; + + DiskSystemAddOnManager(); + + AddOn* _AddOnAt(int32 index) const; + +private: + mutable BLocker fLock; + BList fAddOns; + int32 fLoadCount; + + static DiskSystemAddOnManager* sManager; +}; + + +} // namespace BPrivate + +using BPrivate::DiskSystemAddOnManager; + +#endif // _DISK_SYSTEM_ADD_ON_MANAGER_H Modified: haiku/trunk/src/kits/storage/Jamfile =================================================================== --- haiku/trunk/src/kits/storage/Jamfile 2007-10-10 21:30:51 UTC (rev 22502) +++ haiku/trunk/src/kits/storage/Jamfile 2007-10-10 21:35:22 UTC (rev 22503) @@ -79,7 +79,10 @@ DiskDeviceVisitor.cpp DiskSystem.cpp DiskSystemAddOn.cpp + DiskSystemAddOnManager.cpp + MutablePartition.cpp Partition.cpp + PartitionDelegate.cpp PartitioningInfo.cpp ; Added: haiku/trunk/src/kits/storage/MutablePartition.cpp =================================================================== --- haiku/trunk/src/kits/storage/MutablePartition.cpp 2007-10-10 21:30:51 UTC (rev 22502) +++ haiku/trunk/src/kits/storage/MutablePartition.cpp 2007-10-10 21:35:22 UTC (rev 22503) @@ -0,0 +1,372 @@ +/* + * Copyright 2007, Ingo Weinhold, bonefish at users.sf.net. + * Distributed under the terms of the MIT License. + */ + +#include + +#include +#include + +#include + +#include + + +using std::nothrow; + + +// set_string +static status_t +set_string(char*& location, const char* newString) +{ + char* string = NULL; + if (newString) { + string = strdup(newString); + if (!string) + return B_NO_MEMORY; + } + + free(location); + location = string; + + return B_OK; +} + + +#define SET_STRING_RETURN_ON_ERROR(location, string) \ +{ \ + status_t error = set_string(location, string); \ + if (error != B_OK) \ + return error; \ +} + + +// Offset +off_t +BMutablePartition::Offset() const +{ + return fData->offset; +} + + +// SetOffset +void +BMutablePartition::SetOffset(off_t offset) +{ + fData->offset = offset; +} + + +// Size +off_t +BMutablePartition::Size() const +{ + return fData->size; +} + + +// SetSize +void +BMutablePartition::SetSize(off_t size) +{ + fData->size = size; +} + + +// ContentSize +off_t +BMutablePartition::ContentSize() const +{ + return fData->content_size; +} + + +// SetContentSize +void +BMutablePartition::SetContentSize(off_t size) +{ + fData->content_size = size; +} + + +// BlockSize +off_t +BMutablePartition::BlockSize() const +{ + return fData->block_size; +} + + +// SetBlockSize +void +BMutablePartition::SetBlockSize(off_t blockSize) +{ + fData->block_size = blockSize; +} + + +// Status +uint32 +BMutablePartition::Status() const +{ + return fData->status; +} + + +// Flags +uint32 +BMutablePartition::Flags() const +{ + return fData->flags; +} + + +// SetFlags +void +BMutablePartition::SetFlags(uint32 flags) +{ + fData->flags = flags; +} + + +// Volume +dev_t +BMutablePartition::Volume() const +{ + return fData->volume; +} + + +// Index +int32 +BMutablePartition::Index() const +{ + return fData->index; +} + + +// Name +const char* +BMutablePartition::Name() const +{ + return fData->name; +} + + +// SetName +status_t +BMutablePartition::SetName(const char* name) +{ + return set_string(fData->name, name); +} + + +// ContentName +const char* +BMutablePartition::ContentName() const +{ + return fData->content_name; +} + + +// SetContentName +status_t +BMutablePartition::SetContentName(const char* name) +{ + return set_string(fData->content_name, name); +} + + +// Type +const char* +BMutablePartition::Type() const +{ + return fData->type; +} + + +// SetType +status_t +BMutablePartition::SetType(const char* type) const +{ + return set_string(fData->type, type); +} + + +// ContentType +const char* +BMutablePartition::ContentType() const +{ + return fData->content_type; +} + + +// SetContentType +status_t +BMutablePartition::SetContentType(const char* type) const +{ + return set_string(fData->content_type, type); +} + + +// Parameters +const char* +BMutablePartition::Parameters() const +{ + return fData->parameters; +} + + +// SetParameters +status_t +BMutablePartition::SetParameters(const char* parameters) +{ + return set_string(fData->parameters, parameters); +} + + +// ContentParameters +const char* +BMutablePartition::ContentParameters() const +{ + return fData->content_parameters; +} + + +// SetContentParameters +status_t +BMutablePartition::SetContentParameters(const char* parameters) +{ + return set_string(fData->content_parameters, parameters); +} + + +// CreateChild +status_t +BMutablePartition::CreateChild(int32 index, BMutablePartition** child) +{ + // TODO: ... + return B_ERROR; +} + + +// DeleteChild +status_t +BMutablePartition::DeleteChild(int32 index) +{ + // TODO: ... + return B_ERROR; +} + + +// ChildAt +BMutablePartition* +BMutablePartition::ChildAt(int32 index) const +{ + return (BMutablePartition*)fChildren.ItemAt(index); +} + + +// CountChildren +int32 +BMutablePartition::CountChildren() const +{ + return fChildren.CountItems(); +} + + +// ChildCookie +void* +BMutablePartition::ChildCookie() const +{ + return fChildCookie; +} + + +// SetChildCookie +void +BMutablePartition::SetChildCookie(void* cookie) +{ + fChildCookie = cookie; +} + + +// constructor +BMutablePartition::BMutablePartition(BPartition::MutableDelegate* delegate) + : fDelegate(delegate), + fData(NULL), + fChildCookie(NULL) +{ +} + + +// Init +status_t +BMutablePartition::Init(const user_partition_data* partitionData) +{ + // allocate data structure + fData = new(nothrow) user_partition_data; + if (!fData) + return B_NO_MEMORY; + + memset(fData, 0, sizeof(user_partition_data)); + + // copy the flat data + fData->id = partitionData->id; + fData->offset = partitionData->offset; + fData->size = partitionData->size; + fData->content_size = partitionData->content_size; + fData->block_size = partitionData->block_size; + fData->status = partitionData->status; + fData->flags = partitionData->flags; [... truncated: 832 lines follow ...] From axeld at mail.berlios.de Thu Oct 11 09:46:56 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 11 Oct 2007 09:46:56 +0200 Subject: [Haiku-commits] r22504 - haiku/trunk/src/system/kernel Message-ID: <200710110746.l9B7kuk7025516@sheep.berlios.de> Author: axeld Date: 2007-10-11 09:46:55 +0200 (Thu, 11 Oct 2007) New Revision: 22504 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22504&view=rev Modified: haiku/trunk/src/system/kernel/sem.c haiku/trunk/src/system/kernel/thread.cpp Log: * IDs are now generally written as decimal numbers, rather than hexadecimal. * Fixed warnings with debug output turned on. * Shuffled functions around a bit. * Minor cleanup. Modified: haiku/trunk/src/system/kernel/sem.c =================================================================== --- haiku/trunk/src/system/kernel/sem.c 2007-10-10 21:35:22 UTC (rev 22503) +++ haiku/trunk/src/system/kernel/sem.c 2007-10-11 07:46:55 UTC (rev 22504) @@ -6,7 +6,7 @@ * Distributed under the terms of the NewOS License. */ -/* Semaphore code */ +/*! Semaphore code */ #include @@ -84,8 +84,7 @@ #define RELEASE_SEM_LOCK(s) release_spinlock(&(s).lock) static int remove_thread_from_sem(struct thread *thread, struct sem_entry *sem, - struct thread_queue *queue, status_t acquireStatus, - bool hasThreadLock); + struct thread_queue *queue, status_t acquireStatus, bool hasThreadLock); struct sem_timeout_args { thread_id blocked_thread; @@ -132,9 +131,9 @@ || (owner != -1 && sem->u.used.owner != owner)) continue; - kprintf("%p %6lx %5ld %6lx " + kprintf("%p %6ld %5ld %6ld " #ifdef DEBUG_LAST_ACQUIRER - "%6lx " + "%6ld " #endif " %s\n", sem, sem->id, sem->u.used.count, sem->u.used.owner, @@ -152,16 +151,16 @@ dump_sem(struct sem_entry *sem) { kprintf("SEM: %p\n", sem); - kprintf("id: %#lx\n", sem->id); + kprintf("id: %ld (%#lx)\n", sem->id, sem->id); if (sem->id >= 0) { kprintf("name: '%s'\n", sem->u.used.name); - kprintf("owner: 0x%lx\n", sem->u.used.owner); - kprintf("count: 0x%lx\n", sem->u.used.count); + kprintf("owner: %ld\n", sem->u.used.owner); + kprintf("count: %ld\n", sem->u.used.count); kprintf("queue: "); if (sem->u.used.queue.head != NULL) { struct thread *thread = sem->u.used.queue.head; while (thread != NULL) { - kprintf(" %lx", thread->id); + kprintf(" %ld", thread->id); thread = thread->queue_next; } kprintf("\n"); @@ -175,7 +174,7 @@ #endif } else { kprintf("next: %p\n", sem->u.unused.next); - kprintf("next_id: %#lx\n", sem->u.unused.next_id); + kprintf("next_id: %ld\n", sem->u.unused.next_id); } } @@ -230,16 +229,15 @@ } -/** \brief Appends a semaphore slot to the free list. - * - * The semaphore list must be locked. - * The slot's id field is not changed. It should already be set to -1. - * - * \param slot The index of the semaphore slot. - * \param nextID The ID the slot will get when reused. If < 0 the \a slot - * is used. - */ +/*! \brief Appends a semaphore slot to the free list. + The semaphore list must be locked. + The slot's id field is not changed. It should already be set to -1. + + \param slot The index of the semaphore slot. + \param nextID The ID the slot will get when reused. If < 0 the \a slot + is used. +*/ static void free_sem_slot(int slot, sem_id nextID) { @@ -259,7 +257,7 @@ } -static void +static inline void notify_sem_select_events(struct sem_entry* sem, uint16 events) { if (sem->u.used.select_infos) @@ -267,6 +265,80 @@ } +/*! Called from a timer handler. Wakes up a semaphore */ +static int32 +sem_timeout(timer *data) +{ + struct sem_timeout_args *args = (struct sem_timeout_args *)data->entry.prev; + struct thread *thread; + int slot; + int state; + struct thread_queue wakeupQueue; + + thread = thread_get_thread_struct(args->blocked_thread); + if (thread == NULL) + return B_HANDLED_INTERRUPT; + slot = args->blocked_sem_id % sMaxSems; + + state = disable_interrupts(); + GRAB_SEM_LOCK(sSems[slot]); + + TRACE(("sem_timeout: called on %p sem %ld, thread %ld\n", + data, args->blocked_sem_id, args->blocked_thread)); + + if (sSems[slot].id != args->blocked_sem_id) { + // this thread was not waiting on this semaphore + panic("sem_timeout: thread %ld was trying to wait on sem %ld which " + "doesn't exist!\n", args->blocked_thread, args->blocked_sem_id); + + RELEASE_SEM_LOCK(sSems[slot]); + restore_interrupts(state); + return B_HANDLED_INTERRUPT; + } + + clear_thread_queue(&wakeupQueue); + remove_thread_from_sem(thread, &sSems[slot], &wakeupQueue, B_TIMED_OUT, + false); + + RELEASE_SEM_LOCK(sSems[slot]); + + GRAB_THREAD_LOCK(); + // put the threads in the run q here to make sure we dont deadlock in sem_interrupt_thread + while ((thread = thread_dequeue(&wakeupQueue)) != NULL) { + scheduler_enqueue_in_run_queue(thread); + } + RELEASE_THREAD_LOCK(); + + restore_interrupts(state); + + return B_INVOKE_SCHEDULER; +} + + +/*! Fills the thread_info structure with information from the specified + thread. + The thread lock must be held when called. +*/ +static void +fill_sem_info(struct sem_entry *sem, sem_info *info, size_t size) +{ + info->sem = sem->id; + info->team = sem->u.used.owner; + strlcpy(info->name, sem->u.used.name, sizeof(info->name)); + info->count = sem->u.used.count; + + // ToDo: not sure if this is the latest holder, or the next + // holder... + if (sem->u.used.queue.head != NULL) + info->latest_holder = sem->u.used.queue.head->id; + else + info->latest_holder = -1; +} + + +// #pragma mark - Private Kernel API + + status_t sem_init(kernel_args *args) { @@ -308,14 +380,13 @@ } -/** Creates a semaphore with the given parameters. - * Note, the team_id is not checked, it must be correct, or else - * that semaphore might not be deleted. - * This function is only available from within the kernel, and - * should not be made public - if possible, we should remove it - * completely (and have only create_sem() exported). - */ - +/*! Creates a semaphore with the given parameters. + Note, the team_id is not checked, it must be correct, or else + that semaphore might not be deleted. + This function is only available from within the kernel, and + should not be made public - if possible, we should remove it + completely (and have only create_sem() exported). +*/ sem_id create_sem_etc(int32 count, const char *name, team_id owner) { @@ -387,85 +458,7 @@ } -sem_id -create_sem(int32 count, const char *name) -{ - return create_sem_etc(count, name, team_get_kernel_team_id()); -} - - status_t -delete_sem(sem_id id) -{ - struct thread_queue releaseQueue; - int32 releasedThreads; - struct thread *thread; - cpu_status state; - int32 slot; - char *name; - - if (sSemsActive == false) - return B_NO_MORE_SEMS; - if (id < 0) - return B_BAD_SEM_ID; - - slot = id % sMaxSems; - - state = disable_interrupts(); - GRAB_SEM_LOCK(sSems[slot]); - - if (sSems[slot].id != id) { - RELEASE_SEM_LOCK(sSems[slot]); - restore_interrupts(state); - TRACE(("delete_sem: invalid sem_id %ld\n", id)); - return B_BAD_SEM_ID; - } - - notify_sem_select_events(&sSems[slot], B_EVENT_INVALID); - sSems[slot].u.used.select_infos = NULL; - - releasedThreads = 0; - clear_thread_queue(&releaseQueue); - - // free any threads waiting for this semaphore - while ((thread = thread_dequeue(&sSems[slot].u.used.queue)) != NULL) { - thread->state = B_THREAD_READY; - thread->sem.acquire_status = B_BAD_SEM_ID; - thread->sem.count = 0; - thread_enqueue(thread, &releaseQueue); - releasedThreads++; - } - - sSems[slot].id = -1; - name = sSems[slot].u.used.name; - sSems[slot].u.used.name = NULL; - - RELEASE_SEM_LOCK(sSems[slot]); - - // append slot to the free list - GRAB_SEM_LIST_LOCK(); - free_sem_slot(slot, id + sMaxSems); - atomic_add(&sUsedSems, -1); - RELEASE_SEM_LIST_LOCK(); - - if (releasedThreads > 0) { - GRAB_THREAD_LOCK(); - while ((thread = thread_dequeue(&releaseQueue)) != NULL) { - scheduler_enqueue_in_run_queue(thread); - } - scheduler_reschedule(); - RELEASE_THREAD_LOCK(); - } - - restore_interrupts(state); - - free(name); - - return B_OK; -} - - -status_t select_sem(int32 id, struct select_info* info, bool kernel) { cpu_status state; @@ -539,53 +532,231 @@ } -/** Called from a timer handler. Wakes up a semaphore */ +/*! Wake up a thread that's blocked on a semaphore + this function must be entered with interrupts disabled and THREADLOCK held +*/ +status_t +sem_interrupt_thread(struct thread *thread) +{ + struct thread_queue wakeupQueue; + int32 slot; -static int32 -sem_timeout(timer *data) + TRACE(("sem_interrupt_thread: called on thread %p (%ld), blocked on sem %ld\n", + thread, thread->id, thread->sem.blocking)); + + if (thread->state != B_THREAD_WAITING || thread->sem.blocking < 0) + return B_BAD_VALUE; + if ((thread->sem.flags & B_CAN_INTERRUPT) == 0 + && ((thread->sem.flags & B_KILL_CAN_INTERRUPT) == 0 + || (thread->sig_pending & KILL_SIGNALS) == 0)) { + return B_NOT_ALLOWED; + } + + slot = thread->sem.blocking % sMaxSems; + + GRAB_SEM_LOCK(sSems[slot]); + + if (sSems[slot].id != thread->sem.blocking) { + panic("sem_interrupt_thread: thread %ld blocks on sem %ld, but that " + "sem doesn't exist!\n", thread->id, thread->sem.blocking); + } + + clear_thread_queue(&wakeupQueue); + if (remove_thread_from_sem(thread, &sSems[slot], &wakeupQueue, + B_INTERRUPTED, true) != B_OK) { + panic("sem_interrupt_thread: thread %ld not found in sem %ld's wait " + "queue\n", thread->id, thread->sem.blocking); + } + + RELEASE_SEM_LOCK(sSems[slot]); + + while ((thread = thread_dequeue(&wakeupQueue)) != NULL) { + scheduler_enqueue_in_run_queue(thread); + } + + return B_NO_ERROR; +} + + +/*! Forcibly removes a thread from a semaphores wait queue. May have to wake up + other threads in the process. All threads that need to be woken up are added + to the passed in thread_queue. + Must be called with semaphore lock held. +*/ +static int +remove_thread_from_sem(struct thread *thread, struct sem_entry *sem, + struct thread_queue *queue, status_t acquireStatus, bool hasThreadLock) { - struct sem_timeout_args *args = (struct sem_timeout_args *)data->entry.prev; - struct thread *thread; - int slot; + // remove the thread from the queue and place it in the supplied queue + if (thread_dequeue_id(&sem->u.used.queue, thread->id) != thread) + return B_ENTRY_NOT_FOUND; + + sem->u.used.count += thread->sem.acquire_count; + thread->state = thread->next_state = B_THREAD_READY; + thread->sem.acquire_status = acquireStatus; + thread_enqueue(thread, queue); + + // now see if more threads need to be woken up + while (sem->u.used.count > 0 + && thread_lookat_queue(&sem->u.used.queue) != NULL) { + int32 delta = min(thread->sem.count, sem->u.used.count); + + thread->sem.count -= delta; + if (thread->sem.count <= 0) { + thread = thread_dequeue(&sem->u.used.queue); + thread->state = thread->next_state = B_THREAD_READY; + thread_enqueue(thread, queue); + } + sem->u.used.count -= delta; + } + + if (sem->u.used.count > 0 && sem->u.used.select_infos != NULL) { + if (hasThreadLock) + RELEASE_THREAD_LOCK(); + + notify_sem_select_events(sem, B_EVENT_ACQUIRE_SEMAPHORE); + + if (hasThreadLock) + GRAB_THREAD_LOCK(); + } + + return B_OK; +} + + +/*! This function cycles through the sem table, deleting all the sems + that are owned by the specified team. +*/ +int +sem_delete_owned_sems(team_id owner) +{ int state; - struct thread_queue wakeupQueue; + int i; + int count = 0; - thread = thread_get_thread_struct(args->blocked_thread); - if (thread == NULL) - return B_HANDLED_INTERRUPT; - slot = args->blocked_sem_id % sMaxSems; + // ToDo: that looks horribly inefficient - maybe it would be better + // to have them in a list in the team + if (owner < 0) + return B_BAD_TEAM_ID; + state = disable_interrupts(); - GRAB_SEM_LOCK(sSems[slot]); + GRAB_SEM_LIST_LOCK(); - TRACE(("sem_timeout: called on 0x%x sem %ld, tid %ld\n", data, args->blocked_sem_id, args->blocked_thread)); + for (i = 0; i < sMaxSems; i++) { + if (sSems[i].id != -1 && sSems[i].u.used.owner == owner) { + sem_id id = sSems[i].id; - if (sSems[slot].id != args->blocked_sem_id) { - // this thread was not waiting on this semaphore - panic("sem_timeout: thid %ld was trying to wait on sem %ld which doesn't exist!\n", - args->blocked_thread, args->blocked_sem_id); + RELEASE_SEM_LIST_LOCK(); + restore_interrupts(state); + delete_sem(id); + count++; + + state = disable_interrupts(); + GRAB_SEM_LIST_LOCK(); + } + } + + RELEASE_SEM_LIST_LOCK(); + restore_interrupts(state); + + return count; +} + + +int32 +sem_max_sems(void) +{ + return sMaxSems; +} + + +int32 +sem_used_sems(void) +{ + return sUsedSems; +} + + +// #pragma mark - Public Kernel API + + +sem_id +create_sem(int32 count, const char *name) +{ + return create_sem_etc(count, name, team_get_kernel_team_id()); +} + + +status_t +delete_sem(sem_id id) +{ + struct thread_queue releaseQueue; + int32 releasedThreads; + struct thread *thread; + cpu_status state; + int32 slot; + char *name; + + if (sSemsActive == false) + return B_NO_MORE_SEMS; + if (id < 0) + return B_BAD_SEM_ID; + + slot = id % sMaxSems; + + state = disable_interrupts(); + GRAB_SEM_LOCK(sSems[slot]); + + if (sSems[slot].id != id) { RELEASE_SEM_LOCK(sSems[slot]); restore_interrupts(state); - return B_HANDLED_INTERRUPT; + TRACE(("delete_sem: invalid sem_id %ld\n", id)); + return B_BAD_SEM_ID; } - clear_thread_queue(&wakeupQueue); - remove_thread_from_sem(thread, &sSems[slot], &wakeupQueue, B_TIMED_OUT, - false); + notify_sem_select_events(&sSems[slot], B_EVENT_INVALID); + sSems[slot].u.used.select_infos = NULL; + releasedThreads = 0; + clear_thread_queue(&releaseQueue); + + // free any threads waiting for this semaphore + while ((thread = thread_dequeue(&sSems[slot].u.used.queue)) != NULL) { + thread->state = B_THREAD_READY; + thread->sem.acquire_status = B_BAD_SEM_ID; + thread->sem.count = 0; + thread_enqueue(thread, &releaseQueue); + releasedThreads++; + } + + sSems[slot].id = -1; + name = sSems[slot].u.used.name; + sSems[slot].u.used.name = NULL; + RELEASE_SEM_LOCK(sSems[slot]); - GRAB_THREAD_LOCK(); - // put the threads in the run q here to make sure we dont deadlock in sem_interrupt_thread - while ((thread = thread_dequeue(&wakeupQueue)) != NULL) { - scheduler_enqueue_in_run_queue(thread); + // append slot to the free list + GRAB_SEM_LIST_LOCK(); + free_sem_slot(slot, id + sMaxSems); + atomic_add(&sUsedSems, -1); + RELEASE_SEM_LIST_LOCK(); + + if (releasedThreads > 0) { + GRAB_THREAD_LOCK(); + while ((thread = thread_dequeue(&releaseQueue)) != NULL) { + scheduler_enqueue_in_run_queue(thread); + } + scheduler_reschedule(); + RELEASE_THREAD_LOCK(); } - RELEASE_THREAD_LOCK(); restore_interrupts(state); - return B_INVOKE_SCHEDULER; + free(name); + + return B_OK; } @@ -623,8 +794,10 @@ if (sSemsActive == false) return B_NO_MORE_SEMS; - if (!are_interrupts_enabled()) - panic("acquire_sem_etc: called with interrupts disabled for sem %#lx\n", id); + if (!are_interrupts_enabled()) { + panic("switch_sem_etc: called with interrupts disabled for sem %ld\n", + id); + } if (id < 0) return B_BAD_SEM_ID; @@ -637,7 +810,7 @@ GRAB_SEM_LOCK(sSems[slot]); if (sSems[slot].id != id) { - TRACE(("acquire_sem_etc: bad sem_id %ld\n", id)); + TRACE(("switch_sem_etc: bad sem %ld\n", id)); status = B_BAD_SEM_ID; goto err; } @@ -665,7 +838,7 @@ timer timeout_timer; // stick it on the stack, since we may be blocking here struct sem_timeout_args args; - TRACE(("acquire_sem_etc(id = %ld): block name = %s, thread = %p," + TRACE(("switch_sem_etc(id = %ld): block name = %s, thread = %p," " name = %s\n", id, sSems[slot].u.used.name, thread, thread->name)); // do a quick check to see if the thread has any pending signals @@ -691,7 +864,7 @@ thread_enqueue(thread, &sSems[slot].u.used.queue); if (timeout != B_INFINITE_TIMEOUT) { - TRACE(("sem_acquire_etc: setting timeout sem for %Ld usecs, semid %d, tid %d\n", + TRACE(("switch_sem_etc: setting timeout sem for %Ld usecs, sem %ld, thread %ld\n", timeout, id, thread->id)); // set up an event to go off with the thread struct as the data @@ -755,8 +928,8 @@ restore_interrupts(state); - TRACE(("acquire_sem_etc(id = %ld): exit block name = %s, " - "thread = %p (%s)\n", id, sSems[slot].u.used.name, thread, + TRACE(("switch_sem_etc(sem %ld): exit block name %s, " + "thread %ld (%s)\n", id, sSems[slot].u.used.name, thread->id, thread->name)); return thread->sem.acquire_status; } else { @@ -898,7 +1071,7 @@ status_t -get_sem_count(sem_id id, int32 *thread_count) +get_sem_count(sem_id id, int32 *_count) { int slot; int state; @@ -907,8 +1080,8 @@ return B_NO_MORE_SEMS; if (id < 0) return B_BAD_SEM_ID; - if (thread_count == NULL) - return EINVAL; + if (_count == NULL) + return B_BAD_VALUE; slot = id % sMaxSems; @@ -922,43 +1095,16 @@ return B_BAD_SEM_ID; } - *thread_count = sSems[slot].u.used.count; + *_count = sSems[slot].u.used.count; RELEASE_SEM_LOCK(sSems[slot]); restore_interrupts(state); - return B_NO_ERROR; + return B_OK; } -/** Fills the thread_info structure with information from the specified - * thread. - * The thread lock must be held when called. - */ - -static void -fill_sem_info(struct sem_entry *sem, sem_info *info, size_t size) -{ - info->sem = sem->id; - info->team = sem->u.used.owner; - strlcpy(info->name, sem->u.used.name, sizeof(info->name)); - info->count = sem->u.used.count; - - // ToDo: not sure if this is the latest holder, or the next - // holder... - if (sem->u.used.queue.head != NULL) - info->latest_holder = sem->u.used.queue.head->id; - else - info->latest_holder = -1; -} - - -/** The underscore is needed for binary compatibility with BeOS. - * OS.h contains the following macro: - * #define get_sem_info(sem, info) \ - * _get_sem_info((sem), (info), sizeof(*(info))) - */ - +/*! Called by the get_sem_info() macro. */ status_t _get_sem_info(sem_id id, struct sem_info *info, size_t size) { @@ -991,14 +1137,10 @@ } -/** The underscore is needed for binary compatibility with BeOS. - * OS.h contains the following macro: - * #define get_next_sem_info(team, cookie, info) \ - * _get_next_sem_info((team), (cookie), (info), sizeof(*(info))) - */ - +/*! Called by the get_next_sem_info() macro. */ status_t -_get_next_sem_info(team_id team, int32 *_cookie, struct sem_info *info, size_t size) +_get_next_sem_info(team_id team, int32 *_cookie, struct sem_info *info, + size_t size) { int state; int slot; @@ -1088,158 +1230,9 @@ } -/** Wake up a thread that's blocked on a semaphore - * this function must be entered with interrupts disabled and THREADLOCK held - */ +// #pragma mark - Syscalls -status_t -sem_interrupt_thread(struct thread *thread) -{ - struct thread_queue wakeupQueue; - int32 slot; - TRACE(("sem_interrupt_thread: called on thread %p (%d), blocked on sem 0x%x\n", - thread, thread->id, thread->sem.blocking)); - - if (thread->state != B_THREAD_WAITING || thread->sem.blocking < 0) - return B_BAD_VALUE; - if ((thread->sem.flags & B_CAN_INTERRUPT) == 0 - && ((thread->sem.flags & B_KILL_CAN_INTERRUPT) == 0 - || (thread->sig_pending & KILL_SIGNALS) == 0)) { - return B_NOT_ALLOWED; - } - - slot = thread->sem.blocking % sMaxSems; - - GRAB_SEM_LOCK(sSems[slot]); - - if (sSems[slot].id != thread->sem.blocking) { - panic("sem_interrupt_thread: thread 0x%lx sez it's blocking on sem 0x%lx, but that sem doesn't exist!\n", thread->id, thread->sem.blocking); - } - - clear_thread_queue(&wakeupQueue); - if (remove_thread_from_sem(thread, &sSems[slot], &wakeupQueue, - B_INTERRUPTED, true) != B_OK) { - panic("sem_interrupt_thread: thread 0x%lx not found in sem 0x%lx's wait queue\n", - thread->id, thread->sem.blocking); - } - - RELEASE_SEM_LOCK(sSems[slot]); - - while ((thread = thread_dequeue(&wakeupQueue)) != NULL) { - scheduler_enqueue_in_run_queue(thread); - } - - return B_NO_ERROR; -} - - -/** Forcibly removes a thread from a semaphores wait queue. May have to wake up - * other threads in the process. All threads that need to be woken up are added - * to the passed in thread_queue. - * Must be called with semaphore lock held. - */ - -static int -remove_thread_from_sem(struct thread *thread, struct sem_entry *sem, - struct thread_queue *queue, status_t acquireStatus, bool hasThreadLock) -{ - // remove the thread from the queue and place it in the supplied queue - if (thread_dequeue_id(&sem->u.used.queue, thread->id) != thread) - return B_ENTRY_NOT_FOUND; - - sem->u.used.count += thread->sem.acquire_count; - thread->state = thread->next_state = B_THREAD_READY; - thread->sem.acquire_status = acquireStatus; - thread_enqueue(thread, queue); - - // now see if more threads need to be woken up - while (sem->u.used.count > 0 - && thread_lookat_queue(&sem->u.used.queue) != NULL) { - int32 delta = min(thread->sem.count, sem->u.used.count); - - thread->sem.count -= delta; - if (thread->sem.count <= 0) { - thread = thread_dequeue(&sem->u.used.queue); - thread->state = thread->next_state = B_THREAD_READY; - thread_enqueue(thread, queue); - } - sem->u.used.count -= delta; - } - - if (sem->u.used.count > 0 && sem->u.used.select_infos != NULL) { - if (hasThreadLock) - RELEASE_THREAD_LOCK(); - - notify_sem_select_events(sem, B_EVENT_ACQUIRE_SEMAPHORE); - - if (hasThreadLock) - GRAB_THREAD_LOCK(); - } - - return B_OK; -} - - -/** this function cycles through the sem table, deleting all the sems that are owned by - * the passed team_id - */ - -int -sem_delete_owned_sems(team_id owner) -{ - int state; - int i; - int count = 0; - - // ToDo: that looks horribly inefficient - maybe it would be better - // to have them in a list in the team - - if (owner < 0) - return B_BAD_TEAM_ID; - - state = disable_interrupts(); - GRAB_SEM_LIST_LOCK(); - - for (i = 0; i < sMaxSems; i++) { - if (sSems[i].id != -1 && sSems[i].u.used.owner == owner) { - sem_id id = sSems[i].id; - - RELEASE_SEM_LIST_LOCK(); - restore_interrupts(state); - - delete_sem(id); - count++; - - state = disable_interrupts(); - GRAB_SEM_LIST_LOCK(); - } - } - - RELEASE_SEM_LIST_LOCK(); - restore_interrupts(state); - - return count; -} - - -int32 -sem_max_sems(void) -{ - return sMaxSems; -} - - -int32 -sem_used_sems(void) -{ - return sUsedSems; -} - - -// #pragma mark - - - sem_id _user_create_sem(int32 count, const char *userName) { Modified: haiku/trunk/src/system/kernel/thread.cpp =================================================================== --- haiku/trunk/src/system/kernel/thread.cpp 2007-10-10 21:35:22 UTC (rev 22503) +++ haiku/trunk/src/system/kernel/thread.cpp 2007-10-11 07:46:55 UTC (rev 22504) @@ -255,7 +255,7 @@ list_init(&thread->exit.waiters); thread->select_infos = NULL; - sprintf(temp, "thread_0x%lx_retcode_sem", thread->id); + sprintf(temp, "thread_%lx_retcode_sem", thread->id); thread->exit.sem = create_sem(0, temp); if (thread->exit.sem < B_OK) goto err1; @@ -558,7 +558,7 @@ bit >>= 1; } - TRACE(("get_death_stack: returning 0x%lx\n", sDeathStacks[i].address)); + TRACE(("get_death_stack: returning %#lx\n", sDeathStacks[i].address)); return (uint32)i; } @@ -599,16 +599,16 @@ // we can't let the interrupts disabled at this point enable_interrupts(); - TRACE(("thread_exit2, running on death stack 0x%lx\n", args.death_stack)); + TRACE(("thread_exit2, running on death stack %#lx\n", args.death_stack)); // delete the old kernel stack area - TRACE(("thread_exit2: deleting old kernel stack id 0x%lx for thread 0x%lx\n", + TRACE(("thread_exit2: deleting old kernel stack id %ld for thread %ld\n", args.old_kernel_stack, args.thread->id)); delete_area(args.old_kernel_stack); // remove this thread from all of the global lists - TRACE(("thread_exit2: removing thread 0x%lx from global lists\n", + TRACE(("thread_exit2: removing thread %ld from global lists\n", args.thread->id)); disable_interrupts(); @@ -683,7 +683,7 @@ if (thread->priority > B_DISPLAY_PRIORITY) { thread->priority = thread->next_priority = B_NORMAL_PRIORITY; - kprintf("thread 0x%lx made unreal\n", thread->id); + kprintf("thread %ld made unreal\n", thread->id); } } @@ -722,11 +722,11 @@ if (thread->id != id) continue; thread->priority = thread->next_priority = prio; - kprintf("thread 0x%lx set to priority %ld\n", id, prio); + kprintf("thread %ld set to priority %ld\n", id, prio); break; } if (!thread) - kprintf("thread 0x%lx not found\n", id); + kprintf("thread %ld (%#lx) not found\n", id, id); hash_close(sThreadHash, &i, false); return 0; @@ -757,11 +757,11 @@ continue; thread->state = thread->next_state = B_THREAD_SUSPENDED; - kprintf("thread 0x%lx suspended\n", id); + kprintf("thread %ld suspended\n", id); break; } if (!thread) - kprintf("thread 0x%lx not found\n", id); + kprintf("thread %ld (%#lx) not found\n", id, id); hash_close(sThreadHash, &i, false); return 0; @@ -793,12 +793,12 @@ if (thread->state == B_THREAD_SUSPENDED) { thread->state = thread->next_state = B_THREAD_READY; scheduler_enqueue_in_run_queue(thread); - kprintf("thread 0x%lx resumed\n", thread->id); + kprintf("thread %ld resumed\n", thread->id); } break; } if (!thread) - kprintf("thread 0x%lx not found\n", id); + kprintf("thread %ld (%#lx) not found\n", id, id); hash_close(sThreadHash, &i, false); return 0; @@ -825,7 +825,7 @@ if (err) kprintf("drop failed\n"); else - kprintf("thread 0x%lx dropped into user debugger\n", id); + kprintf("thread %ld dropped into user debugger\n", id); return 0; } @@ -867,7 +867,7 @@ struct death_entry *death = NULL; kprintf("THREAD: %p\n", thread); - kprintf("id: 0x%lx\n", thread->id); + kprintf("id: %ld (%#lx)\n", thread->id, thread->id); kprintf("name: \"%s\"\n", thread->name); kprintf("all_next: %p\nteam_next: %p\nq_next: %p\n", thread->all_next, thread->team_next, thread->queue_next); @@ -879,12 +879,12 @@ kprintf("(%d)\n", thread->cpu->cpu_num); else kprintf("\n"); - kprintf("sig_pending: 0x%lx\n", thread->sig_pending); + kprintf("sig_pending: %#lx\n", thread->sig_pending); kprintf("in_kernel: %d\n", thread->in_kernel); - kprintf(" sem.blocking: 0x%lx\n", thread->sem.blocking); - kprintf(" sem.count: 0x%lx\n", thread->sem.count); - kprintf(" sem.acquire_status: 0x%lx\n", thread->sem.acquire_status); - kprintf(" sem.flags: 0x%lx\n", thread->sem.flags); + kprintf(" sem.blocking: %ld\n", thread->sem.blocking); + kprintf(" sem.count: %ld\n", thread->sem.count); + kprintf(" sem.acquire_status: %#lx\n", thread->sem.acquire_status); + kprintf(" sem.flags: %#lx\n", thread->sem.flags); kprintf("condition variables:"); PrivateConditionVariableEntry* entry = thread->condition_variable_entry; @@ -898,22 +898,23 @@ kprintf("args: %p %p\n", thread->args1, thread->args2); kprintf("entry: %p\n", (void *)thread->entry); kprintf("team: %p, \"%s\"\n", thread->team, thread->team->name); - kprintf(" exit.sem: 0x%lx\n", thread->exit.sem); - kprintf(" exit.status: 0x%lx (%s)\n", thread->exit.status, strerror(thread->exit.status)); - kprintf(" exit.reason: 0x%x\n", thread->exit.reason); - kprintf(" exit.signal: 0x%x\n", thread->exit.signal); + kprintf(" exit.sem: %ld\n", thread->exit.sem); + kprintf(" exit.status: %#lx (%s)\n", thread->exit.status, strerror(thread->exit.status)); + kprintf(" exit.reason: %#x\n", thread->exit.reason); + kprintf(" exit.signal: %#x\n", thread->exit.signal); kprintf(" exit.waiters:\n"); while ((death = (struct death_entry*)list_get_next_item( &thread->exit.waiters, death)) != NULL) { - kprintf("\t%p (group 0x%lx, thread 0x%lx)\n", death, death->group_id, death->thread); + kprintf("\t%p (group %ld, thread %ld)\n", death, death->group_id, death->thread); } - kprintf("kernel_stack_area: 0x%lx\n", thread->kernel_stack_area); + kprintf("kernel_stack_area: %ld\n", thread->kernel_stack_area); kprintf("kernel_stack_base: %p\n", (void *)thread->kernel_stack_base); - kprintf("user_stack_area: 0x%lx\n", thread->user_stack_area); + kprintf("user_stack_area: %ld\n", thread->user_stack_area); kprintf("user_stack_base: %p\n", (void *)thread->user_stack_base); kprintf("user_local_storage: %p\n", (void *)thread->user_local_storage); [... truncated: 83 lines follow ...] From axeld at mail.berlios.de Thu Oct 11 09:49:05 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 11 Oct 2007 09:49:05 +0200 Subject: [Haiku-commits] r22505 - haiku/trunk/src/system/kernel/vm Message-ID: <200710110749.l9B7n5BQ025699@sheep.berlios.de> Author: axeld Date: 2007-10-11 09:49:04 +0200 (Thu, 11 Oct 2007) New Revision: 22505 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22505&view=rev Modified: haiku/trunk/src/system/kernel/vm/vm.cpp Log: No need to print and try NULL at all. Modified: haiku/trunk/src/system/kernel/vm/vm.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm.cpp 2007-10-11 07:46:55 UTC (rev 22504) +++ haiku/trunk/src/system/kernel/vm/vm.cpp 2007-10-11 07:49:04 UTC (rev 22505) @@ -3698,7 +3698,7 @@ #endif dprintf("stack trace:\n"); - while (status == B_OK) { + while (status == B_OK && frame.return_address != NULL) { dprintf(" %p", frame.return_address); area = vm_area_lookup(addressSpace, (addr_t)frame.return_address); From axeld at mail.berlios.de Thu Oct 11 10:01:19 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 11 Oct 2007 10:01:19 +0200 Subject: [Haiku-commits] r22506 - in haiku/trunk: headers/private/kernel src/system/kernel/vm Message-ID: <200710110801.l9B81J4w026262@sheep.berlios.de> Author: axeld Date: 2007-10-11 10:01:18 +0200 (Thu, 11 Oct 2007) New Revision: 22506 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22506&view=rev Modified: haiku/trunk/headers/private/kernel/vm_priv.h haiku/trunk/src/system/kernel/vm/vm_daemons.cpp haiku/trunk/src/system/kernel/vm/vm_low_memory.cpp haiku/trunk/src/system/kernel/vm/vm_page.cpp Log: * Reworked stealing pages: the page thief thread is gone now, vm_page_reserve_pages() and vm_page_allocate_page() will now steal pages from the inactive queue as needed. * We currently never steal active pages anymore, but this might need to be revised later (therefore, the page scanner never waits anymore, but uses mutex_trylock() to lock a cache). * The page scanner and writer now both run at normal priority - let's see how that will work out. * Introduced an inactive queue. * Instead of shuffling pages around in the queue (and therefore destroying LRU) the page stealing mechanism now uses a marker page to be able to release the page lock without losing its position in the queue. * The page writer now always grabs the whole release count of the semaphore, so that there won't be a huge backlog to catch up with. * vm_page_num_free_pages() now also includes the inactive queue as well as the reserved pages (they are no longer regarded as free pages). * Added a insert_page_after() function that inserts a page after another one, needed by the marker code. * clear_page() now gets a vm_page instead of a physical address which simplified some code. * Removed superfluous initialization of the queues (if those aren't zeroed on start, we would have serious problems, anyway). * Removed old and unimplemented dump_free_page_table() ("free_pages") KDL command. Modified: haiku/trunk/headers/private/kernel/vm_priv.h =================================================================== --- haiku/trunk/headers/private/kernel/vm_priv.h 2007-10-11 07:49:04 UTC (rev 22505) +++ haiku/trunk/headers/private/kernel/vm_priv.h 2007-10-11 08:01:18 UTC (rev 22506) @@ -49,6 +49,7 @@ bool isUser, addr_t *newip); void vm_unreserve_memory(size_t bytes); status_t vm_try_reserve_memory(size_t bytes); +void vm_schedule_page_scanner(uint32 target); status_t vm_daemon_init(void); const char *page_state_to_string(int state); Modified: haiku/trunk/src/system/kernel/vm/vm_daemons.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_daemons.cpp 2007-10-11 07:49:04 UTC (rev 22505) +++ haiku/trunk/src/system/kernel/vm/vm_daemons.cpp 2007-10-11 08:01:18 UTC (rev 22506) @@ -65,7 +65,14 @@ if (cache == NULL) return false; +#if 0 mutex_lock(&cache->lock); +#else + if (mutex_trylock(&cache->lock) != B_OK) { + vm_cache_release_ref(cache); + return false; + } +#endif if (cache != page->cache || _IgnorePage(page)) { mutex_unlock(&cache->lock); @@ -185,8 +192,7 @@ scanPagesCount = kMaxScanPagesCount - (kMaxScanPagesCount - kMinScanPagesCount) * pagesLeft / sLowPagesCount; - uint32 leftToFree = 32 + (scanPagesCount - 32) - * pagesLeft / sLowPagesCount; + uint32 leftToFree = sLowPagesCount - pagesLeft; dprintf("wait interval %Ld, scan pages %lu, free %lu, target %lu\n", scanWaitInterval, scanPagesCount, pagesLeft, leftToFree); @@ -210,6 +216,13 @@ } +void +vm_schedule_page_scanner(uint32 target) +{ + release_sem(sPageDaemonSem); +} + + status_t vm_daemon_init() { @@ -223,7 +236,7 @@ // create a kernel thread to select pages for pageout thread_id thread = spawn_kernel_thread(&page_daemon, "page daemon", - B_LOW_PRIORITY + 1, NULL); + B_NORMAL_PRIORITY, NULL); send_signal_etc(thread, SIGCONT, B_DO_NOT_RESCHEDULE); return B_OK; Modified: haiku/trunk/src/system/kernel/vm/vm_low_memory.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_low_memory.cpp 2007-10-11 07:49:04 UTC (rev 22505) +++ haiku/trunk/src/system/kernel/vm/vm_low_memory.cpp 2007-10-11 08:01:18 UTC (rev 22506) @@ -17,6 +17,7 @@ #include #include #include +#include //#define TRACE_LOW_MEMORY @@ -144,6 +145,7 @@ { // TODO: take requirements into account + vm_schedule_page_scanner(requirements); release_sem(sLowMemoryWaitSem); } Modified: haiku/trunk/src/system/kernel/vm/vm_page.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_page.cpp 2007-10-11 07:49:04 UTC (rev 22505) +++ haiku/trunk/src/system/kernel/vm/vm_page.cpp 2007-10-11 08:01:18 UTC (rev 22506) @@ -46,22 +46,21 @@ uint32 count; } page_queue; -extern bool trimming_cycle; - static page_queue sFreePageQueue; static page_queue sClearPageQueue; static page_queue sModifiedPageQueue; +static page_queue sInactivePageQueue; static page_queue sActivePageQueue; static vm_page *sPages; static addr_t sPhysicalPageOffset; static size_t sNumPages; static size_t sReservedPages; +static vint32 sPageDeficit; static ConditionVariable sFreePageCondition; static spinlock sPageLock; -static sem_id sThiefWaitSem; static sem_id sWriterWaitSem; @@ -188,11 +187,36 @@ } -static int -dump_free_page_table(int argc, char **argv) +/*! Inserts \a page after the \a before page in the \a queue. */ +static void +insert_page_after(page_queue *queue, vm_page *before, vm_page *page) { - dprintf("not finished\n"); - return 0; +#ifdef DEBUG_PAGE_QUEUE + if (page->queue != NULL) { + panic("enqueue_page(queue: %p, page: %p): page thinks it is " + "already in queue %p", queue, page, page->queue); + } +#endif // DEBUG_PAGE_QUEUE + + if (before == NULL) { + enqueue_page(queue, page); + return; + } + + page->queue_next = before->queue_next; + if (page->queue_next != NULL) + page->queue_next->queue_prev = page; + page->queue_prev = before; + before->queue_next = page; + + if (queue->tail == before) + queue->tail = page; + + queue->count++; + +#ifdef DEBUG_PAGE_QUEUE + page->queue = queue; +#endif } @@ -292,7 +316,7 @@ || argv[index][1] != 'x') { kprintf("usage: page [-p|-v]
\n" " -v looks up a virtual address for the page, -p a physical address.\n" - " Default is to look for the page structure address directly\n."); + " Default is to look for the page structure address directly.\n"); return 0; } @@ -308,7 +332,6 @@ addressSpace->translation_map.ops->query_interrupt( &addressSpace->translation_map, address, &address, &flags); - } page = vm_lookup_page(address / B_PAGE_SIZE); } else @@ -365,6 +388,8 @@ queue = &sModifiedPageQueue; else if (!strcmp(argv[1], "active")) queue = &sActivePageQueue; + else if (!strcmp(argv[1], "inactive")) + queue = &sInactivePageQueue; else { kprintf("page_queue: unknown queue \"%s\".\n", argv[1]); return 0; @@ -375,24 +400,27 @@ if (argc == 3) { struct vm_page *page = queue->head; - const char *type = "unknown"; + const char *type = "none"; int i; - switch (page->cache->type) { - case CACHE_TYPE_RAM: - type = "RAM"; - break; - case CACHE_TYPE_DEVICE: - type = "device"; - break; - case CACHE_TYPE_VNODE: - type = "vnode"; - break; - case CACHE_TYPE_NULL: - type = "null"; - break; - default: - break; + if (page->cache != NULL) { + switch (page->cache->type) { + case CACHE_TYPE_RAM: + type = "RAM"; + break; + case CACHE_TYPE_DEVICE: + type = "device"; + break; + case CACHE_TYPE_VNODE: + type = "vnode"; + break; + case CACHE_TYPE_NULL: + type = "null"; + break; + default: + type = "???"; + break; + } } kprintf("page cache type state wired usage\n"); @@ -430,6 +458,7 @@ counter[PAGE_STATE_WIRED], counter[PAGE_STATE_MODIFIED], counter[PAGE_STATE_FREE], counter[PAGE_STATE_CLEAR]); kprintf("reserved pages: %lu\n", sReservedPages); + kprintf("page deficit: %lu\n", sPageDeficit); kprintf("\nfree queue: %p, count = %ld\n", &sFreePageQueue, sFreePageQueue.count); @@ -439,10 +468,19 @@ sModifiedPageQueue.count); kprintf("active queue: %p, count = %ld\n", &sActivePageQueue, sActivePageQueue.count); + kprintf("inactive queue: %p, count = %ld\n", &sInactivePageQueue, + sInactivePageQueue.count); return 0; } +static inline size_t +free_page_queue_count(void) +{ + return sFreePageQueue.count + sClearPageQueue.count; +} + + static status_t set_page_state_nolock(vm_page *page, int pageState) { @@ -452,11 +490,13 @@ switch (page->state) { case PAGE_STATE_BUSY: case PAGE_STATE_ACTIVE: - case PAGE_STATE_INACTIVE: case PAGE_STATE_WIRED: case PAGE_STATE_UNUSED: fromQueue = &sActivePageQueue; break; + case PAGE_STATE_INACTIVE: + fromQueue = &sInactivePageQueue; + break; case PAGE_STATE_MODIFIED: fromQueue = &sModifiedPageQueue; break; @@ -480,11 +520,13 @@ switch (pageState) { case PAGE_STATE_BUSY: case PAGE_STATE_ACTIVE: - case PAGE_STATE_INACTIVE: case PAGE_STATE_WIRED: case PAGE_STATE_UNUSED: toQueue = &sActivePageQueue; break; + case PAGE_STATE_INACTIVE: + toQueue = &sInactivePageQueue; + break; case PAGE_STATE_MODIFIED: toQueue = &sModifiedPageQueue; break; @@ -498,11 +540,11 @@ panic("vm_page_set_state: invalid target state %d\n", pageState); } - if (pageState == PAGE_STATE_CLEAR || pageState == PAGE_STATE_FREE) { - if (sFreePageQueue.count + sClearPageQueue.count <= sReservedPages) - sFreePageCondition.NotifyAll(); + if (pageState == PAGE_STATE_CLEAR || pageState == PAGE_STATE_FREE || pageState == PAGE_STATE_INACTIVE) { + if (sPageDeficit > 0) + sFreePageCondition.NotifyOne(); - if (page->cache != NULL) + if (pageState != PAGE_STATE_INACTIVE && page->cache != NULL) panic("to be freed page %p has cache", page); } @@ -526,24 +568,23 @@ if (dequeued) { page->state = state; - enqueue_page(&sActivePageQueue, page); + enqueue_page(state == PAGE_STATE_ACTIVE + ? &sActivePageQueue : &sInactivePageQueue, page); } else set_page_state_nolock(page, state); } static void -clear_page(addr_t pa) +clear_page(struct vm_page *page) { - addr_t va; + addr_t virtualAddress; + vm_get_physical_page(page->physical_page_number << PAGE_SHIFT, + &virtualAddress, PHYSICAL_PAGE_CAN_WAIT); -// dprintf("clear_page: clearing page 0x%x\n", pa); + memset((void *)virtualAddress, 0, B_PAGE_SIZE); - vm_get_physical_page(pa, &va, PHYSICAL_PAGE_CAN_WAIT); - - memset((void *)va, 0, B_PAGE_SIZE); - - vm_put_physical_page(va); + vm_put_physical_page(virtualAddress); } @@ -588,7 +629,7 @@ scrubCount = i; for (i = 0; i < scrubCount; i++) { - clear_page(page[i]->physical_page_number * B_PAGE_SIZE); + clear_page(page[i]); } state = disable_interrupts(); @@ -650,7 +691,12 @@ page_writer(void* /*unused*/) { while (true) { - acquire_sem_etc(sWriterWaitSem, 1, B_RELATIVE_TIMEOUT, 3000000); + int32 count = 0; + get_sem_count(sWriterWaitSem, &count); + if (count == 0) + count = 1; + + acquire_sem_etc(sWriterWaitSem, count, B_RELATIVE_TIMEOUT, 3000000); // all 3 seconds when no one triggers us const uint32 kNumPages = 32; @@ -754,171 +800,233 @@ } -/*! The page thief is a "service" that runs in its own thread, and only - gets active in low memory situations. - Its job is to remove unused pages from caches and recycle it. When - low memory is critical, this is potentially the only source of free - pages for the system, so it cannot block on an external service. -*/ -static status_t -page_thief(void* /*unused*/) +static bool +steal_page(vm_page *page, bool stealActive) { - bigtime_t timeout = B_INFINITE_TIMEOUT; + // try to lock the page's cache - while (true) { - acquire_sem_etc(sThiefWaitSem, 1, B_RELATIVE_TIMEOUT, timeout); + class PageCacheTryLocker { + public: + PageCacheTryLocker(vm_page *page) + : + fIsLocked(false), + fOwnsLock(false) + { + fCache = vm_cache_acquire_page_cache_ref(page); + if (fCache != NULL) { + if (fCache->lock.holder != thread_get_current_thread_id()) { + if (mutex_trylock(&fCache->lock) != B_OK) + return; - int32 state = vm_low_memory_state(); - uint32 steal; - int32 score; - switch (state) { - default: - timeout = B_INFINITE_TIMEOUT; - continue; - case B_LOW_MEMORY_NOTE: - timeout = 1000000; - continue; + fOwnsLock = true; + } - case B_LOW_MEMORY_WARNING: - steal = 50; - score = -5; - timeout = 1000000; - break; - case B_LOW_MEMORY_CRITICAL: - steal = 500; - score = -1; - timeout = 100000; - break; + if (fCache == page->cache) + fIsLocked = true; + } } - vm_page* page = NULL; - bool stealActive = false, desperate = false; - InterruptsSpinLocker locker(sPageLock); + ~PageCacheTryLocker() + { + if (fOwnsLock) + mutex_unlock(&fCache->lock); + if (fCache != NULL) + vm_cache_release_ref(fCache); + } - while (steal > 0) { - if (!locker.IsLocked()) - locker.Lock(); + bool IsLocked() { return fIsLocked; } - // find a candidate to steal from the inactive queue + private: + vm_cache *fCache; + bool fIsLocked; + bool fOwnsLock; + } cacheLocker(page); - int32 i = sActivePageQueue.count; - while (i-- > 0) { - // move page to the tail of the queue so that we don't - // scan it again directly - page = dequeue_page(&sActivePageQueue); - enqueue_page(&sActivePageQueue, page); + if (!cacheLocker.IsLocked()) + return false; - if ((page->state == PAGE_STATE_INACTIVE - || (stealActive && page->state == PAGE_STATE_ACTIVE - && page->wired_count == 0)) - && page->usage_count <= score) - break; - } + // check again if that page is still a candidate + if (page->state != PAGE_STATE_INACTIVE + && (!stealActive || page->state != PAGE_STATE_ACTIVE + || page->wired_count != 0)) + return false; - if (i < 0) { - if (score == 0) { - if (state != B_LOW_MEMORY_CRITICAL) - break; - if (stealActive && score > 5) - break; + // recheck eventual last minute changes + uint32 flags; + vm_remove_all_page_mappings(page, &flags); + if ((flags & PAGE_MODIFIED) != 0) { + // page was modified, don't steal it + vm_page_set_state(page, PAGE_STATE_MODIFIED); + return false; + } else if ((flags & PAGE_ACCESSED) != 0) { + // page is in active use, don't steal it + vm_page_set_state(page, PAGE_STATE_ACTIVE); + return false; + } - // when memory is really low, we really want pages - if (stealActive) { - score = 127; - desperate = true; - } else { - stealActive = true; - score = 5; - steal = 5; - } + // we can now steal this page - // let the page writer clear some pages for reuse - release_sem_etc(sWriterWaitSem, 1, B_DO_NOT_RESCHEDULE); - continue; - } + //dprintf(" steal page %p from cache %p%s\n", page, page->cache, + // page->state == PAGE_STATE_INACTIVE ? "" : " (ACTIVE)"); - score = 0; - continue; - } + vm_cache_remove_page(page->cache, page); + remove_page_from_queue(page->state == PAGE_STATE_ACTIVE + ? &sActivePageQueue : &sInactivePageQueue, page); + return true; +} - locker.Unlock(); - // try to lock the page's cache +static void +remove_page_marker(struct vm_page &marker) +{ + if (marker.state == PAGE_STATE_UNUSED) + return; - class PageCacheTryLocker { - public: - PageCacheTryLocker(vm_page *page) - : fIsLocked(false) - { - fCache = vm_cache_acquire_page_cache_ref(page); - if (fCache != NULL - && mutex_trylock(&fCache->lock) == B_OK) { - if (fCache == page->cache) - fIsLocked = true; - else - mutex_unlock(&fCache->lock); - } - } + page_queue *queue; + vm_page *page; - ~PageCacheTryLocker() - { - if (fIsLocked) - mutex_unlock(&fCache->lock); - if (fCache != NULL) - vm_cache_release_ref(fCache); - } + switch (marker.state) { + case PAGE_STATE_ACTIVE: + queue = &sActivePageQueue; + break; + case PAGE_STATE_INACTIVE: + queue = &sInactivePageQueue; + break; - bool IsLocked() { return fIsLocked; } + default: + return; + } - private: - vm_cache *fCache; - bool fIsLocked; - } cacheLocker(page); + remove_page_from_queue(queue, &marker); + marker.state = PAGE_STATE_UNUSED; +} - if (!cacheLocker.IsLocked()) - continue; - // check again if that page is still a candidate - if (page->state != PAGE_STATE_INACTIVE - && (!stealActive || page->state != PAGE_STATE_ACTIVE - || page->wired_count != 0)) - continue; +static vm_page * +find_page_candidate(struct vm_page &marker, bool stealActive) +{ + InterruptsSpinLocker locker(sPageLock); + page_queue *queue; + vm_page *page; - // recheck eventual last minute changes - uint32 flags; - vm_remove_all_page_mappings(page, &flags); - if ((flags & PAGE_MODIFIED) != 0) { - // page was modified, don't steal it - vm_page_set_state(page, PAGE_STATE_MODIFIED); - continue; - } else if ((flags & PAGE_ACCESSED) != 0 && !desperate) { - // page is in active use, don't steal it - vm_page_set_state(page, PAGE_STATE_ACTIVE); - continue; + switch (marker.state) { + case PAGE_STATE_ACTIVE: + queue = &sActivePageQueue; + page = marker.queue_next; + remove_page_from_queue(queue, &marker); + marker.state = PAGE_STATE_UNUSED; + break; + case PAGE_STATE_INACTIVE: + queue = &sInactivePageQueue; + page = marker.queue_next; + remove_page_from_queue(queue, &marker); + marker.state = PAGE_STATE_UNUSED; + break; + default: + queue = &sInactivePageQueue; + page = sInactivePageQueue.head; + if (page == NULL && stealActive) { + queue = &sActivePageQueue; + page = sActivePageQueue.head; } + break; + } - // we can now steal this page + while (page != NULL) { + if (page->type != PAGE_TYPE_DUMMY + && (page->state == PAGE_STATE_INACTIVE + || (stealActive && page->state == PAGE_STATE_ACTIVE + && page->wired_count == 0))) { + // insert marker + marker.state = queue == &sActivePageQueue ? PAGE_STATE_ACTIVE : PAGE_STATE_INACTIVE; + insert_page_after(queue, page, &marker); + return page; + } - //dprintf(" steal page %p from cache %p\n", page, page->cache); - - vm_cache_remove_page(page->cache, page); - vm_page_set_state(page, PAGE_STATE_FREE); - steal--; + page = page->queue_next; + if (page == NULL && stealActive && queue != &sActivePageQueue) { + queue = &sActivePageQueue; + page = sActivePageQueue.head; } } - return B_OK; + return NULL; } -/*! This triggers a run of the page thief - depending on the memory - pressure, it might not actually do anything, though. - This function is registered as a low memory handler. -*/ -static void -schedule_page_thief(void* /*unused*/, int32 level) +static size_t +steal_pages(vm_page **pages, size_t count, bool reserve) { - release_sem(sThiefWaitSem); + size_t maxCount = count; + + while (true) { + vm_page marker; + marker.type = PAGE_TYPE_DUMMY; + marker.cache = NULL; + marker.state = PAGE_STATE_UNUSED; + + bool tried = false; + size_t stolen = 0; + + while (count > 0) { + vm_page *page = find_page_candidate(marker, false); + if (page == NULL) + break; + + if (steal_page(page, false)) { + if (reserve) { + InterruptsSpinLocker _(sPageLock); + enqueue_page(&sFreePageQueue, page); + page->state = PAGE_STATE_FREE; + } else if (stolen < maxCount) { + pages[stolen] = page; + } + stolen++; + count--; + } else + tried = true; + } + + InterruptsSpinLocker locker(sPageLock); + remove_page_marker(marker); + + if (reserve && sReservedPages <= free_page_queue_count() + || count == 0 + || !reserve && (sInactivePageQueue.count > 0 + || free_page_queue_count() > sReservedPages)) + return stolen; + + if (stolen && !tried && sInactivePageQueue.count > 0) { + count++; + continue; + } + if (tried) { + // we had our go, but there are pages left, let someone else + // try + locker.Unlock(); + sFreePageCondition.NotifyOne(); + locker.Lock(); + } + + // we need to wait for pages to become inactive + + ConditionVariableEntry freeConditionEntry; + sPageDeficit++; + freeConditionEntry.Add(&sFreePageQueue); + locker.Unlock(); + + vm_low_memory(count); + //snooze(50000); + // sleep for 50ms + + freeConditionEntry.Wait(); + + locker.Lock(); + sPageDeficit--; + + if (reserve && sReservedPages <= free_page_queue_count()) + return stolen; + } } @@ -1028,26 +1136,8 @@ status_t vm_page_init(kernel_args *args) { - uint32 i; - TRACE(("vm_page_init: entry\n")); - sPageLock = 0; - - // initialize queues - sFreePageQueue.head = NULL; - sFreePageQueue.tail = NULL; - sFreePageQueue.count = 0; - sClearPageQueue.head = NULL; - sClearPageQueue.tail = NULL; - sClearPageQueue.count = 0; - sModifiedPageQueue.head = NULL; - sModifiedPageQueue.tail = NULL; - sModifiedPageQueue.count = 0; - sActivePageQueue.head = NULL; - sActivePageQueue.tail = NULL; - sActivePageQueue.count = 0; - // map in the new free page table sPages = (vm_page *)vm_allocate_early(args, sNumPages * sizeof(vm_page), ~0L, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); @@ -1056,7 +1146,7 @@ sPages, sNumPages, (unsigned int)(sNumPages * sizeof(vm_page)))); // initialize the free page table - for (i = 0; i < sNumPages; i++) { + for (uint32 i = 0; i < sNumPages; i++) { sPages[i].physical_page_number = sPhysicalPageOffset + i; sPages[i].type = PAGE_TYPE_PHYSICAL; sPages[i].state = PAGE_STATE_FREE; @@ -1077,7 +1167,7 @@ TRACE(("initialized table\n")); // mark some of the page ranges inuse - for (i = 0; i < args->num_physical_allocated_ranges; i++) { + for (uint32 i = 0; i < args->num_physical_allocated_ranges; i++) { vm_mark_page_range_inuse(args->physical_allocated_range[i].start / B_PAGE_SIZE, args->physical_allocated_range[i].size / B_PAGE_SIZE); } @@ -1099,7 +1189,6 @@ B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); add_debugger_command("page_stats", &dump_page_stats, "Dump statistics about page usage"); - add_debugger_command("free_pages", &dump_free_page_table, "Dump list of free pages"); add_debugger_command("page", &dump_page, "Dump page info"); add_debugger_command("page_queue", &dump_page_queue, "Dump page queue"); add_debugger_command("find_page", &find_page, @@ -1124,17 +1213,11 @@ // start page writer and page thief sWriterWaitSem = create_sem(0, "page writer"); - sThiefWaitSem = create_sem(0, "page thief"); thread = spawn_kernel_thread(&page_writer, "page writer", - B_LOW_PRIORITY + 2, NULL); + B_NORMAL_PRIORITY, NULL); send_signal_etc(thread, SIGCONT, B_DO_NOT_RESCHEDULE); - thread = spawn_kernel_thread(&page_thief, "page thief", - B_LOW_PRIORITY, NULL); - send_signal_etc(thread, SIGCONT, B_DO_NOT_RESCHEDULE); - - register_low_memory_handler(schedule_page_thief, NULL, 100); return B_OK; } @@ -1211,9 +1294,7 @@ sReservedPages -= count; - // TODO: find out why the line below won't work correctly - //if (vm_page_num_free_pages() <= sReservedPages + count) - if (!kernel_startup) + if (sPageDeficit > 0) sFreePageCondition.NotifyAll(); } @@ -1232,24 +1313,15 @@ InterruptsSpinLocker locker(sPageLock); sReservedPages += count; - size_t freePages = vm_page_num_free_pages(); + size_t freePages = free_page_queue_count(); if (sReservedPages <= freePages) return; - ConditionVariableEntry freeConditionEntry; - vm_low_memory(sReservedPages - freePages); + locker.Unlock(); - while (true) { - // we need to wait until new pages become available - freeConditionEntry.Add(&sFreePageQueue); - locker.Unlock(); - - freeConditionEntry.Wait(); - - locker.Lock(); - if (sReservedPages <= vm_page_num_free_pages()) - break; - } + steal_pages(NULL, count + 1, true); + // we get one more, just in case we can do something someone + // else can't } @@ -1277,7 +1349,7 @@ vm_page *page = NULL; while (true) { - if (reserved || sReservedPages < vm_page_num_free_pages()) { + if (reserved || sReservedPages < free_page_queue_count()) { page = dequeue_page(queue); if (page == NULL) { #ifdef DEBUG @@ -1291,29 +1363,21 @@ } } - if (page == NULL) { - if (reserved) - panic("Had reserved page, but there is none!"); -#ifdef DEBUG - if (otherQueue->count != 0) { - panic("other queue %p corrupted, count = %d\n", otherQueue, - otherQueue->count); - } -#endif - - freeConditionEntry.Add(&sFreePageQueue); - vm_low_memory(sReservedPages + 1); - } - if (page != NULL) break; - // we need to wait until new pages become available + if (reserved) + panic("Had reserved page, but there is none!"); + + // steal one from the inactive list locker.Unlock(); + size_t stolen = steal_pages(&page, 1, false); + locker.Lock(); - freeConditionEntry.Wait(); - - locker.Lock(); + if (stolen == 0) { + // just try again + continue; + } } if (page->cache != NULL) @@ -1329,7 +1393,7 @@ // if needed take the page from the free queue and zero it out if (pageState == PAGE_STATE_CLEAR && oldPageState != PAGE_STATE_CLEAR) - clear_page(page->physical_page_number * B_PAGE_SIZE); + clear_page(page); return page; } @@ -1406,10 +1470,8 @@ if (firstPage != NULL && pageState == PAGE_STATE_CLEAR) { for (uint32 i = 0; i < length; i++) { - if (!sPages[start + i].is_cleared) { - clear_page(sPages[start + i].physical_page_number - * B_PAGE_SIZE); - } + if (!sPages[start + i].is_cleared) + clear_page(&sPages[start + i]); } } @@ -1459,11 +1521,13 @@ switch (page->state) { case PAGE_STATE_BUSY: case PAGE_STATE_ACTIVE: - case PAGE_STATE_INACTIVE: case PAGE_STATE_WIRED: case PAGE_STATE_UNUSED: queue = &sActivePageQueue; break; + case PAGE_STATE_INACTIVE: + queue = &sInactivePageQueue; + break; case PAGE_STATE_MODIFIED: queue = &sModifiedPageQueue; break; @@ -1498,6 +1562,11 @@ size_t vm_page_num_free_pages(void) { - return sFreePageQueue.count + sClearPageQueue.count; + size_t reservedPages = sReservedPages; + size_t count = free_page_queue_count() + sInactivePageQueue.count; + if (reservedPages > count) + return 0; + + return count - reservedPages; } From axeld at mail.berlios.de Thu Oct 11 10:30:19 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 11 Oct 2007 10:30:19 +0200 Subject: [Haiku-commits] r22507 - haiku/trunk/src/system/kernel Message-ID: <200710110830.l9B8UJT9027245@sheep.berlios.de> Author: axeld Date: 2007-10-11 10:30:18 +0200 (Thu, 11 Oct 2007) New Revision: 22507 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22507&view=rev Modified: haiku/trunk/src/system/kernel/port.c haiku/trunk/src/system/kernel/team.cpp Log: * IDs are now generally printed as decimal values. * Removed old port test code, it doesn't belong there. * Cleanup. Modified: haiku/trunk/src/system/kernel/port.c =================================================================== --- haiku/trunk/src/system/kernel/port.c 2007-10-11 08:01:18 UTC (rev 22506) +++ haiku/trunk/src/system/kernel/port.c 2007-10-11 08:30:18 UTC (rev 22507) @@ -6,7 +6,7 @@ * Distributed under the terms of the NewOS License. */ -/* ports for IPC */ +/*! Ports for IPC */ #include @@ -54,19 +54,14 @@ struct list msg_queue; }; -// internal API -static int dump_port_list(int argc, char **argv); -static int dump_port_info(int argc, char **argv); -static void _dump_port_info(struct port_entry *port); +#define MAX_QUEUE_LENGTH 4096 +#define PORT_MAX_MESSAGE_SIZE 65536 // sMaxPorts must be power of 2 static int32 sMaxPorts = 4096; static int32 sUsedPorts = 0; -#define MAX_QUEUE_LENGTH 4096 -#define PORT_MAX_MESSAGE_SIZE 65536 - static struct port_entry *sPorts = NULL; static area_id sPortArea = 0; static bool sPortsActive = false; @@ -81,143 +76,7 @@ #define RELEASE_PORT_LOCK(s) release_spinlock(&(s).lock) -status_t -port_init(kernel_args *args) -{ - size_t size = sizeof(struct port_entry) * sMaxPorts; - int32 i; - - // create and initialize ports table - sPortArea = create_area("port_table", (void **)&sPorts, B_ANY_KERNEL_ADDRESS, - size, B_FULL_LOCK, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); - if (sPortArea < 0) { - panic("unable to allocate kernel port table!\n"); - } - - // ToDo: investigate preallocating a list of port_msgs to - // speed up actual message sending/receiving, a slab allocator - // might do it as well, though :-) - - memset(sPorts, 0, size); - for (i = 0; i < sMaxPorts; i++) - sPorts[i].id = -1; - - // add debugger commands - add_debugger_command("ports", &dump_port_list, "Dump a list of all active ports"); - add_debugger_command("port", &dump_port_info, "Dump info about a particular port"); - - sPortsActive = true; - - return 0; -} - - -#ifdef DEBUG -// ToDo: the test code does not belong here! -// the same code is present in the test_app in kernel/apps -// so I guess we can remove this -/* - * testcode - */ - -static int32 port_test_thread_func(void *arg); - -port_id test_p1, test_p2, test_p3, test_p4; - -void -port_test() -{ - char testdata[5]; - thread_id t; - int res; - int32 dummy; - int32 dummy2; - - strcpy(testdata, "abcd"); - - dprintf("porttest: create_port()\n"); - test_p1 = create_port(1, "test port #1"); - test_p2 = create_port(10, "test port #2"); - test_p3 = create_port(1024, "test port #3"); - test_p4 = create_port(1024, "test port #4"); - - dprintf("porttest: find_port()\n"); - dprintf("'test port #1' has id %ld (should be %ld)\n", find_port("test port #1"), test_p1); - - dprintf("porttest: write_port() on 1, 2 and 3\n"); - write_port(test_p1, 1, &testdata, sizeof(testdata)); - write_port(test_p2, 666, &testdata, sizeof(testdata)); - write_port(test_p3, 999, &testdata, sizeof(testdata)); - dprintf("porttest: port_count(test_p1) = %ld\n", port_count(test_p1)); - - dprintf("porttest: write_port() on 1 with timeout of 1 sec (blocks 1 sec)\n"); - write_port_etc(test_p1, 1, &testdata, sizeof(testdata), B_TIMEOUT, 1000000); - dprintf("porttest: write_port() on 2 with timeout of 1 sec (wont block)\n"); - res = write_port_etc(test_p2, 777, &testdata, sizeof(testdata), B_TIMEOUT, 1000000); - dprintf("porttest: res=%d, %s\n", res, res == 0 ? "ok" : "BAD"); - - dprintf("porttest: read_port() on empty port 4 with timeout of 1 sec (blocks 1 sec)\n"); - res = read_port_etc(test_p4, &dummy, &dummy2, sizeof(dummy2), B_TIMEOUT, 1000000); - dprintf("porttest: res=%d, %s\n", res, res == B_TIMED_OUT ? "ok" : "BAD"); - - dprintf("porttest: spawning thread for port 1\n"); - t = spawn_kernel_thread(port_test_thread_func, "port_test", B_NORMAL_PRIORITY, NULL); - resume_thread(t); - - dprintf("porttest: write\n"); - write_port(test_p1, 1, &testdata, sizeof(testdata)); - - // now we can write more (no blocking) - dprintf("porttest: write #2\n"); - write_port(test_p1, 2, &testdata, sizeof(testdata)); - dprintf("porttest: write #3\n"); - write_port(test_p1, 3, &testdata, sizeof(testdata)); - - dprintf("porttest: waiting on spawned thread\n"); - wait_for_thread(t, NULL); - - dprintf("porttest: close p1\n"); - close_port(test_p2); - dprintf("porttest: attempt write p1 after close\n"); - res = write_port(test_p2, 4, &testdata, sizeof(testdata)); - dprintf("porttest: write_port ret %d\n", res); - - dprintf("porttest: testing delete p2\n"); - delete_port(test_p2); - - dprintf("porttest: end test main thread\n"); - -} - - -static int32 -port_test_thread_func(void *arg) -{ - int32 msg_code; - int n; - char buf[6]; - buf[5] = '\0'; - - dprintf("porttest: port_test_thread_func()\n"); - - n = read_port(test_p1, &msg_code, &buf, 3); - dprintf("read_port #1 code %ld len %d buf %s\n", msg_code, n, buf); - n = read_port(test_p1, &msg_code, &buf, 4); - dprintf("read_port #1 code %ld len %d buf %s\n", msg_code, n, buf); - buf[4] = 'X'; - n = read_port(test_p1, &msg_code, &buf, 5); - dprintf("read_port #1 code %ld len %d buf %s\n", msg_code, n, buf); - - dprintf("porttest: testing delete p1 from other thread\n"); - delete_port(test_p1); - dprintf("porttest: end port_test_thread_func()\n"); - - return 0; -} -#endif /* DEBUG */ - - -int +static int dump_port_list(int argc, char **argv) { const char *name = NULL; @@ -241,8 +100,9 @@ || (name != NULL && strstr(port->name, name) == NULL)) continue; - kprintf("%p %6lx %4ld %6lx %6lx %6lx %s\n", port, port->id, port->capacity, - port->read_sem, port->write_sem, port->owner, port->name); + kprintf("%p %6ld %4ld %6ld %6ld %6ld %s\n", port, port->id, + port->capacity, port->read_sem, port->write_sem, port->owner, + port->name); } return 0; } @@ -293,7 +153,7 @@ uint32 num = strtoul(argv[1], NULL, 0); uint32 slot = num % sMaxPorts; if (sPorts[slot].id != (int)num) { - kprintf("port 0x%lx doesn't exist!\n", num); + kprintf("port %ld (%#lx) doesn't exist!\n", num, num); return 0; } _dump_port_info(&sPorts[slot]); @@ -303,8 +163,10 @@ // walk through the ports list, trying to match name for (i = 0; i < sMaxPorts; i++) { - if ((name != NULL && sPorts[i].name != NULL && !strcmp(name, sPorts[i].name)) - || (sem != -1 && (sPorts[i].read_sem == sem || sPorts[i].write_sem == sem))) { + if ((name != NULL && sPorts[i].name != NULL + && !strcmp(name, sPorts[i].name)) + || (sem != -1 && (sPorts[i].read_sem == sem + || sPorts[i].write_sem == sem))) { _dump_port_info(&sPorts[i]); return 0; } @@ -322,10 +184,77 @@ } -/** this function cycles through the ports table, deleting all - * the ports that are owned by the passed team_id - */ +static void +put_port_msg(port_msg *msg) +{ + cbuf_free_chain(msg->buffer_chain); + free(msg); +} + +static port_msg * +get_port_msg(int32 code, size_t bufferSize) +{ + // ToDo: investigate preallocation of port_msgs (or use a slab allocator) + cbuf *bufferChain = NULL; + + port_msg *msg = (port_msg *)malloc(sizeof(port_msg)); + if (msg == NULL) + return NULL; + + if (bufferSize > 0) { + bufferChain = cbuf_get_chain(bufferSize); + if (bufferChain == NULL) { + free(msg); + return NULL; + } + } + + msg->code = code; + msg->buffer_chain = bufferChain; + msg->size = bufferSize; + return msg; +} + + +/*! You need to own the port's lock when calling this function */ +static bool +is_port_closed(int32 slot) +{ + return sPorts[slot].capacity == 0; +} + + +/*! Fills the port_info structure with information from the specified + port. + The port lock must be held when called. +*/ +static void +fill_port_info(struct port_entry *port, port_info *info, size_t size) +{ + int32 count; + + info->port = port->id; + info->team = port->owner; + info->capacity = port->capacity; + + get_sem_count(port->read_sem, &count); + if (count < 0) + count = 0; + + info->queue_count = count; + info->total_count = port->total_count; + + strlcpy(info->name, port->name, B_OS_NAME_LENGTH); +} + + +// #pragma mark - private kernel API + + +/*! This function cycles through the ports table, deleting all + the ports that are owned by the passed team_id +*/ int delete_owned_ports(team_id owner) { @@ -365,59 +294,48 @@ } -static void -put_port_msg(port_msg *msg) +int32 +port_max_ports(void) { - cbuf_free_chain(msg->buffer_chain); - free(msg); + return sMaxPorts; } -static port_msg * -get_port_msg(int32 code, size_t bufferSize) +int32 +port_used_ports(void) { - // ToDo: investigate preallocation of port_msgs (or use a slab allocator) - cbuf *bufferChain = NULL; - - port_msg *msg = (port_msg *)malloc(sizeof(port_msg)); - if (msg == NULL) - return NULL; - - if (bufferSize > 0) { - bufferChain = cbuf_get_chain(bufferSize); - if (bufferChain == NULL) { - free(msg); - return NULL; - } - } - - msg->code = code; - msg->buffer_chain = bufferChain; - msg->size = bufferSize; - return msg; + return sUsedPorts; } -/** You need to own the port's lock when calling this function */ - -static bool -is_port_closed(int32 slot) +status_t +port_init(kernel_args *args) { - return sPorts[slot].capacity == 0; -} + size_t size = sizeof(struct port_entry) * sMaxPorts; + int32 i; + // create and initialize ports table + sPortArea = create_area("port_table", (void **)&sPorts, B_ANY_KERNEL_ADDRESS, + size, B_FULL_LOCK, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); + if (sPortArea < 0) { + panic("unable to allocate kernel port table!\n"); + return sPortArea; + } -int32 -port_max_ports(void) -{ - return sMaxPorts; -} + // ToDo: investigate preallocating a list of port_msgs to + // speed up actual message sending/receiving, a slab allocator + // might do it as well, though :-) + memset(sPorts, 0, size); + for (i = 0; i < sMaxPorts; i++) + sPorts[i].id = -1; -int32 -port_used_ports(void) -{ - return sUsedPorts; + // add debugger commands + add_debugger_command("ports", &dump_port_list, "Dump a list of all active ports"); + add_debugger_command("port", &dump_port_info, "Dump info about a particular port"); + + sPortsActive = true; + return B_OK; } @@ -778,31 +696,6 @@ } -/** Fills the port_info structure with information from the specified - * port. - * The port lock must be held when called. - */ - -static void -fill_port_info(struct port_entry *port, port_info *info, size_t size) -{ - int32 count; - - info->port = port->id; - info->team = port->owner; - info->capacity = port->capacity; - - get_sem_count(port->read_sem, &count); - if (count < 0) - count = 0; - - info->queue_count = count; - info->total_count = port->total_count; - - strlcpy(info->name, port->name, B_OS_NAME_LENGTH); -} - - status_t _get_port_info(port_id id, port_info *info, size_t size) { Modified: haiku/trunk/src/system/kernel/team.cpp =================================================================== --- haiku/trunk/src/system/kernel/team.cpp 2007-10-11 08:01:18 UTC (rev 22506) +++ haiku/trunk/src/system/kernel/team.cpp 2007-10-11 08:30:18 UTC (rev 22507) @@ -6,7 +6,7 @@ * Distributed under the terms of the NewOS License. */ -/* Team functions */ +/*! Team functions */ #include #include @@ -88,27 +88,27 @@ _dump_team_info(struct team *team) { kprintf("TEAM: %p\n", team); - kprintf("id: 0x%lx\n", team->id); + kprintf("id: %ld (%#lx)\n", team->id, team->id); kprintf("name: '%s'\n", team->name); kprintf("args: '%s'\n", team->args); kprintf("next: %p\n", team->next); kprintf("parent: %p", team->parent); if (team->parent != NULL) { - kprintf(" (id = 0x%lx)\n", team->parent->id); + kprintf(" (id = %ld)\n", team->parent->id); } else kprintf("\n"); kprintf("children: %p\n", team->children); kprintf("num_threads: %d\n", team->num_threads); kprintf("state: %d\n", team->state); - kprintf("pending_signals: 0x%x\n", team->pending_signals); + kprintf("pending_signals: %#x\n", team->pending_signals); kprintf("io_context: %p\n", team->io_context); if (team->address_space) - kprintf("address_space: %p (id = 0x%lx)\n", team->address_space, team->address_space->id); + kprintf("address_space: %p\n", team->address_space); kprintf("main_thread: %p\n", team->main_thread); kprintf("thread_list: %p\n", team->thread_list); - kprintf("group_id: 0x%lx\n", team->group_id); - kprintf("session_id: 0x%lx\n", team->session_id); + kprintf("group_id: %ld\n", team->group_id); + kprintf("session_id: %ld\n", team->session_id); } @@ -167,12 +167,11 @@ } -/** Frees an array of strings in kernel space. - * - * \param strings strings array - * \param count number of strings in array - */ +/*! Frees an array of strings in kernel space. + \param strings strings array + \param count number of strings in array +*/ static void free_strings_array(char **strings, int32 count) { @@ -188,15 +187,14 @@ } -/** Copy an array of strings in kernel space - * - * \param strings strings array to be copied - * \param count number of strings in array - * \param kstrings pointer to the kernel copy - * \return \c B_OK on success, or an appropriate error code on - * failure. - */ +/*! Copy an array of strings in kernel space + \param strings strings array to be copied + \param count number of strings in array + \param kstrings pointer to the kernel copy + \return \c B_OK on success, or an appropriate error code on + failure. +*/ static status_t kernel_copy_strings_array(char * const *in, int32 count, char ***_strings) { @@ -227,15 +225,14 @@ } -/** Copy an array of strings from user space to kernel space - * - * \param strings userspace strings array - * \param count number of strings in array - * \param kstrings pointer to the kernel copy - * \return \c B_OK on success, or an appropriate error code on - * failure. - */ +/*! Copy an array of strings from user space to kernel space + \param strings userspace strings array + \param count number of strings in array + \param kstrings pointer to the kernel copy + \return \c B_OK on success, or an appropriate error code on + failure. +*/ static status_t user_copy_strings_array(char * const *userStrings, int32 count, char ***_strings) { @@ -365,9 +362,7 @@ } -/** Note: must have TEAM lock held - */ - +/*! Note: must have team lock held */ static void remove_team_from_parent(struct team *parent, struct team *team) { @@ -388,10 +383,9 @@ } -/** Reparent each of our children - * Note: must have TEAM lock held - */ - +/*! Reparent each of our children + Note: must have team lock held +*/ static void reparent_children(struct team *team) { @@ -421,8 +415,7 @@ } -/** You must hold the team lock when calling this function. */ - +/*! You must hold the team lock when calling this function. */ static void insert_group_into_session(struct process_session *session, struct process_group *group) { @@ -435,8 +428,7 @@ } -/** You must hold the team lock when calling this function. */ - +/*! You must hold the team lock when calling this function. */ static void insert_team_into_group(struct process_group *group, struct team *team) { @@ -449,11 +441,10 @@ } -/** Removes a group from a session, and puts the session object - * back into the session cache, if it's not used anymore. - * You must hold the team lock when calling this function. - */ - +/*! Removes a group from a session, and puts the session object + back into the session cache, if it's not used anymore. + You must hold the team lock when calling this function. +*/ static void remove_group_from_session(struct process_group *group) { @@ -472,18 +463,15 @@ } +/*! Removes the team from the group. If that group becomes therefore + unused, it will set \a _freeGroup to point to the group - otherwise + it will be \c NULL. + It cannot be freed here because this function has to be called + with having the team lock held. - -/** Removes the team from the group. If that group becomes therefore - * unused, it will set \a _freeGroup to point to the group - otherwise - * it will be \c NULL. - * It cannot be freed here because this function has to be called - * with having the team lock held. - * - * \param team the team that'll be removed from it's group - * \param _freeGroup points to the group to be freed or NULL - */ - + \param team the team that'll be removed from it's group + \param _freeGroup points to the group to be freed or NULL +*/ static void remove_team_from_group(struct team *team, struct process_group **_freeGroup) { @@ -865,7 +853,7 @@ return err; } - TRACE(("team_create_thread_start: loaded elf. entry = 0x%lx\n", entry)); + TRACE(("team_create_thread_start: loaded elf. entry = %#lx\n", entry)); team->state = TEAM_STATE_NORMAL; @@ -875,10 +863,9 @@ } -/** The BeOS kernel exports a function with this name, but most probably with - * different parameters; we should not make it public. - */ - +/*! The BeOS kernel exports a function with this name, but most probably with + different parameters; we should not make it public. +*/ static thread_id load_image_etc(int32 argCount, char * const *args, int32 envCount, char * const *env, int32 priority, uint32 flags, @@ -1023,12 +1010,11 @@ } -/** Almost shuts down the current team and loads a new image into it. - * If successful, this function does not return and will takeover ownership of - * the arguments provided. - * This function may only be called from user space. - */ - +/*! Almost shuts down the current team and loads a new image into it. + If successful, this function does not return and will takeover ownership of + the arguments provided. + This function may only be called from user space. +*/ static status_t exec_team(const char *path, int32 argCount, char * const *args, int32 envCount, char * const *env) @@ -1041,7 +1027,7 @@ struct thread *thread; thread_id nubThreadID = -1; - TRACE(("exec_team(path = \"%s\", argc = %ld, envCount = %ld): team %lx\n", + TRACE(("exec_team(path = \"%s\", argc = %ld, envCount = %ld): team %ld\n", args[0], argCount, envCount, team->id)); // switching the kernel at run time is probably not a good idea :) @@ -1128,12 +1114,11 @@ } -/** This is the first function to be called from the newly created - * main child thread. - * It will fill in everything what's left to do from fork_arg, and - * return from the parent's fork() syscall to the child. - */ - +/*! This is the first function to be called from the newly created + main child thread. + It will fill in everything what's left to do from fork_arg, and + return from the parent's fork() syscall to the child. +*/ static int32 fork_team_thread_start(void *_args) { @@ -1175,7 +1160,7 @@ status_t status; int32 cookie; - TRACE(("fork_team(): team %lx\n", parentTeam->id)); + TRACE(("fork_team(): team %ld\n", parentTeam->id)); if (parentTeam == team_get_kernel_team()) return B_NOT_ALLOWED; @@ -1288,10 +1273,10 @@ } -/** Returns if the specified \a team has any children belonging to the specified \a group. - * Must be called with the team lock held. - */ - +/*! Returns if the specified \a team has any children belonging to the + specified \a group. + Must be called with the team lock held. +*/ static bool has_children_in_group(struct team *parent, pid_t groupID) { @@ -1504,11 +1489,10 @@ } -/** Fills the team_info structure with information from the specified - * team. - * The team lock must be held when called. - */ - +/*! Fills the team_info structure with information from the specified + team. + The team lock must be held when called. +*/ static status_t fill_team_info(struct team *team, team_info *info, size_t size) { @@ -1675,9 +1659,7 @@ } -/** Quick check to see if we have a valid team ID. - */ - +/*! Quick check to see if we have a valid team ID. */ bool team_is_valid(team_id id) { @@ -1709,10 +1691,9 @@ } -/** This searches the session of the team for the specified group ID. - * You must hold the team lock when you call this function. - */ - +/*! This searches the session of the team for the specified group ID. + You must hold the team lock when you call this function. +*/ struct process_group * team_get_process_group_locked(struct process_session *session, pid_t id) { @@ -2126,11 +2107,10 @@ } -/** Adds a hook to the team that is called as soon as this - * team goes away. - * This call might get public in the future. - */ - +/*! Adds a hook to the team that is called as soon as this + team goes away. + This call might get public in the future. +*/ status_t start_watching_team(team_id teamID, void (*hook)(team_id, void *), void *data) { From jackburton at mail.berlios.de Thu Oct 11 15:30:57 2007 From: jackburton at mail.berlios.de (jackburton at BerliOS) Date: Thu, 11 Oct 2007 15:30:57 +0200 Subject: [Haiku-commits] r22508 - in haiku/trunk: headers/private/interface src/kits/interface Message-ID: <200710111330.l9BDUvXF030333@sheep.berlios.de> Author: jackburton Date: 2007-10-11 15:30:56 +0200 (Thu, 11 Oct 2007) New Revision: 22508 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22508&view=rev Modified: haiku/trunk/headers/private/interface/ColorConversion.h haiku/trunk/src/kits/interface/ColorConversion.cpp haiku/trunk/src/kits/interface/InterfaceDefs.cpp Log: PaletteConverter now exports a static InitializeDefault() method, which can be used (and is, by _init_interface_kit()) to initialize the ... er... default instance of PaletteConverter using the system color map, thus avoid building the list of colors, which takes some time. Fixes bug #505. Modified: haiku/trunk/headers/private/interface/ColorConversion.h =================================================================== --- haiku/trunk/headers/private/interface/ColorConversion.h 2007-10-11 08:30:18 UTC (rev 22507) +++ haiku/trunk/headers/private/interface/ColorConversion.h 2007-10-11 13:30:56 UTC (rev 22508) @@ -44,6 +44,8 @@ uint8 &blue, uint8 &alpha) const; inline uint8 GrayColorForIndex(uint8 index) const; + static status_t InitializeDefault(bool useServer = false); + private: const color_map *fColorMap; color_map *fOwnColorMap; Modified: haiku/trunk/src/kits/interface/ColorConversion.cpp =================================================================== --- haiku/trunk/src/kits/interface/ColorConversion.cpp 2007-10-11 08:30:18 UTC (rev 22507) +++ haiku/trunk/src/kits/interface/ColorConversion.cpp 2007-10-11 13:30:56 UTC (rev 22508) @@ -13,6 +13,7 @@ #include "ColorConversion.h" +#include #include #include @@ -27,6 +28,8 @@ // TODO: system palette -- hard-coded for now, when the app server is ready // we should use system_colors() or BScreen::ColorMap(). +// Stefano: We cannot do that, since this code is also used by client-side only BBitmaps, +// and also by the app_server const rgb_color kSystemPalette[] = { { 0, 0, 0, 255 }, { 8, 8, 8, 255 }, { 16, 16, 16, 255 }, { 24, 24, 24, 255 }, { 32, 32, 32, 255 }, { 40, 40, 40, 255 }, @@ -526,24 +529,27 @@ } -// TODO: Remove these and palette_converter() when BScreen is available. static BLocker gPaletteConverterLock("PalConvLock"); static PaletteConverter gPaletteConverter; -/*! \brief Returns a PaletteConverter using the system color palette. - \return A PaletteConverter. +/*! \brief Initialize the global instance of PaletteConverter using the system color palette. + \return B_OK. */ -static -const PaletteConverter* -palette_converter() +/* static */ +status_t +PaletteConverter::InitializeDefault(bool useServer) { if (gPaletteConverterLock.Lock()) { - if (gPaletteConverter.InitCheck() != B_OK) - gPaletteConverter.SetTo(kSystemPalette); + if (gPaletteConverter.InitCheck() != B_OK) { + if (useServer) + gPaletteConverter.SetTo(system_colors()); + else + gPaletteConverter.SetTo(kSystemPalette); + } gPaletteConverterLock.Unlock(); } - return &gPaletteConverter; + return B_OK; } @@ -909,7 +915,7 @@ break; case B_CMAP8: - BPrivate::palette_converter(); + PaletteConverter::InitializeDefault(); ConvertBits(srcBits, (uint8 *)dstBits, srcBitsLength, dstBitsLength, redShift - 15, greenShift - 10, blueShift - 5, 0, 0, 0x7c00, 0x03e0, 0x001f, 0x0000, srcBytesPerRow, @@ -1063,7 +1069,7 @@ break; case B_CMAP8: - palette_converter(); + PaletteConverter::InitializeDefault(); return ConvertBits((const uint8 *)srcBits, dstBits, srcBitsLength, dstBitsLength, 24, 16, 8, 32, 8, srcBytesPerRow, dstBytesPerRow, 8, srcColorSpace, dstColorSpace, srcOffset, Modified: haiku/trunk/src/kits/interface/InterfaceDefs.cpp =================================================================== --- haiku/trunk/src/kits/interface/InterfaceDefs.cpp 2007-10-11 08:30:18 UTC (rev 22507) +++ haiku/trunk/src/kits/interface/InterfaceDefs.cpp 2007-10-11 13:30:56 UTC (rev 22508) @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -794,6 +795,10 @@ extern "C" status_t _init_interface_kit_() { + status_t status = BPrivate::PaletteConverter::InitializeDefault(true); + if (status < B_OK) + return status; + sem_id widthSem = create_sem(0, "BTextView WidthBuffer Sem"); if (widthSem < 0) return widthSem; @@ -804,7 +809,8 @@ _init_global_fonts_(); _menu_info_ptr_ = &BMenu::sMenuInfo; - status_t status = get_menu_info(&BMenu::sMenuInfo); + + status = get_menu_info(&BMenu::sMenuInfo); general_info.background_color = ui_color(B_PANEL_BACKGROUND_COLOR); general_info.mark_color.set_to(0, 0, 0); From jackburton at mail.berlios.de Thu Oct 11 15:43:08 2007 From: jackburton at mail.berlios.de (jackburton at BerliOS) Date: Thu, 11 Oct 2007 15:43:08 +0200 Subject: [Haiku-commits] r22509 - haiku/trunk/src/kits/interface Message-ID: <200710111343.l9BDh845031120@sheep.berlios.de> Author: jackburton Date: 2007-10-11 15:43:07 +0200 (Thu, 11 Oct 2007) New Revision: 22509 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22509&view=rev Modified: haiku/trunk/src/kits/interface/ColorConversion.cpp Log: Static variables should have the s prefix. Modified: haiku/trunk/src/kits/interface/ColorConversion.cpp =================================================================== --- haiku/trunk/src/kits/interface/ColorConversion.cpp 2007-10-11 13:30:56 UTC (rev 22508) +++ haiku/trunk/src/kits/interface/ColorConversion.cpp 2007-10-11 13:43:07 UTC (rev 22509) @@ -529,8 +529,8 @@ } -static BLocker gPaletteConverterLock("PalConvLock"); -static PaletteConverter gPaletteConverter; +static BLocker sPaletteConverterLock("PalConvLock"); +static PaletteConverter sPaletteConverter; /*! \brief Initialize the global instance of PaletteConverter using the system color palette. @@ -540,14 +540,14 @@ status_t PaletteConverter::InitializeDefault(bool useServer) { - if (gPaletteConverterLock.Lock()) { - if (gPaletteConverter.InitCheck() != B_OK) { + if (sPaletteConverterLock.Lock()) { + if (sPaletteConverter.InitCheck() != B_OK) { if (useServer) - gPaletteConverter.SetTo(system_colors()); + sPaletteConverter.SetTo(system_colors()); else - gPaletteConverter.SetTo(kSystemPalette); + sPaletteConverter.SetTo(kSystemPalette); } - gPaletteConverterLock.Unlock(); + sPaletteConverterLock.Unlock(); } return B_OK; } @@ -620,7 +620,7 @@ void WriteCMAP8(uint8 **dest, uint8 *data, int32 index) { - **dest = gPaletteConverter.IndexForRGB15(*(uint16 *)data); + **dest = sPaletteConverter.IndexForRGB15(*(uint16 *)data); (*dest)++; } @@ -628,7 +628,7 @@ uint32 ReadCMAP8(const uint8 **source, int32 index) { - uint32 result = gPaletteConverter.RGBA32ColorForIndex(**source); + uint32 result = sPaletteConverter.RGBA32ColorForIndex(**source); (*source)++; return result; } From axeld at mail.berlios.de Thu Oct 11 19:55:28 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 11 Oct 2007 19:55:28 +0200 Subject: [Haiku-commits] r22510 - haiku/trunk/src/tests/add-ons/kernel Message-ID: <200710111755.l9BHtSqL031267@sheep.berlios.de> Author: axeld Date: 2007-10-11 19:55:27 +0200 (Thu, 11 Oct 2007) New Revision: 22510 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22510&view=rev Modified: haiku/trunk/src/tests/add-ons/kernel/kernelland_emu.cpp Log: Updated to latest kernel versions. Modified: haiku/trunk/src/tests/add-ons/kernel/kernelland_emu.cpp =================================================================== --- haiku/trunk/src/tests/add-ons/kernel/kernelland_emu.cpp 2007-10-11 13:43:07 UTC (rev 22509) +++ haiku/trunk/src/tests/add-ons/kernel/kernelland_emu.cpp 2007-10-11 17:55:27 UTC (rev 22510) @@ -820,7 +820,7 @@ // #pragma mark - Private locking functions -int +int32 recursive_lock_get_recursion(recursive_lock *lock) { thread_id thid = find_thread(NULL); @@ -863,38 +863,33 @@ } -bool +status_t recursive_lock_lock(recursive_lock *lock) { - thread_id thid = find_thread(NULL); - bool retval = false; + thread_id thread = find_thread(NULL); - if (thid != lock->holder) { - acquire_sem(lock->sem); - - lock->holder = thid; - retval = true; + if (thread != lock->holder) { + status_t status = acquire_sem(lock->sem); + if (status < B_OK) + return status; + + lock->holder = thread; } lock->recursion++; - return retval; + return B_OK; } -bool +void recursive_lock_unlock(recursive_lock *lock) { - thread_id thid = find_thread(NULL); - bool retval = false; - - if (thid != lock->holder) + if (find_thread(NULL) != lock->holder) panic("recursive_lock %p unlocked by non-holder thread!\n", lock); if (--lock->recursion == 0) { lock->holder = -1; - release_sem(lock->sem); - retval = true; + release_sem_etc(lock->sem, 1, 0/*B_DO_NOT_RESCHEDULE*/); } - return retval; } @@ -934,19 +929,22 @@ } -void +status_t mutex_lock(mutex *mutex) { thread_id me = find_thread(NULL); // ToDo: if acquire_sem() fails, we shouldn't panic - but we should definitely // change the mutex API to actually return the status code - if (acquire_sem(mutex->sem) == B_OK) { - if (me == mutex->holder) - panic("mutex_lock failure: mutex %p (sem = 0x%lx) acquired twice by thread 0x%lx\n", mutex, mutex->sem, me); - } + status_t status = acquire_sem(mutex->sem); + if (status < B_OK) + return status; + if (me == mutex->holder) + panic("mutex_lock failure: mutex %p (sem = 0x%lx) acquired twice by thread 0x%lx\n", mutex, mutex->sem, me); + mutex->holder = me; + return B_OK; } From jackburton at mail.berlios.de Fri Oct 12 09:58:34 2007 From: jackburton at mail.berlios.de (jackburton at BerliOS) Date: Fri, 12 Oct 2007 09:58:34 +0200 Subject: [Haiku-commits] r22511 - haiku/trunk/src/apps/stylededit Message-ID: <200710120758.l9C7wYwD009873@sheep.berlios.de> Author: jackburton Date: 2007-10-12 09:58:33 +0200 (Fri, 12 Oct 2007) New Revision: 22511 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22511&view=rev Modified: haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp Log: StyledEdit didn't print anything if there's only one line (bug #1288). Note, though, that printing in StyledEdit is still very much broken. Often it prints only the current page, for example. Modified: haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp =================================================================== --- haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp 2007-10-11 17:55:27 UTC (rev 22510) +++ haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp 2007-10-12 07:58:33 UTC (rev 22511) @@ -1115,26 +1115,30 @@ lastLine = currentLine - 1; } + printJob.BeginJob(); - int32 printLine = firstLine; - while (printLine < lastLine) { - float currentHeight = 0; - int32 firstLineOnPage = printLine; - while (currentHeight < printableRect.Height() && printLine < lastLine) { - currentHeight += fTextView->LineHeight(printLine); - if (currentHeight < printableRect.Height()) - printLine++; - } + if (fTextView->CountLines() > 0 && fTextView->TextLength() > 0) { + int32 printLine = firstLine; + while (printLine <= lastLine) { + float currentHeight = 0; + int32 firstLineOnPage = printLine; + while (currentHeight < printableRect.Height() && printLine <= lastLine) { + currentHeight += fTextView->LineHeight(printLine); + if (currentHeight < printableRect.Height()) + printLine++; + } - float top = 0; - if (firstLineOnPage != 0) - top = fTextView->TextHeight(0, firstLineOnPage - 1); + float top = 0; + if (firstLineOnPage != 0) + top = fTextView->TextHeight(0, firstLineOnPage - 1); - float bottom = fTextView->TextHeight(0, printLine - 1); - BRect textRect(0.0, top + TEXT_INSET, printableRect.Width(), bottom + TEXT_INSET); - printJob.DrawView(fTextView, textRect, BPoint(0.0,0.0)); - printJob.SpoolPage(); + float bottom = fTextView->TextHeight(0, printLine - 1); + BRect textRect(0.0, top + TEXT_INSET, printableRect.Width(), bottom + TEXT_INSET); + printJob.DrawView(fTextView, textRect, B_ORIGIN); + printJob.SpoolPage(); + } } + printJob.CommitJob(); } From jackburton at mail.berlios.de Fri Oct 12 11:44:32 2007 From: jackburton at mail.berlios.de (jackburton at BerliOS) Date: Fri, 12 Oct 2007 11:44:32 +0200 Subject: [Haiku-commits] r22512 - haiku/trunk/src/apps/terminal Message-ID: <200710120944.l9C9iWbM018961@sheep.berlios.de> Author: jackburton Date: 2007-10-12 11:44:32 +0200 (Fri, 12 Oct 2007) New Revision: 22512 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22512&view=rev Modified: haiku/trunk/src/apps/terminal/TermView.cpp Log: Check keys against "raw_char" instead of "key" Modified: haiku/trunk/src/apps/terminal/TermView.cpp =================================================================== --- haiku/trunk/src/apps/terminal/TermView.cpp 2007-10-12 07:58:33 UTC (rev 22511) +++ haiku/trunk/src/apps/terminal/TermView.cpp 2007-10-12 09:44:32 UTC (rev 22512) @@ -1486,32 +1486,27 @@ fShell->Signal(SIGINT); } - //printf("rawKey: %c\n", (char)rawChar); - // Terminal filters RET, ENTER, F1...F12, and ARROW key code. // TODO: Cleanup if (numBytes == 1) { switch (*bytes) { case B_RETURN: - if (key == RETURN_KEY || key == ENTER_KEY) { + if (rawChar == B_RETURN) { char c = 0x0d; fShell->Write(&c, 1); return; - } else { - fShell->Write(bytes, numBytes); - return; } break; case B_LEFT_ARROW: - if (key == LEFT_ARROW_KEY) { + if (rawChar == B_LEFT_ARROW) { fShell->Write(LEFT_ARROW_KEY_CODE, sizeof(LEFT_ARROW_KEY_CODE) - 1); return; } break; case B_RIGHT_ARROW: - if (key == RIGHT_ARROW_KEY) { + if (rawChar == B_RIGHT_ARROW) { fShell->Write(RIGHT_ARROW_KEY_CODE, sizeof(RIGHT_ARROW_KEY_CODE) - 1); return; } @@ -1525,7 +1520,7 @@ } return; } - if (key == UP_ARROW_KEY) { + if (rawChar == B_UP_ARROW) { fShell->Write(UP_ARROW_KEY_CODE, sizeof(UP_ARROW_KEY_CODE) - 1); return; } @@ -1538,28 +1533,28 @@ return; } - if (key == DOWN_ARROW_KEY) { + if (rawChar == B_DOWN_ARROW) { fShell->Write(DOWN_ARROW_KEY_CODE, sizeof(DOWN_ARROW_KEY_CODE) - 1); return; } break; case B_INSERT: - if (key == INSERT_KEY) { + if (rawChar == B_INSERT) { fShell->Write(INSERT_KEY_CODE, sizeof(INSERT_KEY_CODE) - 1); return; } break; case B_HOME: - if (key == HOME_KEY) { + if (rawChar == B_HOME) { fShell->Write(HOME_KEY_CODE, sizeof(HOME_KEY_CODE) - 1); return; } break; case B_END: - if (key == END_KEY) { + if (rawChar == B_END) { fShell->Write(END_KEY_CODE, sizeof(END_KEY_CODE) - 1); return; } @@ -1573,7 +1568,7 @@ } return; } - if (key == PAGE_UP_KEY) { + if (rawChar == B_PAGE_UP) { fShell->Write(PAGE_UP_KEY_CODE, sizeof(PAGE_UP_KEY_CODE) - 1); return; } @@ -1586,7 +1581,7 @@ return; } - if (key == PAGE_DOWN_KEY) { + if (rawChar == B_PAGE_DOWN) { fShell->Write(PAGE_DOWN_KEY_CODE, sizeof(PAGE_DOWN_KEY_CODE) - 1); return; } From axeld at mail.berlios.de Fri Oct 12 12:23:46 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Fri, 12 Oct 2007 12:23:46 +0200 Subject: [Haiku-commits] r22513 - in haiku/trunk/src/tests/system/kernel: . scheduler Message-ID: <200710121023.l9CANkC1023784@sheep.berlios.de> Author: axeld Date: 2007-10-12 12:23:45 +0200 (Fri, 12 Oct 2007) New Revision: 22513 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22513&view=rev Added: haiku/trunk/src/tests/system/kernel/scheduler/ haiku/trunk/src/tests/system/kernel/scheduler/Jamfile haiku/trunk/src/tests/system/kernel/scheduler/main.cpp haiku/trunk/src/tests/system/kernel/scheduler/override_types.h Modified: haiku/trunk/src/tests/system/kernel/Jamfile Log: Started working on a test application for the scheduler; it uses the scheduler of the kernel directly, and emulates the kernel's API where necessary. Not complete at all yet, but I already found one serious bug in our current scheduler with it :-) Modified: haiku/trunk/src/tests/system/kernel/Jamfile =================================================================== --- haiku/trunk/src/tests/system/kernel/Jamfile 2007-10-12 09:44:32 UTC (rev 22512) +++ haiku/trunk/src/tests/system/kernel/Jamfile 2007-10-12 10:23:45 UTC (rev 22513) @@ -57,5 +57,6 @@ SubInclude HAIKU_TOP src tests system kernel cache ; #SubInclude HAIKU_TOP src tests system kernel disk_device_manager ; SubInclude HAIKU_TOP src tests system kernel device_manager ; +SubInclude HAIKU_TOP src tests system kernel scheduler ; SubInclude HAIKU_TOP src tests system kernel slab ; SubInclude HAIKU_TOP src tests system kernel util ; Added: haiku/trunk/src/tests/system/kernel/scheduler/Jamfile =================================================================== --- haiku/trunk/src/tests/system/kernel/scheduler/Jamfile 2007-10-12 09:44:32 UTC (rev 22512) +++ haiku/trunk/src/tests/system/kernel/scheduler/Jamfile 2007-10-12 10:23:45 UTC (rev 22513) @@ -0,0 +1,24 @@ +SubDir HAIKU_TOP src tests system kernel scheduler ; + +#SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src system kernel util ] ; + +UsePrivateHeaders kernel ; +UsePrivateHeaders [ FDirName kernel arch $(TARGET_ARCH) ] ; +UsePrivateHeaders [ FDirName kernel boot platform $(TARGET_BOOT_PLATFORM) ] ; +#UseHeaders [ FDirName $(HAIKU_TOP) src system kernel cache ] ; + +local includes = -include $(SUBDIR)/override_types.h ; +local defines = ; #-DTRACE_SCHEDULER ; + +SubDirCcFlags $(defines) $(includes) -fno-exceptions -fno-rtti ; +SubDirC++Flags $(defines) $(includes) -fno-exceptions -fno-rtti ; + +SimpleTest SchedulerTest : + main.cpp + scheduler.cpp + : libkernelland_emu.so be +; + +SEARCH on [ FGristFiles + scheduler.cpp + ] = [ FDirName $(HAIKU_TOP) src system kernel ] ; Added: haiku/trunk/src/tests/system/kernel/scheduler/main.cpp =================================================================== --- haiku/trunk/src/tests/system/kernel/scheduler/main.cpp 2007-10-12 09:44:32 UTC (rev 22512) +++ haiku/trunk/src/tests/system/kernel/scheduler/main.cpp 2007-10-12 10:23:45 UTC (rev 22513) @@ -0,0 +1,390 @@ +#include "override_types.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + + +const static option kOptions[] = { + {"time", required_argument, NULL, 't'}, + {"cpu", required_argument, NULL, 'c'}, +}; + +const bigtime_t kQuantum = 3000; +const uint32 kMaxCPUCount = 64; + +class Thread { +public: + Thread(const char* name, int32 priority); + virtual ~Thread(); + + struct thread* GetThread() { return &fThread; } + virtual void Rescheduled() { fOnCPU[fThread.cpu->cpu_num]++; } + + virtual bigtime_t NextQuantum() { return kQuantum; } + virtual bigtime_t NextState() { return B_THREAD_READY; } + virtual bigtime_t NextReady() { return 0; } + +protected: + struct thread fThread; + int32 fOnCPU[kMaxCPUCount]; +}; + +class IdleThread : public Thread { +public: + IdleThread(); + virtual ~IdleThread(); +}; + +class CPU { +public: + CPU(int32 num); + ~CPU(); + + cpu_ent* GetCPU() { return &fCPU; } + int32 Index() { return fCPU.cpu_num; } + + struct thread* CurrentThread() + { return fCurrentThread->GetThread(); } + void SetCurrentThread(struct thread* thread) + { fCurrentThread = thread->object; } + + void Quit(); + +private: + void _Run(); + static status_t _Run(void* self); + + struct cpu_ent fCPU; + thread_id fThread; + Thread* fCurrentThread; + IdleThread fIdleThread; + int32 fRescheduleCount; + bool fQuit; +}; + +class Timer { +public: + Timer(); + ~Timer(); + + void AddTimer(bigtime_t time); +}; + +thread_queue dead_q; + +static BLocker sThreadLock; +static BList sThreads; +static int32 sNextThreadID = 1; +static int32 sCPUIndexSlot; +static CPU* sCPU[kMaxCPUCount]; +static size_t sCPUCount; + + +// #pragma mark - + + +Thread::Thread(const char* name, int32 priority) +{ + memset(&fThread, 0, sizeof(struct thread)); + fThread.name = strdup(name); + fThread.id = sNextThreadID++; + fThread.priority = fThread.next_priority = priority; + fThread.state = fThread.next_state = B_THREAD_READY; + fThread.object = this; + fThread.last_time = system_time(); + + memset(&fOnCPU, 0, sizeof(fOnCPU)); +} + + +Thread::~Thread() +{ + printf(" %p %10Ld %s, prio %ld, cpu:", &fThread, fThread.kernel_time, + fThread.name, fThread.priority); + for (uint32 i = 0; i < kMaxCPUCount; i++) { + if (fOnCPU[i]) + printf(" [%ld] %ld", i, fOnCPU[i]); + } + putchar('\n'); + free(fThread.name); +} + + +// #pragma mark - + + +IdleThread::IdleThread() + : Thread("idle thread", B_IDLE_PRIORITY) +{ +} + + +IdleThread::~IdleThread() +{ +} + + +// #pragma mark - + + +CPU::CPU(int32 num) + : + fRescheduleCount(0), + fQuit(false) +{ + memset(&fCPU, 0, sizeof(struct cpu_ent)); + fCPU.cpu_num = num; + + fCurrentThread = &fIdleThread; + fIdleThread.GetThread()->cpu = &fCPU; + + fThread = spawn_thread(&_Run, (BString("cpu ") << num).String(), + B_NORMAL_PRIORITY, this); + resume_thread(fThread); +} + + +CPU::~CPU() +{ +} + + +void +CPU::Quit() +{ + fQuit = true; + + status_t status; + wait_for_thread(fThread, &status); +} + + +void +CPU::_Run() +{ + tls_set(sCPUIndexSlot, this); + printf("CPU %d has started.\n", fCPU.cpu_num); + + while (!fQuit) { + fRescheduleCount++; + + grab_thread_lock(); + scheduler_reschedule(); + release_thread_lock(); + + fCurrentThread->Rescheduled(); + snooze(fCurrentThread->NextQuantum()); + fCurrentThread->GetThread()->next_state = fCurrentThread->NextState(); + } + + thread_info info; + get_thread_info(find_thread(NULL), &info); + + printf("CPU %d has halted, user %Ld, %ld rescheduled.\n", + fCPU.cpu_num, info.user_time, fRescheduleCount); + delete this; +} + + +status_t +CPU::_Run(void* self) +{ + CPU* cpu = (CPU*)self; + cpu->_Run(); + return B_OK; +} + + +// #pragma mark - Emulation + + +extern "C" void +kprintf(const char *format,...) +{ + va_list args; + va_start(args, format); + printf("\33[35m"); + vprintf(format, args); + printf("\33[0m"); + fflush(stdout); + va_end(args); +} + + +void +thread_enqueue(struct thread *t, struct thread_queue *q) +{ +} + + +struct thread * +thread_get_current_thread(void) +{ + CPU* cpu = (CPU*)tls_get(sCPUIndexSlot); + return cpu->CurrentThread(); +} + + +void +grab_thread_lock(void) +{ + sThreadLock.Lock(); +} + + +void +release_thread_lock(void) +{ + sThreadLock.Unlock(); +} + + +void +arch_thread_context_switch(struct thread *t_from, struct thread *t_to) +{ +} + + +void +arch_thread_set_current_thread(struct thread *thread) +{ + CPU* cpu = (CPU*)tls_get(sCPUIndexSlot); + //printf("[%ld] %p %s\n", cpu->Index(), thread, thread->name); + return cpu->SetCurrentThread(thread); +} + + +int +add_debugger_command(char *name, int (*func)(int, char **), char *desc) +{ + return B_OK; +} + + +cpu_status +disable_interrupts() +{ + return 0; +} + + +void +restore_interrupts(cpu_status status) +{ +} + + +extern "C" status_t +_local_timer_cancel_event(int cpu, timer *event) +{ + return B_OK; +} + + +status_t +add_timer(timer *event, timer_hook hook, bigtime_t period, int32 flags) +{ + return B_OK; +} + + +int32 +smp_get_current_cpu(void) +{ + return thread_get_current_thread()->cpu->cpu_num; +} + + +// #pragma mark - + + +static void +start_cpus(uint32 count) +{ + sCPUIndexSlot = tls_allocate(); + sCPUCount = count; + + for (size_t i = 0; i < count; i++) { + sCPU[i] = new CPU(i); + } +} + + +static void +stop_cpus() +{ + for (size_t i = 0; i < sCPUCount; i++) { + sCPU[i]->Quit(); + } +} + + +static void +add_thread(Thread* thread) +{ + grab_thread_lock(); + sThreads.AddItem(thread); + scheduler_enqueue_in_run_queue(thread->GetThread()); + release_thread_lock(); +} + + +static void +delete_threads() +{ + for (int32 i = 0; i < sThreads.CountItems(); i++) { + delete (Thread*)sThreads.ItemAt(i); + } +} + + +int +main(int argc, char** argv) +{ + bigtime_t runTime = 1000000; + uint32 cpuCount = 1; + + char option; + while ((option = getopt_long(argc, argv, "", kOptions, NULL)) != -1) { + switch (option) { + case 't': + runTime *= strtol(optarg, 0, NULL); + if (runTime <= 0) { + fprintf(stderr, "Invalid run time.\n"); + exit(1); + } + break; + case 'c': + cpuCount = strtol(optarg, 0, NULL); + if (cpuCount <= 0 || cpuCount > 64) { + fprintf(stderr, "Invalid CPU count (allowed: 1-64).\n"); + exit(1); + } + break; + } + } + + start_cpus(cpuCount); + + add_thread(new Thread("test 1", 5)); + add_thread(new Thread("test 2", 10)); + add_thread(new Thread("test 3", 15)); + + snooze(runTime); + + stop_cpus(); + delete_threads(); + return 0; +} Added: haiku/trunk/src/tests/system/kernel/scheduler/override_types.h =================================================================== --- haiku/trunk/src/tests/system/kernel/scheduler/override_types.h 2007-10-12 09:44:32 UTC (rev 22512) +++ haiku/trunk/src/tests/system/kernel/scheduler/override_types.h 2007-10-12 10:23:45 UTC (rev 22513) @@ -0,0 +1,69 @@ +/* + * Copyright 2004-2007, Haiku Inc. + * Distributed under the terms of the MIT License. + * + * Thread definition and structures + */ +#ifndef _KERNEL_THREAD_TYPES_H +#define _KERNEL_THREAD_TYPES_H + +#define _THREAD_H + +#include + +#if 0 +struct cpu_ent { + bool preempted; +}; +#endif +extern struct thread_queue dead_q; + +struct thread { + struct thread *queue_next; /* i.e. run queue, release queue, etc. */ + char *name; + thread_id id; + int32 priority; + int32 next_priority; + int32 state; + int32 next_state; + struct cpu_ent *cpu; + struct Thread *object; + + bool in_kernel; + bool is_idle; + bool was_yielded; + + bigtime_t user_time; + bigtime_t kernel_time; + bigtime_t last_time; +}; + +enum additional_thread_state { + THREAD_STATE_FREE_ON_RESCHED = 7, // free the thread structure upon reschedule +// THREAD_STATE_BIRTH // thread is being created +}; + +struct thread_queue { + struct thread *head; + struct thread *tail; +}; + + +static inline bool +thread_is_idle_thread(struct thread *thread) +{ + return thread->is_idle; +} + +void thread_enqueue(struct thread *t, struct thread_queue *q); +struct thread *thread_get_current_thread(void); + +#define GRAB_THREAD_LOCK grab_thread_lock +#define RELEASE_THREAD_LOCK release_thread_lock +void grab_thread_lock(void); +void release_thread_lock(void); + +void arch_thread_context_switch(struct thread *t_from, struct thread *t_to); +void arch_thread_set_current_thread(struct thread *t); + +#endif /* _KERNEL_THREAD_TYPES_H */ From axeld at mail.berlios.de Fri Oct 12 12:25:58 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Fri, 12 Oct 2007 12:25:58 +0200 Subject: [Haiku-commits] r22514 - haiku/trunk/src/system/kernel Message-ID: <200710121025.l9CAPwxh024140@sheep.berlios.de> Author: axeld Date: 2007-10-12 12:25:58 +0200 (Fri, 12 Oct 2007) New Revision: 22514 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22514&view=rev Modified: haiku/trunk/src/system/kernel/thread.cpp Log: Removed the "next_*" in queue debugger commands. Modified: haiku/trunk/src/system/kernel/thread.cpp =================================================================== --- haiku/trunk/src/system/kernel/thread.cpp 2007-10-12 10:23:45 UTC (rev 22513) +++ haiku/trunk/src/system/kernel/thread.cpp 2007-10-12 10:25:58 UTC (rev 22514) @@ -93,8 +93,6 @@ static sem_id sDeathStackSem; static spinlock sDeathStackLock = 0; -static struct thread *last_thread_dumped = NULL; - // The dead queue is used as a pool from which to retrieve and reuse previously // allocated thread structs when creating a new thread. It should be gone once // the slab allocator is in. @@ -919,8 +917,6 @@ kprintf("user_time: %Ld\n", thread->user_time); kprintf("architecture dependant section:\n"); arch_thread_dump_info(&thread->arch_info); - - last_thread_dumped = thread; } @@ -1038,66 +1034,6 @@ } -static int -dump_next_thread_in_q(int argc, char **argv) -{ - struct thread *thread = last_thread_dumped; - - if (thread == NULL) { - kprintf("no thread previously dumped. Examine a thread first.\n"); - return 0; - } - - kprintf("next thread in queue after thread @ %p\n", thread); - if (thread->queue_next != NULL) - _dump_thread_info(thread->queue_next); - else - kprintf("NULL\n"); - - return 0; -} - - -static int -dump_next_thread_in_all_list(int argc, char **argv) -{ - struct thread *thread = last_thread_dumped; - - if (thread == NULL) { - kprintf("no thread previously dumped. Examine a thread first.\n"); - return 0; - } - - kprintf("next thread in global list after thread @ %p\n", thread); - if (thread->all_next != NULL) - _dump_thread_info(thread->all_next); - else - kprintf("NULL\n"); - - return 0; -} - - -static int -dump_next_thread_in_team(int argc, char **argv) -{ - struct thread *thread = last_thread_dumped; - - if (thread == NULL) { - kprintf("no thread previously dumped. Examine a thread first.\n"); - return 0; - } - - kprintf("next thread in team after thread @ %p\n", thread); - if (thread->team_next != NULL) - _dump_thread_info(thread->team_next); - else - kprintf("NULL\n"); - - return 0; -} - - // #pragma mark - private kernel API @@ -1801,9 +1737,6 @@ add_debugger_command("waiting", &dump_thread_list, "list all waiting threads (optionally for a specific semaphore)"); add_debugger_command("realtime", &dump_thread_list, "list all realtime threads"); add_debugger_command("thread", &dump_thread_info, "list info about a particular thread"); - add_debugger_command("next_q", &dump_next_thread_in_q, "dump the next thread in the queue of last thread viewed"); - add_debugger_command("next_all", &dump_next_thread_in_all_list, "dump the next thread in the global list of the last thread viewed"); - add_debugger_command("next_team", &dump_next_thread_in_team, "dump the next thread in the team of the last thread viewed"); add_debugger_command("unreal", &make_thread_unreal, "set realtime priority threads to normal priority"); add_debugger_command("suspend", &make_thread_suspended, "suspend a thread"); add_debugger_command("resume", &make_thread_resumed, "resume a thread"); From axeld at mail.berlios.de Fri Oct 12 12:29:08 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Fri, 12 Oct 2007 12:29:08 +0200 Subject: [Haiku-commits] r22515 - haiku/trunk/src/system/kernel Message-ID: <200710121029.l9CAT8Ju024274@sheep.berlios.de> Author: axeld Date: 2007-10-12 12:29:08 +0200 (Fri, 12 Oct 2007) New Revision: 22515 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22515&view=rev Modified: haiku/trunk/src/system/kernel/scheduler.cpp Log: * The loop that should select a thread of the next priority class actually did not work; it would always choose the last thread of the current priority. IOW a thread was never skipped, and lower priority threads were never called when a higher priority thread was running - from the POV of the scheduler, we only has real time threads... * Improved "run_queue" KDL output. * Minor cleanup. Modified: haiku/trunk/src/system/kernel/scheduler.cpp =================================================================== --- haiku/trunk/src/system/kernel/scheduler.cpp 2007-10-12 10:25:58 UTC (rev 22514) +++ haiku/trunk/src/system/kernel/scheduler.cpp 2007-10-12 10:29:08 UTC (rev 22515) @@ -7,7 +7,7 @@ * Distributed under the terms of the NewOS License. */ -/* The thread scheduler */ +/*! The thread scheduler */ #include @@ -30,10 +30,6 @@ #endif -// prototypes -static int dump_run_queue(int argc, char **argv); -static int _rand(void); - // The run queue. Holds the threads ready to run ordered by priority. static struct thread *sRunQueue = NULL; @@ -58,10 +54,12 @@ thread = sRunQueue; if (!thread) - dprintf("Run queue is empty!\n"); + kprintf("Run queue is empty!\n"); else { + kprintf("thread id priority name\n"); while (thread) { - dprintf("Thread id: %ld - priority: %ld\n", thread->id, thread->priority); + kprintf("%p %-7ld %-8ld %s\n", thread, thread->id, + thread->priority, thread->name); thread = thread->queue_next; } } @@ -70,10 +68,9 @@ } -/** Enqueues the thread into the run queue. - * Note: thread lock must be held when entering this function - */ - +/*! Enqueues the thread into the run queue. + Note: thread lock must be held when entering this function +*/ void scheduler_enqueue_in_run_queue(struct thread *thread) { @@ -98,17 +95,17 @@ } -/** Removes a thread from the run queue. - * Note: thread lock must be held when entering this function - */ - +/*! Removes a thread from the run queue. + Note: thread lock must be held when entering this function +*/ void scheduler_remove_from_run_queue(struct thread *thread) { struct thread *item, *prev; // find thread in run queue - for (item = sRunQueue, prev = NULL; item && item != thread; item = item->queue_next) { + for (item = sRunQueue, prev = NULL; item && item != thread; + item = item->queue_next) { if (prev) prev = prev->queue_next; else @@ -145,10 +142,9 @@ } -/** Runs the scheduler. - * Note: expects thread spinlock to be held - */ - +/*! Runs the scheduler. + Note: expects thread spinlock to be held +*/ void scheduler_reschedule(void) { @@ -206,17 +202,18 @@ if (nextThread->queue_next && nextThread->queue_next->priority == B_IDLE_PRIORITY) break; - // skip normal threads sometimes (roughly 16%) - if (_rand() > 0x2000) + // skip normal threads sometimes (roughly 20%) + if (_rand() > 0x1a00) break; // skip until next lower priority int32 priority = nextThread->priority; - while (nextThread->queue_next && priority == nextThread->queue_next->priority - && nextThread->queue_next->priority > B_IDLE_PRIORITY) { + do { prevThread = nextThread; nextThread = nextThread->queue_next; - } + } while (nextThread->queue_next != NULL + && priority == nextThread->queue_next->priority + && nextThread->queue_next->priority > B_IDLE_PRIORITY); } } @@ -273,10 +270,9 @@ } -/** This starts the scheduler. Must be run under the context of - * the initial idle thread. - */ - +/*! This starts the scheduler. Must be run under the context of + the initial idle thread. +*/ void scheduler_start(void) { From axeld at mail.berlios.de Fri Oct 12 17:56:09 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Fri, 12 Oct 2007 17:56:09 +0200 Subject: [Haiku-commits] r22516 - in haiku/trunk: headers/private/graphics/common src/add-ons/accelerants/common src/add-ons/accelerants/radeon src/system/boot/platform/bios_ia32 Message-ID: <200710121556.l9CFu9lB030273@sheep.berlios.de> Author: axeld Date: 2007-10-12 17:56:08 +0200 (Fri, 12 Oct 2007) New Revision: 22516 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22516&view=rev Modified: haiku/trunk/headers/private/graphics/common/edid.h haiku/trunk/headers/private/graphics/common/edid_raw.h haiku/trunk/src/add-ons/accelerants/common/decode_edid.c haiku/trunk/src/add-ons/accelerants/common/dump_edid.c haiku/trunk/src/add-ons/accelerants/radeon/monitor_detection.c haiku/trunk/src/system/boot/platform/bios_ia32/video.cpp Log: Cleanup. Modified: haiku/trunk/headers/private/graphics/common/edid.h =================================================================== --- haiku/trunk/headers/private/graphics/common/edid.h 2007-10-12 10:29:08 UTC (rev 22515) +++ haiku/trunk/headers/private/graphics/common/edid.h 2007-10-12 15:56:08 UTC (rev 22516) @@ -5,7 +5,7 @@ #ifndef _EDID_H #define _EDID_H -//! EDID handling, including decoded EDID data block definition. +//! Extended Display Identification Data (EDID) #include "edid_raw.h" @@ -116,19 +116,20 @@ } edid1_detailed_monitor; // EDID data block -typedef struct{ +typedef struct edid1_info { edid1_vendor vendor; edid1_version version; edid1_display display; edid1_established_timing established_timing; edid1_std_timing std_timing[EDID1_NUM_STD_TIMING]; - + // since EDID version 1.2 edid1_detailed_monitor detailed_monitor[EDID1_NUM_DETAILED_MONITOR_DESC]; - + uint8 num_sections; } edid1_info; +#define EDID_VERSION_1 1 #ifdef __cplusplus extern "C" { Modified: haiku/trunk/headers/private/graphics/common/edid_raw.h =================================================================== --- haiku/trunk/headers/private/graphics/common/edid_raw.h 2007-10-12 10:29:08 UTC (rev 22515) +++ haiku/trunk/headers/private/graphics/common/edid_raw.h 2007-10-12 15:56:08 UTC (rev 22516) @@ -147,13 +147,13 @@ // types of detailed monitor description enum { - edid1_serial_number = 0xff, - edid1_ascii_data = 0xfe, - edid1_monitor_ranges = 0xfd, - edid1_monitor_name = 0xfc, - edid1_add_colour_pointer = 0xfb, - edid1_add_std_timing = 0xfa, - edid1_is_detailed_timing = 1 + EDID1_SERIAL_NUMBER = 0xff, + EDID1_ASCII_DATA = 0xfe, + EDID1_MONITOR_RANGES = 0xfd, + EDID1_MONITOR_NAME = 0xfc, + EDID1_ADD_COLOUR_POINTER = 0xfb, + EDID1_ADD_STD_TIMING = 0xfa, + EDID1_IS_DETAILED_TIMING = 1 }; Modified: haiku/trunk/src/add-ons/accelerants/common/decode_edid.c =================================================================== --- haiku/trunk/src/add-ons/accelerants/common/decode_edid.c 2007-10-12 10:29:08 UTC (rev 22515) +++ haiku/trunk/src/add-ons/accelerants/common/decode_edid.c 2007-10-12 15:56:08 UTC (rev 22516) @@ -179,7 +179,7 @@ int i, j; for (i = 0; i < EDID1_NUM_DETAILED_MONITOR_DESC; ++i, ++monitor, ++raw) { - monitor->monitor_desc_type = edid1_is_detailed_timing; + monitor->monitor_desc_type = EDID1_IS_DETAILED_TIMING; // workaround: normally, all four bytes must be zero for detailed // description, but at least some Formac monitors violate that: @@ -192,31 +192,31 @@ monitor->monitor_desc_type = raw->extra.monitor_desc_type; switch (raw->extra.monitor_desc_type) { - case edid1_serial_number: - copy_str( monitor->data.serial_number, - raw->extra.data.serial_number, EDID1_EXTRA_STRING_LEN ); + case EDID1_SERIAL_NUMBER: + copy_str(monitor->data.serial_number, + raw->extra.data.serial_number, EDID1_EXTRA_STRING_LEN); break; - case edid1_ascii_data: - copy_str( monitor->data.ascii_data, - raw->extra.data.ascii_data, EDID1_EXTRA_STRING_LEN ); + case EDID1_ASCII_DATA: + copy_str(monitor->data.ascii_data, + raw->extra.data.ascii_data, EDID1_EXTRA_STRING_LEN); break; - case edid1_monitor_ranges: + case EDID1_MONITOR_RANGES: monitor->data.monitor_range = raw->extra.data.monitor_range; break; - case edid1_monitor_name: - copy_str( monitor->data.monitor_name, - raw->extra.data.monitor_name, EDID1_EXTRA_STRING_LEN ); + case EDID1_MONITOR_NAME: + copy_str(monitor->data.monitor_name, + raw->extra.data.monitor_name, EDID1_EXTRA_STRING_LEN); break; - case edid1_add_colour_pointer: - decode_whitepoint( monitor->data.whitepoint, - &raw->extra.data.whitepoint ); + case EDID1_ADD_COLOUR_POINTER: + decode_whitepoint(monitor->data.whitepoint, + &raw->extra.data.whitepoint); break; - case edid1_add_std_timing: + case EDID1_ADD_STD_TIMING: for (j = 0; j < EDID1_NUM_EXTRA_STD_TIMING; ++j) { decode_std_timing(&monitor->data.std_timing[j], &raw->extra.data.std_timing[j]); Modified: haiku/trunk/src/add-ons/accelerants/common/dump_edid.c =================================================================== --- haiku/trunk/src/add-ons/accelerants/common/dump_edid.c 2007-10-12 10:29:08 UTC (rev 22515) +++ haiku/trunk/src/add-ons/accelerants/common/dump_edid.c 2007-10-12 15:56:08 UTC (rev 22516) @@ -90,15 +90,15 @@ edid1_detailed_monitor *monitor = &edid->detailed_monitor[i]; switch(monitor->monitor_desc_type) { - case edid1_serial_number: + case EDID1_SERIAL_NUMBER: dprintf("Serial Number: %s\n", monitor->data.serial_number); break; - case edid1_ascii_data: + case EDID1_ASCII_DATA: dprintf(" %s\n", monitor->data.serial_number); break; - case edid1_monitor_ranges: + case EDID1_MONITOR_RANGES: { edid1_monitor_range monitor_range = monitor->data.monitor_range; @@ -110,11 +110,11 @@ break; } - case edid1_monitor_name: - dprintf("Monitor Name: %s\n", monitor->data.serial_number); + case EDID1_MONITOR_NAME: + dprintf("Monitor Name: %s\n", monitor->data.monitor_name); break; - case edid1_add_colour_pointer: + case EDID1_ADD_COLOUR_POINTER: { for (j = 0; j < EDID1_NUM_EXTRA_WHITEPOINTS; ++j) { edid1_whitepoint *whitepoint = &monitor->data.whitepoint[j]; @@ -131,7 +131,7 @@ break; } - case edid1_add_std_timing: + case EDID1_ADD_STD_TIMING: { for (j = 0; j < EDID1_NUM_EXTRA_STD_TIMING; ++j) { edid1_std_timing *timing = &monitor->data.std_timing[j]; @@ -146,7 +146,7 @@ break; } - case edid1_is_detailed_timing: + case EDID1_IS_DETAILED_TIMING: { edid1_detailed_timing *timing = &monitor->data.detailed_timing; Modified: haiku/trunk/src/add-ons/accelerants/radeon/monitor_detection.c =================================================================== --- haiku/trunk/src/add-ons/accelerants/radeon/monitor_detection.c 2007-10-12 10:29:08 UTC (rev 22515) +++ haiku/trunk/src/add-ons/accelerants/radeon/monitor_detection.c 2007-10-12 15:56:08 UTC (rev 22516) @@ -696,7 +696,7 @@ int i; for (i = 0; i < EDID1_NUM_DETAILED_MONITOR_DESC; ++i) { - if (edid->detailed_monitor[i].monitor_desc_type == edid1_is_detailed_timing) { + if (edid->detailed_monitor[i].monitor_desc_type == EDID1_IS_DETAILED_TIMING) { const edid1_detailed_timing *timing = &edid->detailed_monitor[i].data.detailed_timing; SHOW_FLOW(2, "Found detailed timing for mode %dx%d in DDC data", Modified: haiku/trunk/src/system/boot/platform/bios_ia32/video.cpp =================================================================== --- haiku/trunk/src/system/boot/platform/bios_ia32/video.cpp 2007-10-12 10:29:08 UTC (rev 22515) +++ haiku/trunk/src/system/boot/platform/bios_ia32/video.cpp 2007-10-12 15:56:08 UTC (rev 22516) @@ -289,10 +289,10 @@ if (info->signature != VESA_SIGNATURE) return B_ERROR; - dprintf("VESA version = %lx\n", info->version); + dprintf("VESA version = %d.%d\n", info->version.major, info->version.minor); if (info->version.major < 2) { - dprintf("VESA support too old\n", info->version); + dprintf("VESA support too old\n"); return B_ERROR; } @@ -824,7 +824,7 @@ for (int32 i = 0; i < EDID1_NUM_DETAILED_MONITOR_DESC; i++) { edid1_detailed_monitor &monitor = info.detailed_monitor[i]; - if (monitor.monitor_desc_type == edid1_is_detailed_timing) { + if (monitor.monitor_desc_type == EDID1_IS_DETAILED_TIMING) { defaultMode = find_video_mode(monitor.data.detailed_timing.h_active, monitor.data.detailed_timing.v_active); if (defaultMode != NULL) From axeld at mail.berlios.de Fri Oct 12 17:59:50 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Fri, 12 Oct 2007 17:59:50 +0200 Subject: [Haiku-commits] r22517 - in haiku/trunk: headers/private/graphics/common src/add-ons/accelerants/common Message-ID: <200710121559.l9CFxoXe030395@sheep.berlios.de> Author: axeld Date: 2007-10-12 17:59:50 +0200 (Fri, 12 Oct 2007) New Revision: 22517 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22517&view=rev Added: haiku/trunk/headers/private/graphics/common/create_display_modes.h haiku/trunk/src/add-ons/accelerants/common/create_display_modes.cpp Modified: haiku/trunk/src/add-ons/accelerants/common/Jamfile Log: Started a create_display_modes() function that should be used by accelerants to create their mode list. Once it's done, it should cover all possible cases, and allow the base mode list to reside in the app_server (under Haiku, at least), so that all drivers will benefit from an updated list. Right now, it might already work to a degree, but it's not yet tested. Added: haiku/trunk/headers/private/graphics/common/create_display_modes.h =================================================================== --- haiku/trunk/headers/private/graphics/common/create_display_modes.h 2007-10-12 15:56:08 UTC (rev 22516) +++ haiku/trunk/headers/private/graphics/common/create_display_modes.h 2007-10-12 15:59:50 UTC (rev 22517) @@ -0,0 +1,29 @@ +/* + * Copyright 2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _CREATE_DISPLAY_MODES_H +#define _CREATE_DISPLAY_MODES_H + + +#include + +#include + + +typedef bool (*check_display_mode_hook)(display_mode *mode); + +#ifdef __cplusplus +extern "C" { +#endif + +area_id create_display_modes(const char *name, edid1_info *edid, + const display_mode *initialModes, uint32 initialModeCount, + const color_space *spaces, uint32 spacesCount, + check_display_mode_hook hook, display_mode **_modes, uint32 *_count); + +#ifdef __cplusplus +} +#endif + +#endif /* _CREATE_DISPLAY_MODES_H */ Modified: haiku/trunk/src/add-ons/accelerants/common/Jamfile =================================================================== --- haiku/trunk/src/add-ons/accelerants/common/Jamfile 2007-10-12 15:56:08 UTC (rev 22516) +++ haiku/trunk/src/add-ons/accelerants/common/Jamfile 2007-10-12 15:59:50 UTC (rev 22517) @@ -7,6 +7,7 @@ UsePrivateHeaders [ FDirName graphics common ] ; StaticLibrary libaccelerantscommon.a : + create_display_modes.cpp ddc.c decode_edid.c dump_edid.c Added: haiku/trunk/src/add-ons/accelerants/common/create_display_modes.cpp =================================================================== --- haiku/trunk/src/add-ons/accelerants/common/create_display_modes.cpp 2007-10-12 15:56:08 UTC (rev 22516) +++ haiku/trunk/src/add-ons/accelerants/common/create_display_modes.cpp 2007-10-12 15:59:50 UTC (rev 22517) @@ -0,0 +1,401 @@ +/* + * Copyright 2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ + + +#include + +#include +#include +#include + +#include + + +#define POSITIVE_SYNC \ + (B_POSITIVE_HSYNC | B_POSITIVE_VSYNC) +#define MODE_FLAGS \ + (B_8_BIT_DAC | B_HARDWARE_CURSOR | B_PARALLEL_ACCESS | B_DPMS | B_SUPPORTS_OVERLAYS) + +// TODO: move this list into the app_server +static const display_mode kBaseModeList[] = { + {{25175, 640, 656, 752, 800, 350, 387, 389, 449, B_POSITIVE_HSYNC}, B_CMAP8, 640, 350, 0, 0, MODE_FLAGS}, /* 640x350 - www.epanorama.net/documents/pc/vga_timing.html) */ + {{25175, 640, 656, 752, 800, 400, 412, 414, 449, B_POSITIVE_VSYNC}, B_CMAP8, 640, 400, 0, 0, MODE_FLAGS}, /* 640x400 - www.epanorama.net/documents/pc/vga_timing.html) */ + {{25175, 640, 656, 752, 800, 480, 490, 492, 525, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 60Hz_(640X480X8.Z1) */ + {{27500, 640, 672, 768, 864, 480, 488, 494, 530, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* 640X480X60Hz */ + {{30500, 640, 672, 768, 864, 480, 517, 523, 588, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* SVGA_640X480X60HzNI */ + {{31500, 640, 664, 704, 832, 480, 489, 492, 520, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 70-72Hz_(640X480X8.Z1) */ + {{31500, 640, 656, 720, 840, 480, 481, 484, 500, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 75Hz_(640X480X8.Z1) */ + {{36000, 640, 696, 752, 832, 480, 481, 484, 509, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 85Hz_(640X480X8.Z1) */ + {{38100, 800, 832, 960, 1088, 600, 602, 606, 620, 0}, B_CMAP8, 800, 600, 0, 0, MODE_FLAGS}, /* SVGA_800X600X56HzNI */ + {{40000, 800, 840, 968, 1056, 600, 601, 605, 628, POSITIVE_SYNC}, B_CMAP8, 800, 600, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 60Hz_(800X600X8.Z1) */ + {{49500, 800, 816, 896, 1056, 600, 601, 604, 625, POSITIVE_SYNC}, B_CMAP8, 800, 600, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 75Hz_(800X600X8.Z1) */ + {{50000, 800, 856, 976, 1040, 600, 637, 643, 666, POSITIVE_SYNC}, B_CMAP8, 800, 600, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 70-72Hz_(800X600X8.Z1) */ + {{56250, 800, 832, 896, 1048, 600, 601, 604, 631, POSITIVE_SYNC}, B_CMAP8, 800, 600, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 85Hz_(800X600X8.Z1) */ + {{65000, 1024, 1048, 1184, 1344, 768, 771, 777, 806, 0}, B_CMAP8, 1024, 768, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 60Hz_(1024X768X8.Z1) */ + {{75000, 1024, 1048, 1184, 1328, 768, 771, 777, 806, 0}, B_CMAP8, 1024, 768, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 70-72Hz_(1024X768X8.Z1) */ + {{78750, 1024, 1040, 1136, 1312, 768, 769, 772, 800, POSITIVE_SYNC}, B_CMAP8, 1024, 768, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 75Hz_(1024X768X8.Z1) */ + {{94500, 1024, 1072, 1168, 1376, 768, 769, 772, 808, POSITIVE_SYNC}, B_CMAP8, 1024, 768, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 85Hz_(1024X768X8.Z1) */ + {{94200, 1152, 1184, 1280, 1472, 864, 865, 868, 914, POSITIVE_SYNC}, B_CMAP8, 1152, 864, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 70Hz_(1152X864X8.Z1) */ + {{108000, 1152, 1216, 1344, 1600, 864, 865, 868, 900, POSITIVE_SYNC}, B_CMAP8, 1152, 864, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 75Hz_(1152X864X8.Z1) */ + {{121500, 1152, 1216, 1344, 1568, 864, 865, 868, 911, POSITIVE_SYNC}, B_CMAP8, 1152, 864, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 85Hz_(1152X864X8.Z1) */ + {{108000, 1280, 1328, 1440, 1688, 1024, 1025, 1028, 1066, POSITIVE_SYNC}, B_CMAP8, 1280, 1024, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 60Hz_(1280X1024X8.Z1) */ + {{135000, 1280, 1296, 1440, 1688, 1024, 1025, 1028, 1066, POSITIVE_SYNC}, B_CMAP8, 1280, 1024, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 75Hz_(1280X1024X8.Z1) */ + {{157500, 1280, 1344, 1504, 1728, 1024, 1025, 1028, 1072, POSITIVE_SYNC}, B_CMAP8, 1280, 1024, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 85Hz_(1280X1024X8.Z1) */ + + {{106500, 1440, 1520, 1672, 1904, 900, 901, 904, 932, POSITIVE_SYNC}, B_CMAP8, 1440, 900, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 60Hz_(1440X900) */ + + {{162000, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 60Hz_(1600X1200X8.Z1) */ + {{175500, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 65Hz_(1600X1200X8.Z1) */ + {{189000, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 70Hz_(1600X1200X8.Z1) */ + {{202500, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 75Hz_(1600X1200X8.Z1) */ + {{216000, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 80Hz_(1600X1200X8.Z1) */ + {{229500, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 85Hz_(1600X1200X8.Z1) */ + + {{147100, 1680, 1784, 1968, 2256, 1050, 1051, 1054, 1087, POSITIVE_SYNC}, B_CMAP8, 1680, 1050, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 60Hz_(1680X1050) */ + + {{154000, 1920, 1968, 2000, 2080, 1200, 1203, 1209, 1235, POSITIVE_SYNC}, B_CMAP8, 1920, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 60Hz_(1920X1200) */ +}; +static const uint32 kNumBaseModes = sizeof(kBaseModeList) / sizeof(display_mode); + + +namespace BPrivate { + +class ModeList { +public: + ModeList(); + ~ModeList(); + + bool AddModes(edid1_info* info); + bool AddModes(const display_mode* modes, uint32 count); + + bool CreateColorSpaces(const color_space* spaces, uint32 count); + void Filter(check_display_mode_hook hook); + void Clean(); + + const display_mode* Modes() const { return fModes; } + uint32 Count() const { return fCount; } + +private: + bool _MakeSpace(uint32 count); + bool _AddMode(const display_mode* mode); + void _RemoveModeAt(uint32 index); + void _AddBaseMode(uint16 width, uint16 height, uint32 refresh); + + display_mode* fModes; + uint32 fCount; + uint32 fCapacity; +}; + +} // namespace BPrivate + +using namespace BPrivate; + + +static float +get_refresh_rate(const display_mode& mode) +{ + // we have to be catious as refresh rate cannot be controlled directly, + // so it suffers under rounding errors and hardware restrictions + return rint(10 * float(mode.timing.pixel_clock * 1000) / + float(mode.timing.h_total * mode.timing.v_total)) / 10.0; +} + + +static int +compare_mode(const void* _mode1, const void* _mode2) +{ + display_mode *mode1 = (display_mode *)_mode1; + display_mode *mode2 = (display_mode *)_mode2; + uint16 width1, width2, height1, height2; + + width1 = mode1->virtual_width; + height1 = mode1->virtual_height; + width2 = mode2->virtual_width; + height2 = mode2->virtual_height; + + if (width1 != width2) + return width1 - width2; + + if (height1 != height2) + return height1 - height2; + + if (mode1->space != mode2->space) + return mode1->space - mode2->space; + + return (int)(10 * get_refresh_rate(*mode1) + - 10 * get_refresh_rate(*mode2)); +} + + +// #pragma mark - + + +ModeList::ModeList() + : + fModes(NULL), + fCount(0), + fCapacity(0) +{ +} + + +ModeList::~ModeList() +{ + free(fModes); +} + + +bool +ModeList::AddModes(edid1_info* info) +{ + if (info->established_timing.res_720x400x70) + _AddBaseMode(720, 400, 70); + if (info->established_timing.res_720x400x88) + _AddBaseMode(720, 400, 88); + + if (info->established_timing.res_640x480x60) + _AddBaseMode(640, 480, 60); + if (info->established_timing.res_640x480x67) + _AddBaseMode(640, 480, 67); + if (info->established_timing.res_640x480x72) + _AddBaseMode(640, 480, 72); + if (info->established_timing.res_640x480x75) + _AddBaseMode(640, 480, 75); + + if (info->established_timing.res_800x600x56) + _AddBaseMode(800, 600, 56); + if (info->established_timing.res_800x600x60) + _AddBaseMode(800, 600, 60); + if (info->established_timing.res_800x600x72) + _AddBaseMode(800, 600, 72); + if (info->established_timing.res_800x600x75) + _AddBaseMode(800, 600, 75); + +#if 0 + if (info->established_timing.res_832x624x75) + _AddBaseMode(832, 624, 75); + + if (info->established_timing.res_1024x768x87i) + _AddBaseMode(1024, 768, 87); +#endif + if (info->established_timing.res_1024x768x60) + _AddBaseMode(1024, 768, 60); + if (info->established_timing.res_1024x768x70) + _AddBaseMode(1024, 768, 70); + if (info->established_timing.res_1024x768x75) + _AddBaseMode(1024, 768, 75); + + if (info->established_timing.res_1152x870x75) + _AddBaseMode(1152, 870, 75); + if (info->established_timing.res_1280x1024x75) + _AddBaseMode(1280, 1024, 75); + + for (uint32 i = 0; i < EDID1_NUM_STD_TIMING; ++i) { + if (info->std_timing[i].h_size <= 256) + continue; + + _AddBaseMode(info->std_timing[i].h_size, info->std_timing[i].v_size, + info->std_timing[i].refresh); + } + + for (uint32 i = 0; i < EDID1_NUM_DETAILED_MONITOR_DESC; ++i) { + if (info->detailed_monitor[i].monitor_desc_type != EDID1_IS_DETAILED_TIMING) + continue; + + const edid1_detailed_timing& timing = info->detailed_monitor[i].data.detailed_timing; + display_mode mode; + mode.timing.pixel_clock = timing.pixel_clock * 10; + mode.timing.h_display = timing.h_active; + mode.timing.h_sync_start = timing.h_blank; + mode.timing.h_sync_end = timing.h_sync_off; + mode.timing.h_total = timing.h_sync_width; + mode.timing.v_display = timing.v_active; + mode.timing.v_sync_start = timing.v_blank; + mode.timing.v_sync_end = timing.v_sync_off; + mode.timing.v_total = timing.v_sync_width; + mode.timing.flags = POSITIVE_SYNC; + mode.space = B_RGB32; + mode.virtual_width = timing.h_active; + mode.virtual_height = timing.v_active; + mode.h_display_start = 0; + mode.v_display_start = 0; + mode.flags = MODE_FLAGS; + } + + // TODO: add other modes from the base list that satisfy the display's + // requirements! + + return true; +} + + +bool +ModeList::AddModes(const display_mode* modes, uint32 count) +{ + if (!_MakeSpace(count)) + return false; + + for (uint32 i = 0; i < count; i++) { + fModes[fCount++] = modes[i]; + } + + return true; +} + + +bool +ModeList::CreateColorSpaces(const color_space* spaces, uint32 count) +{ + uint32 modeCount = fCount; + + for (uint32 i = 0; i < count; i++) { + if (i > 0 && !AddModes(fModes, modeCount)) + return false; + + for (uint32 j = 0; j < modeCount; j++) { + fModes[j + fCount - modeCount].space = spaces[i]; + } + } + + return true; +} + + +void +ModeList::Filter(check_display_mode_hook hook) +{ + if (hook == NULL) + return; + + for (uint32 i = fCount; i-- > 0;) { + if (!hook(&fModes[i])) + _RemoveModeAt(i); + } +} + + +void +ModeList::Clean() +{ + // sort mode list + qsort(fModes, fCount, sizeof(display_mode), compare_mode); + + // remove duplicates + for (uint32 i = fCount; i-- > 1;) { + if (compare_mode(&fModes[i], &fModes[i - 1]) == 0) + _RemoveModeAt(i); + } +} + + +void +ModeList::_AddBaseMode(uint16 width, uint16 height, uint32 refresh) +{ + for (uint32 i = 0; i < kNumBaseModes; i++) { + const display_mode& mode = kBaseModeList[i]; + + if (mode.timing.h_display == width && mode.timing.v_display == height + && get_refresh_rate(mode) == refresh) { + _AddMode(&mode); + return; + } + } +} + + +bool +ModeList::_MakeSpace(uint32 count) +{ + if (fCount + count <= fCapacity) + return true; + + uint32 capacity = (fCapacity + count + 0xf) & ~0xf; + display_mode* modes = (display_mode*)realloc(fModes, + capacity * sizeof(display_mode)); + if (modes == NULL) + return false; + + fModes = modes; + fCapacity = capacity; + return true; +} + + +bool +ModeList::_AddMode(const display_mode* mode) +{ + if (!_MakeSpace(1)) + return false; + + fModes[fCount++] = *mode; + return true; +} + + +void +ModeList::_RemoveModeAt(uint32 index) +{ + if (index < fCount - 1) { + memmove(&fModes[index], &fModes[index + 1], + (fCount - 1 - index) * sizeof(display_mode)); + } + + fCount--; +} + + +// #pragma mark - + + +extern "C" area_id +create_display_modes(const char* name, edid1_info* edid, + const display_mode* initialModes, uint32 initialModeCount, + const color_space *spaces, uint32 spacesCount, + check_display_mode_hook hook, display_mode** _modes, uint32* _count) +{ + if (_modes == NULL || _count == NULL) + return B_BAD_VALUE; + + // compile initial mode list from the different sources + + ModeList modes; + modes.AddModes(initialModes, initialModeCount); + + if (edid != NULL) + modes.AddModes(edid); + else + modes.AddModes(kBaseModeList, kNumBaseModes); + + // filter out modes the caller doesn't like, and multiply modes for + // every color space + + if (spaces == NULL) { + const color_space kDefaultSpaces[] = {B_RGB32_LITTLE, B_RGB16_LITTLE, + B_RGB15_LITTLE, B_CMAP8}; + modes.CreateColorSpaces(kDefaultSpaces, + sizeof(kDefaultSpaces) / sizeof(kDefaultSpaces[0])); + } else + modes.CreateColorSpaces(spaces, spacesCount); + + modes.Filter(hook); + modes.Clean(); + + // create area for output modes + + size_t size = (sizeof(display_mode) * modes.Count() + B_PAGE_SIZE - 1) + & ~(B_PAGE_SIZE - 1); + display_mode *list; + area_id area = create_area(name, (void **)&list, B_ANY_ADDRESS, + size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); + if (area < B_OK) + return area; + + memcpy(list, modes.Modes(), sizeof(display_mode) * modes.Count()); + *_modes = list; + *_count = modes.Count(); + + return area; +} + From bonefish at mail.berlios.de Fri Oct 12 18:49:20 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Fri, 12 Oct 2007 18:49:20 +0200 Subject: [Haiku-commits] r22518 - haiku/trunk/src/system/libroot/posix/string Message-ID: <200710121649.l9CGnKU8004222@sheep.berlios.de> Author: bonefish Date: 2007-10-12 18:49:19 +0200 (Fri, 12 Oct 2007) New Revision: 22518 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22518&view=rev Modified: haiku/trunk/src/system/libroot/posix/string/memmove.c haiku/trunk/src/system/libroot/posix/string/strchr.c Log: Patch by Vasilis Kaoutsis: Style cleanup. Modified: haiku/trunk/src/system/libroot/posix/string/memmove.c =================================================================== --- haiku/trunk/src/system/libroot/posix/string/memmove.c 2007-10-12 15:59:50 UTC (rev 22517) +++ haiku/trunk/src/system/libroot/posix/string/memmove.c 2007-10-12 16:49:19 UTC (rev 22518) @@ -1,8 +1,9 @@ /* -** Copyright 2001, Travis Geiselbrecht. All rights reserved. -** Distributed under the terms of the NewOS License. -*/ + * Copyright 2001, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the NewOS License. + */ + #include #include @@ -13,55 +14,56 @@ #define lsize sizeof(word) #define lmask (lsize - 1) -void * -memmove(void *dest, void const *src, size_t count) + +void* +memmove(void* dest, void const* src, size_t count) { - char *d = (char *)dest; - const char *s = (const char *)src; + char* d = (char*)dest; + const char* s = (const char*)src; int len; - if(count == 0 || dest == src) + if (count == 0 || dest == src) return dest; - if((long)d < (long)s) { - if(((long)d | (long)s) & lmask) { + if ((long)d < (long)s) { + if (((long)d | (long)s) & lmask) { // src and/or dest do not align on word boundary - if((((long)d ^ (long)s) & lmask) || (count < lsize)) + if ((((long)d ^ (long)s) & lmask) || (count < lsize)) len = count; // copy the rest of the buffer with the byte mover else len = lsize - ((long)d & lmask); // move the ptrs up to a word boundary count -= len; - for(; len > 0; len--) + for (; len > 0; len--) *d++ = *s++; } - for(len = count / lsize; len > 0; len--) { - *(word *)d = *(word *)s; + for (len = count / lsize; len > 0; len--) { + *(word*)d = *(word*)s; d += lsize; s += lsize; } - for(len = count & lmask; len > 0; len--) + for (len = count & lmask; len > 0; len--) *d++ = *s++; } else { d += count; s += count; - if(((long)d | (long)s) & lmask) { + if (((long)d | (long)s) & lmask) { // src and/or dest do not align on word boundary - if((((long)d ^ (long)s) & lmask) || (count <= lsize)) + if ((((long)d ^ (long)s) & lmask) || (count <= lsize)) len = count; else len = ((long)d & lmask); count -= len; - for(; len > 0; len--) + for (; len > 0; len--) *--d = *--s; } - for(len = count / lsize; len > 0; len--) { + for (len = count / lsize; len > 0; len--) { d -= lsize; s -= lsize; - *(word *)d = *(word *)s; + *(word*)d = *(word*)s; } - for(len = count & lmask; len > 0; len--) + for (len = count & lmask; len > 0; len--) *--d = *--s; } @@ -69,4 +71,3 @@ } #endif - Modified: haiku/trunk/src/system/libroot/posix/string/strchr.c =================================================================== --- haiku/trunk/src/system/libroot/posix/string/strchr.c 2007-10-12 15:59:50 UTC (rev 22517) +++ haiku/trunk/src/system/libroot/posix/string/strchr.c 2007-10-12 16:49:19 UTC (rev 22518) @@ -1,25 +1,25 @@ /* -** Copyright 2001, Travis Geiselbrecht. All rights reserved. -** Distributed under the terms of the NewOS License. -*/ + * Copyright 2001, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the NewOS License. + */ + #include #include -char * -strchr(const char *s, int c) +char* +strchr(const char* s, int c) { - for(; *s != (char) c; ++s) + for (; *s != (char)c; ++s) if (*s == '\0') return NULL; - return (char *)s; + return (char*)s; } -char * -index(const char *s, int c) +char* +index(const char* s, int c) { return strchr(s, c); } - From bonefish at mail.berlios.de Fri Oct 12 18:49:57 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Fri, 12 Oct 2007 18:49:57 +0200 Subject: [Haiku-commits] r22519 - haiku/trunk/src/system/libroot/posix Message-ID: <200710121649.l9CGnvqN004915@sheep.berlios.de> Author: bonefish Date: 2007-10-12 18:49:56 +0200 (Fri, 12 Oct 2007) New Revision: 22519 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22519&view=rev Modified: haiku/trunk/src/system/libroot/posix/poll.c Log: Patch by Vasilis Kaoutsis: Correctly set errno on error. Modified: haiku/trunk/src/system/libroot/posix/poll.c =================================================================== --- haiku/trunk/src/system/libroot/posix/poll.c 2007-10-12 16:49:19 UTC (rev 22518) +++ haiku/trunk/src/system/libroot/posix/poll.c 2007-10-12 16:49:56 UTC (rev 22519) @@ -1,9 +1,10 @@ /* -** Copyright 2002-2004, Axel D?rfler, axeld at pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ + * Copyright 2002-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the OpenBeOS License. + */ +#include #include #include @@ -11,6 +12,10 @@ int poll(struct pollfd *fds, nfds_t numfds, int timeout) { - return _kern_poll(fds, numfds, timeout * 1000LL); + int result = _kern_poll(fds, numfds, timeout * 1000LL); + if (result < 0) { + errno = result; + return -1; + } + return result; } - From axeld at mail.berlios.de Fri Oct 12 18:50:26 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Fri, 12 Oct 2007 18:50:26 +0200 Subject: [Haiku-commits] r22520 - in haiku/trunk: headers/os/add-ons/graphics src/servers/app src/servers/app/drawing Message-ID: <200710121650.l9CGoQ5x005548@sheep.berlios.de> Author: axeld Date: 2007-10-12 18:50:24 +0200 (Fri, 12 Oct 2007) New Revision: 22520 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22520&view=rev Modified: haiku/trunk/headers/os/add-ons/graphics/Accelerant.h haiku/trunk/src/servers/app/ServerScreen.cpp haiku/trunk/src/servers/app/ServerScreen.h haiku/trunk/src/servers/app/VirtualScreen.cpp haiku/trunk/src/servers/app/drawing/AccelerantHWInterface.cpp haiku/trunk/src/servers/app/drawing/AccelerantHWInterface.h haiku/trunk/src/servers/app/drawing/HWInterface.cpp haiku/trunk/src/servers/app/drawing/HWInterface.h haiku/trunk/src/servers/app/drawing/Jamfile Log: * Started accelerant extension to be able to get the preferred mode from the accelerant, as well as its EDID info. B_GET_PREFERRED_DISPLAY_MODE and B_GET_EDID_INFO are both optional. The preferred mode will be taken from the EDID info if only the latter hook is implemented, or the former returned an error. * Currently, the app_server should correctly set the preferred mode on start, but no accelerant supports that yet, so it's not really tested. Modified: haiku/trunk/headers/os/add-ons/graphics/Accelerant.h =================================================================== --- haiku/trunk/headers/os/add-ons/graphics/Accelerant.h 2007-10-12 16:49:56 UTC (rev 22519) +++ haiku/trunk/headers/os/add-ons/graphics/Accelerant.h 2007-10-12 16:50:24 UTC (rev 22520) @@ -41,6 +41,8 @@ B_DPMS_CAPABILITIES, /* required if driver supports DPMS */ B_DPMS_MODE, /* required if driver supports DPMS */ B_SET_DPMS_MODE, /* required if driver supports DPMS */ + B_GET_PREFERRED_DISPLAY_MODE, /* optional */ + B_GET_EDID_INFO, /* optional */ /* cursor managment */ B_MOVE_CURSOR = 0x200, /* optional */ @@ -213,6 +215,8 @@ typedef uint32 (*dpms_capabilities)(void); typedef uint32 (*dpms_mode)(void); typedef status_t (*set_dpms_mode)(uint32 dpms_flags); +typedef status_t (*get_preferred_display_mode)(display_mode *preferredMode); +typedef status_t (*get_edid_info)(void *info, uint32 size, uint32 *_version); typedef sem_id (*accelerant_retrace_semaphore)(void); typedef status_t (*set_cursor_shape)(uint16 width, uint16 height, uint16 hot_x, uint16 hot_y, uint8 *andMask, uint8 *xorMask); Modified: haiku/trunk/src/servers/app/ServerScreen.cpp =================================================================== --- haiku/trunk/src/servers/app/ServerScreen.cpp 2007-10-12 16:49:56 UTC (rev 22519) +++ haiku/trunk/src/servers/app/ServerScreen.cpp 2007-10-12 16:50:24 UTC (rev 22520) @@ -86,7 +86,7 @@ status_t -Screen::SetMode(display_mode mode, bool makeDefault) +Screen::SetMode(const display_mode& mode, bool makeDefault) { gBitmapManager->SuspendOverlays(); @@ -140,6 +140,18 @@ } +status_t +Screen::SetPreferredMode() +{ + display_mode mode; + status_t status = fHWInterface->GetPreferredMode(&mode); + if (status < B_OK) + return status; + + return SetMode(mode, false); +} + + void Screen::GetMode(display_mode* mode) const { @@ -149,7 +161,7 @@ void Screen::GetMode(uint16 &width, uint16 &height, uint32 &colorspace, - float &frequency) const + float &frequency) const { display_mode mode; fHWInterface->GetMode(&mode); @@ -183,7 +195,7 @@ status_t Screen::_FindMode(uint16 width, uint16 height, uint32 colorspace, - float frequency, display_mode* mode) const + float frequency, display_mode* mode) const { display_mode* modes = NULL; uint32 count; Modified: haiku/trunk/src/servers/app/ServerScreen.h =================================================================== --- haiku/trunk/src/servers/app/ServerScreen.h 2007-10-12 16:49:56 UTC (rev 22519) +++ haiku/trunk/src/servers/app/ServerScreen.h 2007-10-12 16:50:24 UTC (rev 22520) @@ -30,10 +30,11 @@ int32 ID() const { return fID; } - status_t SetMode(display_mode mode, bool makeDefault); + status_t SetMode(const display_mode& mode, bool makeDefault); status_t SetMode(uint16 width, uint16 height, uint32 colorspace, float frequency, bool makeDefault); + status_t SetPreferredMode(); void GetMode(display_mode* mode) const; void GetMode(uint16 &width, Modified: haiku/trunk/src/servers/app/VirtualScreen.cpp =================================================================== --- haiku/trunk/src/servers/app/VirtualScreen.cpp 2007-10-12 16:49:56 UTC (rev 22519) +++ haiku/trunk/src/servers/app/VirtualScreen.cpp 2007-10-12 16:50:24 UTC (rev 22520) @@ -133,7 +133,8 @@ } if (status < B_OK) { // TODO: more intelligent standard mode (monitor preference, desktop default, ...) - screen->SetMode(800, 600, B_RGB32, 60.f, false); + if (screen->SetPreferredMode() != B_OK) + screen->SetMode(800, 600, B_RGB32, 60.f, false); } // TODO: this works only for single screen configurations Modified: haiku/trunk/src/servers/app/drawing/AccelerantHWInterface.cpp =================================================================== --- haiku/trunk/src/servers/app/drawing/AccelerantHWInterface.cpp 2007-10-12 16:49:56 UTC (rev 22519) +++ haiku/trunk/src/servers/app/drawing/AccelerantHWInterface.cpp 2007-10-12 16:50:24 UTC (rev 22520) @@ -22,6 +22,7 @@ #include "ServerProtocol.h" #include "SystemPalette.h" +#include #include #include @@ -349,6 +350,8 @@ // optional fAccGetTimingConstraints = (get_timing_constraints)fAccelerantHook(B_GET_TIMING_CONSTRAINTS, NULL); fAccProposeDisplayMode = (propose_display_mode)fAccelerantHook(B_PROPOSE_DISPLAY_MODE, NULL); + fAccGetPreferredDisplayMode = (get_preferred_display_mode)fAccelerantHook(B_GET_PREFERRED_DISPLAY_MODE, NULL); + fAccGetEDIDInfo = (get_edid_info)fAccelerantHook(B_GET_EDID_INFO, NULL); // cursor fAccSetCursorShape = (set_cursor_shape)fAccelerantHook(B_SET_CURSOR_SHAPE, NULL); @@ -716,6 +719,102 @@ } +status_t +AccelerantHWInterface::GetPreferredMode(display_mode* mode) +{ + status_t status = B_NOT_SUPPORTED; + + if (fAccGetPreferredDisplayMode != NULL) { + status = fAccGetPreferredDisplayMode(mode); + if (status == B_OK) + return B_OK; + } + + if (fAccGetEDIDInfo != NULL) { + edid1_info info; + uint32 version; + status_t status = fAccGetEDIDInfo(&info, sizeof(info), &version); + if (status < B_OK) + return status; + if (version != EDID_VERSION_1) + return B_NOT_SUPPORTED; + + status = B_ERROR; + + // find preferred mode from EDID info + for (uint32 i = 0; i < EDID1_NUM_DETAILED_MONITOR_DESC; ++i) { + if (info.detailed_monitor[i].monitor_desc_type != EDID1_IS_DETAILED_TIMING) + continue; + + // TODO: we could also just look for this mode in the most list + // TODO: handle sync and flags correctly! + const edid1_detailed_timing& timing = info.detailed_monitor[i].data.detailed_timing; + mode->timing.pixel_clock = timing.pixel_clock * 10; + mode->timing.h_display = timing.h_active; + mode->timing.h_sync_start = timing.h_blank; + mode->timing.h_sync_end = timing.h_sync_off; + mode->timing.h_total = timing.h_sync_width; + mode->timing.v_display = timing.v_active; + mode->timing.v_sync_start = timing.v_blank; + mode->timing.v_sync_end = timing.v_sync_off; + mode->timing.v_total = timing.v_sync_width; + mode->timing.flags = B_POSITIVE_HSYNC | B_POSITIVE_VSYNC; + mode->space = B_RGB32; + mode->virtual_width = timing.h_active; + mode->virtual_height = timing.v_active; + mode->h_display_start = 0; + mode->v_display_start = 0; + if (fModeCount > 0) + mode->flags = fModeList[0].flags; + else + mode->flags = B_8_BIT_DAC | B_PARALLEL_ACCESS; + status = B_OK; + } + } + + return status; +} + + +status_t +AccelerantHWInterface::GetMonitorInfo(BString& name, BString& serial) +{ + if (fAccGetEDIDInfo == NULL) + return B_NOT_SUPPORTED; + + edid1_info info; + uint32 version; + status_t status = fAccGetEDIDInfo(&info, sizeof(info), &version); + if (status < B_OK) + return status; + if (version != EDID_VERSION_1) + return B_NOT_SUPPORTED; + + uint32 found = 0; + + for (uint32 i = 0; i < EDID1_NUM_DETAILED_MONITOR_DESC; ++i) { + edid1_detailed_monitor *monitor = &info.detailed_monitor[i]; + + switch (monitor->monitor_desc_type) { + case EDID1_SERIAL_NUMBER: + serial.SetTo(monitor->data.serial_number); + found++; + break; + + case EDID1_MONITOR_NAME: + name.SetTo(monitor->data.monitor_name); + found++; + break; + + default: + break; + } + } + + return found > 0 ? B_OK : B_NAME_NOT_FOUND; +} + + sem_id AccelerantHWInterface::RetraceSemaphore() { Modified: haiku/trunk/src/servers/app/drawing/AccelerantHWInterface.h =================================================================== --- haiku/trunk/src/servers/app/drawing/AccelerantHWInterface.h 2007-10-12 16:49:56 UTC (rev 22519) +++ haiku/trunk/src/servers/app/drawing/AccelerantHWInterface.h 2007-10-12 16:50:24 UTC (rev 22520) @@ -41,6 +41,8 @@ virtual status_t ProposeMode(display_mode *candidate, const display_mode *low, const display_mode *high); + virtual status_t GetPreferredMode(display_mode* mode); + virtual status_t GetMonitorInfo(BString& name, BString& serial); virtual sem_id RetraceSemaphore(); virtual status_t WaitForRetrace(bigtime_t timeout = B_INFINITE_TIMEOUT); @@ -128,6 +130,8 @@ // optional accelerant hooks get_timing_constraints fAccGetTimingConstraints; propose_display_mode fAccProposeDisplayMode; + get_preferred_display_mode fAccGetPreferredDisplayMode; + get_edid_info fAccGetEDIDInfo; fill_rectangle fAccFillRect; invert_rectangle fAccInvertRect; screen_to_screen_blit fAccScreenBlit; Modified: haiku/trunk/src/servers/app/drawing/HWInterface.cpp =================================================================== --- haiku/trunk/src/servers/app/drawing/HWInterface.cpp 2007-10-12 16:49:56 UTC (rev 22519) +++ haiku/trunk/src/servers/app/drawing/HWInterface.cpp 2007-10-12 16:50:24 UTC (rev 22520) @@ -89,6 +89,20 @@ } +status_t +HWInterface::GetPreferredMode(display_mode* mode) +{ + return B_NOT_SUPPORTED; +} + + +status_t +HWInterface::GetMonitorInfo(BString& name, BString& serial) +{ + return B_NOT_SUPPORTED; +} + + // #pragma mark - Modified: haiku/trunk/src/servers/app/drawing/HWInterface.h =================================================================== --- haiku/trunk/src/servers/app/drawing/HWInterface.h 2007-10-12 16:49:56 UTC (rev 22519) +++ haiku/trunk/src/servers/app/drawing/HWInterface.h 2007-10-12 16:50:24 UTC (rev 22520) @@ -77,6 +77,8 @@ virtual status_t ProposeMode(display_mode *candidate, const display_mode *low, const display_mode *high) = 0; + virtual status_t GetPreferredMode(display_mode* mode); + virtual status_t GetMonitorInfo(BString& name, BString& serial); virtual sem_id RetraceSemaphore() = 0; virtual status_t WaitForRetrace(bigtime_t timeout = B_INFINITE_TIMEOUT) = 0; Modified: haiku/trunk/src/servers/app/drawing/Jamfile =================================================================== --- haiku/trunk/src/servers/app/drawing/Jamfile 2007-10-12 16:49:56 UTC (rev 22519) +++ haiku/trunk/src/servers/app/drawing/Jamfile 2007-10-12 16:50:24 UTC (rev 22520) @@ -2,6 +2,7 @@ UseLibraryHeaders agg ; UsePrivateHeaders app graphics kernel interface shared ; +UsePrivateHeaders [ FDirName graphics common ] ; UseHeaders [ FDirName $(HAIKU_TOP) src servers app ] ; UseHeaders [ FDirName $(HAIKU_TOP) src servers app drawing Painter ] ; From axeld at pinc-software.de Fri Oct 12 18:54:18 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Fri, 12 Oct 2007 18:54:18 +0200 CEST Subject: [Haiku-commits] r22519 - haiku/trunk/src/system/libroot/posix In-Reply-To: <200710121649.l9CGnvqN004915@sheep.berlios.de> Message-ID: <4190235857-BeMail@zon> bonefish at BerliOS wrote: > -** Copyright 2002-2004, Axel D?rfler, axeld at pinc-software.de. All > rights reserved. > -** Distributed under the terms of the OpenBeOS License. > -*/ > + * Copyright 2002-2007, Axel D?rfler, axeld at pinc-software.de. All > rights reserved. > + * Distributed under the terms of the OpenBeOS License. BTW please feel free to replace OpenBeOS with MIT here, and thanks! :-) Bye, Axel. From sbenedetto at mail.berlios.de Sat Oct 13 00:11:54 2007 From: sbenedetto at mail.berlios.de (sbenedetto at BerliOS) Date: Sat, 13 Oct 2007 00:11:54 +0200 Subject: [Haiku-commits] r22521 - haiku/trunk/build/jam Message-ID: <200710122211.l9CMBs2L007717@sheep.berlios.de> Author: sbenedetto Date: 2007-10-13 00:11:54 +0200 (Sat, 13 Oct 2007) New Revision: 22521 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22521&view=rev Modified: haiku/trunk/build/jam/HaikuImage Log: Removing the ohci driver from the building system so that I can work without worrying about breaking anything :-) I'll add it back once I have something usable. Modified: haiku/trunk/build/jam/HaikuImage =================================================================== --- haiku/trunk/build/jam/HaikuImage 2007-10-12 16:50:24 UTC (rev 22520) +++ haiku/trunk/build/jam/HaikuImage 2007-10-12 22:11:54 UTC (rev 22521) @@ -134,7 +134,7 @@ AddFilesToHaikuImage beos system add-ons kernel busses scsi : ahci ; AddFilesToHaikuImage beos system add-ons kernel busses usb - : uhci ohci ehci ; + : uhci ehci ; AddFilesToHaikuImage beos system add-ons kernel console : vga_text ; AddFilesToHaikuImage beos system add-ons kernel debugger : hangman ; AddFilesToHaikuImage beos system add-ons kernel file_systems From sbenedetto at mail.berlios.de Sat Oct 13 00:17:28 2007 From: sbenedetto at mail.berlios.de (sbenedetto at BerliOS) Date: Sat, 13 Oct 2007 00:17:28 +0200 Subject: [Haiku-commits] r22522 - haiku/trunk/src/add-ons/kernel/busses/usb Message-ID: <200710122217.l9CMHSn5008173@sheep.berlios.de> Author: sbenedetto Date: 2007-10-13 00:17:27 +0200 (Sat, 13 Oct 2007) New Revision: 22522 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22522&view=rev Modified: haiku/trunk/src/add-ons/kernel/busses/usb/ohci.cpp haiku/trunk/src/add-ons/kernel/busses/usb/ohci.h haiku/trunk/src/add-ons/kernel/busses/usb/ohci_hardware.h Log: * Clean up (removing unneeded comment) * Renaming, fixing coding guidelines * Re-writing AddTo method * Removing ohci_software.h file (its content has been moved to ohci.h) but it will probably be deleted in the future. Modified: haiku/trunk/src/add-ons/kernel/busses/usb/ohci.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/usb/ohci.cpp 2007-10-12 22:11:54 UTC (rev 22521) +++ haiku/trunk/src/add-ons/kernel/busses/usb/ohci.cpp 2007-10-12 22:17:27 UTC (rev 22522) @@ -1,67 +1,32 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2005, Jan-Rixt Van Hoye -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// explanation of this file: -// ------------------------- -// -// This is the implementation of the OHCI module for the Haiku USB stack -// It is bases on the hcir1_0a documentation that can be found on www.usb.org -// Some parts are derive from source-files from openbsd, netbsd and linux. -// -// ------------------------------------------------------------------------ +/* + * Copyright 2005-2008, Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Jan-Rixt Van Hoye + * Salvatore Benedetto + */ -// --------------------------- -// OHCI:: Includes -// --------------------------- #include #include #include #include #include -// --------------------------- -// OHCI:: Local includes -// --------------------------- - #include "ohci.h" -#include "ohci_hardware.h" -#include "usb_p.h" +pci_module_info *OHCI::sPCIModule = NULL; + //------------------------------------------------------ // OHCI:: Reverse the bits in a value between 0 and 31 // (Section 3.3.2) //------------------------------------------------------ - -static uint8 revbits[OHCI_NO_INTRS] = +static uint8 revbits[OHCI_NUMBER_OF_INTERRUPTS] = { 0x00, 0x10, 0x08, 0x18, 0x04, 0x14, 0x0c, 0x1c, 0x02, 0x12, 0x0a, 0x1a, 0x06, 0x16, 0x0e, 0x1e, 0x01, 0x11, 0x09, 0x19, 0x05, 0x15, 0x0d, 0x1d, 0x03, 0x13, 0x0b, 0x1b, 0x07, 0x17, 0x0f, 0x1f }; -//------------------------------------------------------------------------ -// OHCI:: These are the OHCI operations that can be done. -// -// parameters: -// - op: operation -//------------------------------------------------------------------------ static int32 ohci_std_ops( int32 op , ... ) @@ -69,14 +34,15 @@ switch (op) { case B_MODULE_INIT: - TRACE(("ohci_module: init the module\n")); + TRACE(("usb_ohci_module: init module\n")); return B_OK; case B_MODULE_UNINIT: - TRACE(("ohci_module: uninit the module\n")); + TRACE(("usb_ohci_module: uninit module\n")); break; default: return EINVAL; } + return B_OK; } @@ -87,67 +53,82 @@ // - &stack: reference to a stack instance form stack.cpp //------------------------------------------------------------------------ -static status_t -ohci_add_to(Stack *stack) +status_t +OHCI::AddTo(Stack *stack) { - status_t status; - pci_info *item; - bool found = false; - int i; - #ifdef TRACE_USB set_dprintf_enabled(true); load_driver_symbols("ohci"); #endif - // - // Try if the PCI module is loaded - // - if( ( status = get_module( B_PCI_MODULE_NAME, (module_info **)&( OHCI::pci_module ) ) ) != B_OK) { - TRACE(("USB_ OHCI: init_hardware(): Get PCI module failed! %lu \n", status)); - return status; + if (!sPCIModule) { + status_t status = get_module(B_PCI_MODULE_NAME, (module_info **)&sPCIModule); + if (status < B_OK) { + TRACE_ERROR(("usb_ohci: AddTo(): getting pci module failed! 0x%08lx\n", + status)); + return status; + } } - TRACE(("usb_ohci init_hardware(): Setting up hardware\n")); - item = new pci_info; - for ( i = 0 ; OHCI::pci_module->get_nth_pci_info( i , item ) == B_OK ; i++ ) { - if ( ( item->class_base == PCI_serial_bus ) && ( item->class_sub == PCI_usb ) - && ( item->class_api == PCI_usb_ohci ) ) - { - if ((item->u.h0.interrupt_line == 0) || (item->u.h0.interrupt_line == 0xFF)) { - TRACE(("USB OHCI: init_hardware(): found with invalid IRQ - check IRQ assignement\n")); + + TRACE(("usb_ohci: AddTo(): setting up hardware\n")); + + bool found = false; + pci_info *item = new(std::nothrow) pci_info; + if (!item) { + sPCIModule = NULL; + put_module(B_PCI_MODULE_NAME); + return B_NO_MEMORY; + } + + for (uint32 i = 0 ; sPCIModule->get_nth_pci_info(i, item) >= B_OK; i++) { + + if (item->class_base == PCI_serial_bus && item->class_sub == PCI_usb + && item->class_api == PCI_usb_ohci) { + if (item->u.h0.interrupt_line == 0 + || item->u.h0.interrupt_line == 0xFF) { + TRACE_ERROR(("usb_ohci: AddTo(): found with invalid IRQ -" + " check IRQ assignement\n")); continue; } - TRACE(("USB OHCI: init_hardware(): found at IRQ %u \n", item->u.h0.interrupt_line)); + + TRACE(("usb_ohci: AddTo(): found at IRQ %u\n", + item->u.h0.interrupt_line)); OHCI *bus = new(std::nothrow) OHCI(item, stack); - if (!bus) { delete item; - OHCI::pci_module = NULL; + sPCIModule = NULL; put_module(B_PCI_MODULE_NAME); return B_NO_MEMORY; } - - if (bus->InitCheck() != B_OK) { - TRACE(("usb_ohci: bus failed to initialize...\n")); + + if (bus->InitCheck() < B_OK) { + TRACE_ERROR(("usb_ohci: AddTo(): InitCheck() failed 0x%08lx\n", + bus->InitCheck())); delete bus; continue; } - bus->Start(); - stack->AddBusManager( bus ); + // the bus took it away + item = new(std::nothrow) pci_info; + + bus->Start(); + stack->AddBusManager(bus); found = true; } } - + if (!found) { - TRACE(("USB OHCI: init hardware(): no devices found\n")); - free( item ); - put_module( B_PCI_MODULE_NAME ); + TRACE_ERROR(("usb_ohci: no devices found\n")); + delete item; + put_module(B_PCI_MODULE_NAME); return ENODEV; } - return B_OK; //Hardware found + + delete item; + return B_OK; } + //------------------------------------------------------------------------ // OHCI:: Host controller information // @@ -157,11 +138,11 @@ host_controller_info ohci_module = { { "busses/usb/ohci", - 0, // No flag like B_KEEP_LOADED : the usb module does that + 0, ohci_std_ops }, - NULL , - ohci_add_to + NULL, + OHCI::AddTo }; //------------------------------------------------------------------------ @@ -194,10 +175,10 @@ fRootHubAddress(0), fNumPorts(0) { - fPcii = info; + fPCIInfo = info; fStack = stack; int i; - TRACE(("USB OHCI: constructing new BusManager\n")); + TRACE(("usb_ohci: constructing new BusManager\n")); fInitOK = false; @@ -205,22 +186,22 @@ fInterruptEndpoints[i] = 0; // enable busmaster and memory mapped access - uint16 cmd = OHCI::pci_module->read_pci_config(fPcii->bus, fPcii->device, fPcii->function, PCI_command, 2); + uint16 cmd = sPCIModule->read_pci_config(fPCIInfo->bus, fPCIInfo->device, fPCIInfo->function, PCI_command, 2); cmd &= ~PCI_command_io; cmd |= PCI_command_master | PCI_command_memory; - OHCI::pci_module->write_pci_config(fPcii->bus, fPcii->device, fPcii->function, PCI_command, 2, cmd ); + sPCIModule->write_pci_config(fPCIInfo->bus, fPCIInfo->device, fPCIInfo->function, PCI_command, 2, cmd ); // // 5.1.1.2 map the registers // - addr_t registeroffset = pci_module->read_pci_config(info->bus, + addr_t registeroffset = sPCIModule->read_pci_config(info->bus, info->device, info->function, PCI_base_registers, 4); registeroffset &= PCI_address_memory_32_mask; TRACE(("OHCI: iospace offset: %lx\n" , registeroffset)); fRegisterArea = map_physical_memory("OHCI base registers", (void *)registeroffset, - B_PAGE_SIZE, B_ANY_KERNEL_BLOCK_ADDRESS, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA | B_READ_AREA | B_WRITE_AREA, (void **)&fRegisters); + B_PAGE_SIZE, B_ANY_KERNEL_BLOCK_ADDRESS, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA | B_READ_AREA | B_WRITE_AREA, (void **)&fRegisterBase); if (fRegisterArea < B_OK) { - TRACE(("USB OHCI: error mapping the registers\n")); + TRACE(("usb_ohci: error mapping the registers\n")); return; } @@ -230,7 +211,7 @@ // Check the revision of the controller. The revision should be 10xh TRACE((" OHCI: Version %ld.%ld%s\n", OHCI_REV_HI(rev), OHCI_REV_LO(rev),OHCI_REV_LEGACY(rev) ? ", legacy support" : "")); if (OHCI_REV_HI(rev) != 1 || OHCI_REV_LO(rev) != 0) { - TRACE(("USB OHCI: Unsupported OHCI revision of the ohci device\n")); + TRACE(("usb_ohci: Unsupported OHCI revision of the ohci device\n")); return; } @@ -239,7 +220,7 @@ fHccaArea = fStack->AllocateArea((void**)&fHcca, &hcca_phy, B_PAGE_SIZE, "OHCI HCCA"); if (fHccaArea < B_OK) { - TRACE(("USB OHCI: Error allocating HCCA block\n")); + TRACE(("usb_ohci: Error allocating HCCA block\n")); return; } memset((void*)fHcca, 0, sizeof(ohci_hcca)); @@ -248,14 +229,14 @@ // 5.1.1.3 Take control of the host controller // if (ReadReg(OHCI_CONTROL) & OHCI_IR) { - TRACE(("USB OHCI: SMM is in control of the host controller\n")); + TRACE(("usb_ohci: SMM is in control of the host controller\n")); WriteReg(OHCI_COMMAND_STATUS, OHCI_OCR); for (int i = 0; i < 100 && (ReadReg(OHCI_CONTROL) & OHCI_IR); i++) snooze(1000); if (ReadReg(OHCI_CONTROL) & OHCI_IR) - TRACE(("USB OHCI: SMM doesn't respond... continueing anyway...\n")); + TRACE(("usb_ohci: SMM doesn't respond... continueing anyway...\n")); } else if (!(ReadReg(OHCI_CONTROL) & OHCI_HCFS_RESET)) { - TRACE(("USB OHCI: BIOS is in control of the host controller\n")); + TRACE(("usb_ohci: BIOS is in control of the host controller\n")); if (!(ReadReg(OHCI_CONTROL) & OHCI_HCFS_OPERATIONAL)) { WriteReg(OHCI_CONTROL, OHCI_HCFS_RESUME); snooze(USB_DELAY_BUS_RESET); @@ -287,9 +268,9 @@ else fInterruptEndpoints[i]->SetNext(fDummyIsochronous); } - for (i = 0; i < OHCI_NO_INTRS; i++) + for (i = 0; i < OHCI_NUMBER_OF_INTERRUPTS; i++) fHcca->hcca_interrupt_table[revbits[i]] = - fInterruptEndpoints[OHCI_NO_EDS-OHCI_NO_INTRS+i]->physicaladdress; + fInterruptEndpoints[OHCI_NO_EDS-OHCI_NUMBER_OF_INTERRUPTS+i]->physicaladdress; //Go to the hardware part of the initialisation uint32 frameinterval = ReadReg(OHCI_FM_INTERVAL); @@ -301,7 +282,7 @@ break; } if (ReadReg(OHCI_COMMAND_STATUS) & OHCI_HCR) { - TRACE(("USB OHCI: Error resetting the host controller\n")); + TRACE(("usb_ohci: Error resetting the host controller\n")); return; } @@ -368,7 +349,7 @@ return B_ERROR; if (!(ReadReg(OHCI_CONTROL) & OHCI_HCFS_OPERATIONAL)) { - TRACE(("USB OHCI::Start(): Controller not started. TODO: find out what happens.\n")); + TRACE(("usb_ohci::Start(): Controller not started. TODO: find out what happens.\n")); return B_ERROR; } @@ -377,17 +358,17 @@ fRootHub = new(std::nothrow) OHCIRootHub(this, fRootHubAddress); if (!fRootHub) { - TRACE_ERROR(("USB OHCI::Start(): no memory to allocate root hub\n")); + TRACE_ERROR(("usb_ohci::Start(): no memory to allocate root hub\n")); return B_NO_MEMORY; } if (fRootHub->InitCheck() < B_OK) { - TRACE_ERROR(("USB OHCI::Start(): root hub failed init check\n")); + TRACE_ERROR(("usb_ohci::Start(): root hub failed init check\n")); return B_ERROR; } SetRootHub(fRootHub); - TRACE(("USB OHCI::Start(): Succesful start\n")); + TRACE(("usb_ohci::Start(): Succesful start\n")); return B_OK; } @@ -525,7 +506,7 @@ //Add a NULL list by creating one TransferDescriptor TransferDescriptor *trans = new(std::nothrow) TransferDescriptor; endpoint->head = endpoint->tail = trans; - endpoint->ed->headp = endpoint->ed->tailp = trans->physicaladdress; + endpoint->ed->head_pointer = endpoint->ed->tail_pointer = trans->physicaladdress; return endpoint; } @@ -544,12 +525,12 @@ TRACE(("OHCI::%s()\n", __FUNCTION__)); TransferDescriptor *transfer = new TransferDescriptor; void *phy; - if (fStack->AllocateChunk((void **)&transfer->td, &phy, sizeof(ohci_transfer_descriptor)) != B_OK) { + if (fStack->AllocateChunk((void **)&transfer->td, &phy, sizeof(ohci_general_transfer_descriptor)) != B_OK) { TRACE(("OHCI::AllocateTransfer(): Error Allocating Transfer\n")); return 0; } transfer->physicaladdress = (addr_t)phy; - memset((void *)transfer->td, 0, sizeof(ohci_transfer_descriptor)); + memset((void *)transfer->td, 0, sizeof(ohci_general_transfer_descriptor)); return transfer; } @@ -557,7 +538,7 @@ OHCI::FreeTransfer(TransferDescriptor *trans) { TRACE(("OHCI::%s(%p)\n", __FUNCTION__, trans)); - fStack->FreeChunk((void *)trans->td, (void *) trans->physicaladdress, sizeof(ohci_transfer_descriptor)); + fStack->FreeChunk((void *)trans->td, (void *) trans->physicaladdress, sizeof(ohci_general_transfer_descriptor)); delete trans; } @@ -579,21 +560,21 @@ uint32 properties = 0; //Set the device address - properties |= OHCI_ENDPOINT_SET_FA(p->DeviceAddress()); + properties |= OHCI_ENDPOINT_SET_DEVICE_ADDRESS(p->DeviceAddress()); //Set the endpoint number - properties |= OHCI_ENDPOINT_SET_EN(p->EndpointAddress()); + properties |= OHCI_ENDPOINT_SET_ENDPOINT_NUMBER(p->EndpointAddress()); //Set the direction switch (p->Direction()) { case Pipe::In: - properties |= OHCI_ENDPOINT_DIR_IN; + properties |= OHCI_ENDPOINT_DIRECTION_IN; break; case Pipe::Out: - properties |= OHCI_ENDPOINT_DIR_OUT; + properties |= OHCI_ENDPOINT_DIRECTION_OUT; break; case Pipe::Default: - properties |= OHCI_ENDPOINT_DIR_TD; + properties |= OHCI_ENDPOINT_DIRECTION_DESCRIPTOR; break; default: //TODO: error @@ -616,10 +597,10 @@ //Assign the format. Isochronous endpoints require this switch if (p->Type() & USB_OBJECT_ISO_PIPE) - properties |= OHCI_ENDPOINT_FORMAT_ISO; + properties |= OHCI_ENDPOINT_ISOCHRONOUS_FORMAT; //Set the maximum packet size - properties |= OHCI_ENDPOINT_SET_MAXP(p->MaxPacketSize()); + properties |= OHCI_ENDPOINT_SET_MAX_PACKET_SIZE(p->MaxPacketSize()); endpoint->ed->flags = properties; } @@ -653,18 +634,25 @@ return B_OK; } -pci_module_info *OHCI::pci_module = 0; +pci_module_info *sPCIModule = 0; void OHCI::WriteReg(uint32 reg, uint32 value) { TRACE(("OHCI::%s(%lu, %lu)\n", __FUNCTION__, reg, value)); - *(volatile uint32 *)(fRegisters + reg) = value; + *(volatile uint32 *)(fRegisterBase + reg) = value; } uint32 OHCI::ReadReg(uint32 reg) { TRACE(("OHCI::%s(%lu)\n", __FUNCTION__, reg)); - return *(volatile uint32 *)(fRegisters + reg); + return *(volatile uint32 *)(fRegisterBase + reg); } + +status_t +OHCI::CancelQueuedTransfers(Pipe *pipe) +{ + return B_ERROR; +} + Modified: haiku/trunk/src/add-ons/kernel/busses/usb/ohci.h =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/usb/ohci.h 2007-10-12 22:11:54 UTC (rev 22521) +++ haiku/trunk/src/add-ons/kernel/busses/usb/ohci.h 2007-10-12 22:17:27 UTC (rev 22522) @@ -1,42 +1,52 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2005, Jan-Rixt Van Hoye -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -//------------------------------------------------------------------------------- +/* + * Copyright 2005-2008, Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Jan-Rixt Van Hoye + * Salvatore Benedetto + */ - #ifndef OHCI_H #define OHCI_H -// --------------------------- -// OHCI:: Includes -// --------------------------- - #include "usb_p.h" -#include "ohci_software.h" +#include "ohci_hardware.h" +#include struct pci_info; struct pci_module_info; class OHCIRootHub; + struct Endpoint; struct TransferDescriptor; +// -------------------------------------- +// OHCI:: Software isonchronous +// transfer descriptor +// -------------------------------------- +typedef struct hcd_soft_itransfer +{ + ohci_isochronous_transfer_descriptor itd; + struct hcd_soft_itransfer *nextitd; // mirrors nexttd in ITD + struct hcd_soft_itransfer *dnext; // next in done list + addr_t physaddr; // physical address to the host controller isonchronous transfer + //LIST_ENTRY(hcd_soft_itransfer) hnext; + uint16 flags; // flags +#ifdef DIAGNOSTIC + char isdone; // is the transfer done? +#endif +}hcd_soft_itransfer; + +#define OHCI_SITD_SIZE ((sizeof (struct hcd_soft_itransfer) + OHCI_ITD_ALIGN - 1) / OHCI_ITD_ALIGN * OHCI_ITD_ALIGN) +#define OHCI_SITD_CHUNK 64 + +// ------------------------------------------ +// OHCI:: Number of enpoint descriptors (63) +// ------------------------------------------ + +#define OHCI_NO_EDS (2 * OHCI_NUMBER_OF_INTERRUPTS - 1) + // -------------------------------- // OHCI: The OHCI class derived // from the BusManager @@ -46,31 +56,40 @@ { friend class OHCIRootHub; public: - - OHCI(pci_info *info, Stack *stack); - ~OHCI(); - status_t Start(); - status_t SubmitTransfer(Transfer *t); //Override from BusManager. - status_t NotifyPipeChange(Pipe *pipe, //Override from BusManager. - usb_change change); - static pci_module_info *pci_module; // Global data for the module. + OHCI(pci_info *info, Stack *stack); + ~OHCI(); - status_t GetPortStatus(uint8 index, usb_port_status *status); - status_t ClearPortFeature(uint8 index, uint16 feature); - status_t SetPortFeature(uint8 index, uint16 feature); - - uint8 PortCount() { return fNumPorts; }; + status_t Start(); +virtual status_t SubmitTransfer(Transfer *transfer); +virtual status_t CancelQueuedTransfers(Pipe *pipe); +virtual status_t NotifyPipeChange(Pipe *pipe, + usb_change change); + +static status_t AddTo(Stack *stack); + + // Port operations + status_t GetPortStatus(uint8 index, usb_port_status *status); + status_t SetPortFeature(uint8 index, uint16 feature); + status_t ClearPortFeature(uint8 index, uint16 feature); + + uint8 PortCount() { return fNumPorts; }; + private: - inline void WriteReg(uint32 reg, uint32 value); - inline uint32 ReadReg(uint32 reg); + // Register functions +inline void WriteReg(uint32 reg, uint32 value); +inline uint32 ReadReg(uint32 reg); // Global - pci_info *fPcii; // pci-info struct - Stack *fStack; // Pointer to the stack - uint8 *fRegisters; // Base address of the operational registers - area_id fRegisterArea; // Area id of the +static pci_module_info *sPCIModule; + + uint32 *fRegisterBase; + pci_info *fPCIInfo; + Stack *fStack; + + area_id fRegisterArea; + // HCCA area_id fHccaArea; struct ohci_hcca *fHcca; // The HCCA structure for the interupt communication @@ -79,10 +98,6 @@ Endpoint *fDummyControl; Endpoint *fDummyBulk; Endpoint *fDummyIsochronous; - // Root Hub - OHCIRootHub *fRootHub; // the root hub - uint8 fRootHubAddress; // the usb address of the roothub - uint8 fNumPorts; // the number of ports // functions Endpoint *AllocateEndpoint(); // allocate memory for an endpoint void FreeEndpoint(Endpoint *end); // Free endpoint @@ -90,6 +105,11 @@ void FreeTransfer(TransferDescriptor *trans); // Free transfer status_t InsertEndpointForPipe(Pipe *p); + + // Root Hub + OHCIRootHub *fRootHub; + uint8 fRootHubAddress; + uint8 fNumPorts; }; // -------------------------------- @@ -132,7 +152,7 @@ struct TransferDescriptor { addr_t physicaladdress; - ohci_transfer_descriptor *td; + ohci_general_transfer_descriptor *td; }; #endif // OHCI_H Modified: haiku/trunk/src/add-ons/kernel/busses/usb/ohci_hardware.h =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/usb/ohci_hardware.h 2007-10-12 22:11:54 UTC (rev 22521) +++ haiku/trunk/src/add-ons/kernel/busses/usb/ohci_hardware.h 2007-10-12 22:17:27 UTC (rev 22522) @@ -1,24 +1,11 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2005, Jan-Rixt Van Hoye -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -//------------------------------------------------------------------------------ +/* + * Copyright 2005-2008, Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Jan-Rixt Van Hoye + * Salvatore Benedetto + */ #ifndef OHCI_HARD_H #define OHCI_HARD_H @@ -31,9 +18,9 @@ // Revision register (section 7.1.1) // -------------------------------- -#define OHCI_REVISION 0x00 // OHCI revision -#define OHCI_REV_LO(rev) ((rev)&0x0f) -#define OHCI_REV_HI(rev) (((rev)>>4)&0x03) +#define OHCI_REVISION 0x00 +#define OHCI_REV_LO(rev) ((rev) & 0x0f) +#define OHCI_REV_HI(rev) (((rev) >> 4) & 0x03) #define OHCI_REV_LEGACY(rev) ((rev) & 0x10) // -------------------------------- @@ -71,7 +58,7 @@ #define OHCI_SOC_MASK 0x00030000 // Scheduling Overrun Count // -------------------------------- -// Interupt status register (section 7.1.4) +// Interrupt status register (section 7.1.4) // -------------------------------- #define OHCI_INTERRUPT_STATUS 0x0c @@ -273,11 +260,11 @@ // HCCA structure (section 4.4) // -------------------------------- -#define OHCI_NO_INTRS 32 +#define OHCI_NUMBER_OF_INTERRUPTS 32 -struct ohci_hcca +typedef struct ohci_hcca { - addr_t hcca_interrupt_table[OHCI_NO_INTRS]; + addr_t hcca_interrupt_table[OHCI_NUMBER_OF_INTERRUPTS]; uint32 hcca_frame_number; addr_t hcca_done_head; uint8 hcca_reserved_for_hc[116]; @@ -297,114 +284,113 @@ typedef struct ohci_endpoint_descriptor { uint32 flags; - addr_t tailp; // Queue tail pointer - addr_t headp; // Queue head pointer - addr_t next_endpoint; // Next endpoint in the list + uint32 tail_pointer; // Queue tail pointer + uint32 head_pointer; // Queue head pointer + uint32 next_endpoint; // Next endpoint in the list }; -#define OHCI_ENDPOINT_GET_FA(s) ((s) & 0x7f) -#define OHCI_ENDPOINT_ADDRMASK 0x0000007f -#define OHCI_ENDPOINT_SET_FA(s) (s) -#define OHCI_ENDPOINT_GET_EN(s) (((s) >> 7) & 0xf) -#define OHCI_ENDPOINT_SET_EN(s) ((s) << 7) -#define OHCI_ENDPOINT_DIR_MASK 0x00001800 -#define OHCI_ENDPOINT_DIR_TD 0x00000000 -#define OHCI_ENDPOINT_DIR_OUT 0x00000800 -#define OHCI_ENDPOINT_DIR_IN 0x00001000 -#define OHCI_ENDPOINT_SPEED 0x00002000 -#define OHCI_ENDPOINT_SKIP 0x00004000 -#define OHCI_ENDPOINT_FORMAT_GEN 0x00000000 -#define OHCI_ENDPOINT_FORMAT_ISO 0x00008000 -#define OHCI_ENDPOINT_GET_MAXP(s) (((s) >> 16) & 0x07ff) -#define OHCI_ENDPOINT_SET_MAXP(s) ((s) << 16) -#define OHCI_ENDPOINT_MAXPMASK (0x7ff << 16) +#define OHCI_ENDPOINT_ADDRESS_MASK 0x0000007f +#define OHCI_ENDPOINT_GET_DEVICE_ADDRESS(s) ((s) & 0x7f) +#define OHCI_ENDPOINT_SET_DEVICE_ADDRESS(s) (s) +#define OHCI_ENDPOINT_GET_ENDPOINT_NUMBER(s) (((s) >> 7) & 0xf) +#define OHCI_ENDPOINT_SET_ENDPOINT_NUMBER(s) ((s) << 7) +#define OHCI_ENDPOINT_DIRECTION_MASK 0x00001800 +#define OHCI_ENDPOINT_DIRECTION_DESCRIPTOR 0x00000000 +#define OHCI_ENDPOINT_DIRECTION_OUT 0x00000800 +#define OHCI_ENDPOINT_DIRECTION_IN 0x00001000 +#define OHCI_ENDPOINT_SPEED 0x00002000 +#define OHCI_ENDPOINT_SKIP 0x00004000 +#define OHCI_ENDPOINT_GENERAL_FORMAT 0x00000000 +#define OHCI_ENDPOINT_ISOCHRONOUS_FORMAT 0x00008000 +#define OHCI_ENDPOINT_MAX_PACKET_SIZE_MASK (0x7ff << 16) +#define OHCI_ENDPOINT_GET_MAX_PACKET_SIZE(s) (((s) >> 16) & 0x07ff) +#define OHCI_ENDPOINT_SET_MAX_PACKET_SIZE(s) ((s) << 16) +#define OHCI_ENDPOINT_HALTED 0x00000001 +#define OHCI_ENDPOINT_TOGGLE_CARRY 0x00000002 +#define OHCI_ENDPOINT_HEAD_MASK 0xfffffffc -#define OHCI_HALTED 0x00000001 -#define OHCI_TOGGLECARRY 0x00000002 -#define OHCI_HEADMASK 0xfffffffc - // -------------------------------- // General transfer descriptor structure (section 4.3.1) // -------------------------------- -typedef struct ohci_transfer_descriptor +typedef struct ohci_general_transfer_descriptor { uint32 flags; - addr_t td_cbp; // Current Buffer Pointer - addr_t td_nexttd; // Next Transfer Descriptor - addr_t td_be; // Buffer End -} ; + uint32 buffer_phy; // Physical buffer pointer + uint32 next_descriptor; // Next transfer descriptor + uint32 last_byte_address; // Physical buffer end +}; -#define OHCI_TD_R 0x00040000 // Buffer Rounding -#define OHCI_TD_DP_MASK 0x00180000 // Direction / PID -#define OHCI_TD_SETUP 0x00000000 -#define OHCI_TD_OUT 0x00080000 -#define OHCI_TD_IN 0x00100000 -#define OHCI_TD_GET_DI(x) (((x) >> 21) & 7) // Delay Interrupt -#define OHCI_TD_SET_DI(x) ((x) << 21) -#define OHCI_TD_NOINTR 0x00e00000 -#define OHCI_TD_INTR_MASK 0x00e00000 -#define OHCI_TD_TOGGLE_CARRY 0x00000000 -#define OHCI_TD_TOGGLE_0 0x02000000 -#define OHCI_TD_TOGGLE_1 0x03000000 -#define OHCI_TD_TOGGLE_MASK 0x03000000 -#define OHCI_TD_GET_EC(x) (((x) >> 26) & 3) // Error Count -#define OHCI_TD_GET_CC(x) ((x) >> 28) // Condition Code -#define OHCI_TD_NOCC 0xf0000000 +#define OHCI_BUFFER_ROUNDING 0x00040000 // Buffer Rounding +#define OHCI_TD_DIRECTION_PID_MASK 0x00180000 // Direction / PID +#define OHCI_TD_DIRECTION_PID_SETUP 0x00000000 +#define OHCI_TD_DIRECTION_PID_OUT 0x00080000 +#define OHCI_TD_DIRECTION_PID_IN 0x00100000 +#define OHCI_TD_GET_DELAY_INTERRUPT(x) (((x) >> 21) & 7) // Delay Interrupt +#define OHCI_TD_SET_DELAY_INTERRUPT(x) ((x) << 21) +#define OHCI_TD_NO_INTERRUPT 0x00e00000 +#define OHCI_TD_INTERRUPT_MASK 0x00e00000 +#define OHCI_TD_TOGGLE_CARRY 0x00000000 +#define OHCI_TD_TOGGLE_0 0x02000000 +#define OHCI_TD_TOGGLE_1 0x03000000 +#define OHCI_TD_TOGGLE_MASK 0x03000000 +#define OHCI_TD_GET_ERROR_COUNT(x) (((x) >> 26) & 3) // Error Count +#define OHCI_TD_GET_CONDITION_CODE(x) ((x) >> 28) // Condition Code +#define OHCI_TD_NO_CONDITION_CODE 0xf0000000 -#define OHCI_TD_ALIGN 16 +#define OHCI_GENERAL_TD_ALIGN 16 // -------------------------------- // Isonchronous transfer descriptor structure (section 4.3.2) // -------------------------------- #define OHCI_ITD_NOFFSET 8 -typedef struct hc_itransfer_descriptor +typedef struct ohci_isochronous_transfer_descriptor { - uint32 itd_flags; - addr_t itd_bp0; // Buffer Page 0 - addr_t itd_nextitd; // Next Isochronous Transfer Descriptor - addr_t itd_be; // Buffer End - uint16 itd_offset[OHCI_ITD_NOFFSET]; // Buffer offsets - + uint32 flags; + uint32 buffer_page_byte_0; // Physical page number of byte 0 + uint32 next_descriptor; // Next isochronous transfer descriptor + uint32 last_byte_address; // Physical buffer end + uint16 offset[OHCI_ITD_NOFFSET]; // Buffer offsets }; -#define OHCI_ITD_GET_SF(x) ((x) & 0x0000ffff) -#define OHCI_ITD_SET_SF(x) ((x) & 0xffff) -#define OHCI_ITD_GET_DI(x) (((x) >> 21) & 7) // Delay Interrupt -#define OHCI_ITD_SET_DI(x) ((x) << 21) -#define OHCI_ITD_NOINTR 0x00e00000 -#define OHCI_ITD_GET_FC(x) ((((x) >> 24) & 7)+1) // Frame Count -#define OHCI_ITD_SET_FC(x) (((x)-1) << 24) -#define OHCI_ITD_GET_CC(x) ((x) >> 28) // Condition Code -#define OHCI_ITD_NOCC 0xf0000000 +#define OHCI_ITD_GET_STARTING_FRAME(x) ((x) & 0x0000ffff) +#define OHCI_ITD_SET_STARTING_FRAME(x) ((x) & 0xffff) +#define OHCI_ITD_GET_DELAY_INTERRUPT(x) (((x) >> 21) & 7) +#define OHCI_ITD_SET_DELAY_INTERRUPT(x) ((x) << 21) +#define OHCI_ITD_NO_INTERRUPT 0x00e00000 +#define OHCI_ITD_GET_FRAME_COUNT(x) ((((x) >> 24) & 7) + 1) +#define OHCI_ITD_SET_FRAME_COUNT(x) (((x) - 1) << 24) +#define OHCI_ITD_GET_CONDITION_CODE(x) ((x) >> 28) +#define OHCI_ITD_NO_CONDITION_CODE 0xf0000000 -#define itd_pswn itd_offset // Packet Status Word -#define OHCI_ITD_PAGE_SELECT 0x00001000 -#define OHCI_ITD_MK_OFFS(len) (0xe000 | ((len) & 0x1fff)) -#define OHCI_ITD_PSW_LENGTH(x) ((x) & 0xfff) // Transfer length -#define OHCI_ITD_PSW_GET_CC(x) ((x) >> 12) // Condition Code +// TO FIX +#define itd_pswn itd_offset // Packet Status Word +#define OHCI_ITD_PAGE_SELECT 0x00001000 +#define OHCI_ITD_MK_OFFS(len) (0xe000 | ((len) & 0x1fff)) +#define OHCI_ITD_GET_BUFFER_LENGTH(x) ((x) & 0xfff) // Transfer length +#define OHCI_ITD_GET_BUFFER_CONDITION_CODE(x) ((x) >> 12) // Condition Code -#define OHCI_ITD_ALIGN 32 +#define OHCI_ISOCHRONOUS_TD_ALIGN 32 // -------------------------------- // Completion Codes (section 4.3.3) // -------------------------------- -#define OHCI_CC_NO_ERROR 0 -#define OHCI_CC_CRC 1 -#define OHCI_CC_BIT_STUFFING 2 -#define OHCI_CC_DATA_TOGGLE_MISMATCH 3 -#define OHCI_CC_STALL 4 -#define OHCI_CC_DEVICE_NOT_RESPONDING 5 -#define OHCI_CC_PID_CHECK_FAILURE 6 -#define OHCI_CC_UNEXPECTED_PID 7 -#define OHCI_CC_DATA_OVERRUN 8 -#define OHCI_CC_DATA_UNDERRUN 9 -#define OHCI_CC_BUFFER_OVERRUN 12 -#define OHCI_CC_BUFFER_UNDERRUN 13 -#define OHCI_CC_NOT_ACCESSED 15 +#define OHCI_NO_ERROR 0 +#define OHCI_CRC 1 +#define OHCI_BIT_STUFFING 2 +#define OHCI_DATA_TOGGLE_MISMATCH 3 +#define OHCI_STALL 4 +#define OHCI_DEVICE_NOT_RESPONDING 5 +#define OHCI_PID_CHECK_FAILURE 6 +#define OHCI_UNEXPECTED_PID 7 +#define OHCI_DATA_OVERRUN 8 +#define OHCI_DATA_UNDERRUN 9 +#define OHCI_BUFFER_OVERRUN 12 +#define OHCI_BUFFER_UNDERRUN 13 +#define OHCI_NOT_ACCESSED 15 // -------------------------------- // Some delay needed when changing From julun at mail.berlios.de Sat Oct 13 00:42:53 2007 From: julun at mail.berlios.de (julun at BerliOS) Date: Sat, 13 Oct 2007 00:42:53 +0200 Subject: [Haiku-commits] r22523 - haiku/trunk/src/kits/interface Message-ID: <200710122242.l9CMgrRw007102@sheep.berlios.de> Author: julun Date: 2007-10-13 00:42:51 +0200 (Sat, 13 Oct 2007) New Revision: 22523 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22523&view=rev Modified: haiku/trunk/src/kits/interface/TextControl.cpp Log: * the divider width was taken from the wrong archive field - this is my first commit, so i'm really looking forward to work with you guys :) Modified: haiku/trunk/src/kits/interface/TextControl.cpp =================================================================== --- haiku/trunk/src/kits/interface/TextControl.cpp 2007-10-12 22:17:27 UTC (rev 22522) +++ haiku/trunk/src/kits/interface/TextControl.cpp 2007-10-12 22:42:51 UTC (rev 22523) @@ -126,7 +126,7 @@ SetAlignment((alignment)labelAlignment, (alignment)textAlignment); if (archive->HasFloat("_divide")) - archive->FindFloat("_a_text", &fDivider); + archive->FindFloat("_divide", &fDivider); if (archive->HasMessage("_mod_msg")) { BMessage* message = new BMessage; From julun at mail.berlios.de Sat Oct 13 00:47:43 2007 From: julun at mail.berlios.de (julun at BerliOS) Date: Sat, 13 Oct 2007 00:47:43 +0200 Subject: [Haiku-commits] r22524 - haiku/trunk/headers/private/storage Message-ID: <200710122247.l9CMlhkV012430@sheep.berlios.de> Author: julun Date: 2007-10-13 00:47:42 +0200 (Sat, 13 Oct 2007) New Revision: 22524 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22524&view=rev Modified: haiku/trunk/headers/private/storage/Partition.h Log: * this should fix the build on gcc4 Modified: haiku/trunk/headers/private/storage/Partition.h =================================================================== --- haiku/trunk/headers/private/storage/Partition.h 2007-10-12 22:42:51 UTC (rev 22523) +++ haiku/trunk/headers/private/storage/Partition.h 2007-10-12 22:47:42 UTC (rev 22524) @@ -16,6 +16,7 @@ class BDiskDeviceParameterEditor; class BDiskDeviceVisitor; class BDiskSystem; +class BMutablePartition; class BPartitioningInfo; class BPath; class BVolume; @@ -170,6 +171,7 @@ friend class BDiskDevice; friend class BDiskSystem; + friend class BMutablePartition; BDiskDevice *fDevice; BPartition *fParent; From marcusoverhagen at arcor.de Sat Oct 13 00:59:03 2007 From: marcusoverhagen at arcor.de (Marcus Overhagen) Date: Sat, 13 Oct 2007 00:59:03 +0200 (CEST) Subject: [Haiku-commits] r22522 - haiku/trunk/src/add-ons/kernel/busses/usb In-Reply-To: <200710122217.l9CMHSn5008173@sheep.berlios.de> References: <200710122217.l9CMHSn5008173@sheep.berlios.de> Message-ID: <12197868.1192229943984.JavaMail.ngmail@webmail16> sbenedetto at BerliOS wrote: > * Clean up (removing unneeded comment) > -// Copyright (c) 2005, Jan-Rixt Van Hoye > -// > -// The above copyright notice and this permission notice shall be included in > -// all copies or substantial portions of the Software. > + * Copyright 2005-2008, Haiku Inc. All rights reserved. > + * Distributed under the terms of the MIT License. > + * > + * Authors: > + * Jan-Rixt Van Hoye > + * Salvatore Benedetto > + */ This change is not allowed. Please revert it. The original copyright notice and permission notice must be preserved unmodified. Marcus Viel oder wenig? Schnell oder langsam? Unbegrenzt surfen + telefonieren ohne Zeit- und Volumenbegrenzung? DAS TOP ANGEBOT F?R ALLE NEUEINSTEIGER Jetzt bei Arcor: g?nstig und schnell mit DSL - das All-Inclusive-Paket f?r clevere Doppel-Sparer, nur 34,95 ? inkl. DSL- und ISDN-Grundgeb?hr! http://www.arcor.de/rd/emf-dsl-2 From leavengood at mail.berlios.de Sat Oct 13 06:46:35 2007 From: leavengood at mail.berlios.de (leavengood at BerliOS) Date: Sat, 13 Oct 2007 06:46:35 +0200 Subject: [Haiku-commits] r22525 - in haiku/trunk/src/apps: . packageinstaller Message-ID: <200710130446.l9D4kZ69001370@sheep.berlios.de> Author: leavengood Date: 2007-10-13 06:46:32 +0200 (Sat, 13 Oct 2007) New Revision: 22525 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22525&view=rev Added: haiku/trunk/src/apps/packageinstaller/ haiku/trunk/src/apps/packageinstaller/InstalledPackageInfo.cpp haiku/trunk/src/apps/packageinstaller/InstalledPackageInfo.h haiku/trunk/src/apps/packageinstaller/Jamfile haiku/trunk/src/apps/packageinstaller/PackageImageViewer.cpp haiku/trunk/src/apps/packageinstaller/PackageImageViewer.h haiku/trunk/src/apps/packageinstaller/PackageInfo.cpp haiku/trunk/src/apps/packageinstaller/PackageInfo.h haiku/trunk/src/apps/packageinstaller/PackageInstaller.rdef haiku/trunk/src/apps/packageinstaller/PackageItem.cpp haiku/trunk/src/apps/packageinstaller/PackageItem.h haiku/trunk/src/apps/packageinstaller/PackageStatus.cpp haiku/trunk/src/apps/packageinstaller/PackageStatus.h haiku/trunk/src/apps/packageinstaller/PackageTextViewer.cpp haiku/trunk/src/apps/packageinstaller/PackageTextViewer.h haiku/trunk/src/apps/packageinstaller/PackageView.cpp haiku/trunk/src/apps/packageinstaller/PackageView.h haiku/trunk/src/apps/packageinstaller/PackageWindow.cpp haiku/trunk/src/apps/packageinstaller/PackageWindow.h haiku/trunk/src/apps/packageinstaller/main.cpp Modified: haiku/trunk/src/apps/Jamfile Log: Adding ?\197?\129ukasz Zemczak's package installer to our tree. This was his Google Summer of Code project. Thanks for your work ?\197?\129ukasz and I hope we can see more work from you. Still to do: - Create an icon. - Add pkg files to the MIME database with PackageInstaller as the default handler. The rdef here has the MIME type name for the pkg format should anyone else choose to add it :) - Support for running scripts included with packages. - Testing various different packages. - Fixing problems in the Haiku GUI layout system which affect the code used for various parts of the installer GUI (please bear with the commented out code for now.) - Adding this to the image. Tomorrow I will add ?\197?\129ukasz's InstalledPackages utility which can be used to view installed packages and uninstall them. Modified: haiku/trunk/src/apps/Jamfile =================================================================== --- haiku/trunk/src/apps/Jamfile 2007-10-12 22:47:42 UTC (rev 22524) +++ haiku/trunk/src/apps/Jamfile 2007-10-13 04:46:32 UTC (rev 22525) @@ -12,6 +12,7 @@ SubInclude HAIKU_TOP src apps fontdemo ; SubInclude HAIKU_TOP src apps glteapot ; SubInclude HAIKU_TOP src apps icon-o-matic ; +SubInclude HAIKU_TOP src apps installedpackages ; SubInclude HAIKU_TOP src apps installer ; SubInclude HAIKU_TOP src apps launchbox ; SubInclude HAIKU_TOP src apps magnify ; @@ -21,6 +22,7 @@ SubInclude HAIKU_TOP src apps mediaplayer ; SubInclude HAIKU_TOP src apps midiplayer ; SubInclude HAIKU_TOP src apps networkstatus ; +SubInclude HAIKU_TOP src apps packageinstaller ; SubInclude HAIKU_TOP src apps people ; SubInclude HAIKU_TOP src apps poorman ; SubInclude HAIKU_TOP src apps powerstatus ; @@ -35,3 +37,5 @@ SubInclude HAIKU_TOP src apps tracker ; SubInclude HAIKU_TOP src apps tv ; SubInclude HAIKU_TOP src apps workspaces ; + +SubInclude HAIKU_TOP src apps test_app ; Added: haiku/trunk/src/apps/packageinstaller/InstalledPackageInfo.cpp =================================================================== --- haiku/trunk/src/apps/packageinstaller/InstalledPackageInfo.cpp 2007-10-12 22:47:42 UTC (rev 22524) +++ haiku/trunk/src/apps/packageinstaller/InstalledPackageInfo.cpp 2007-10-13 04:46:32 UTC (rev 22525) @@ -0,0 +1,331 @@ +/* + * Copyright (c) 2007, Haiku, Inc. + * Distributed under the terms of the MIT license. + * + * Author: + * ?ukasz 'Sil2100' Zemczak + */ + + +#include "InstalledPackageInfo.h" +#include +#include +#include +#include +#include +#include + + +const char * kPackagesDir = "packages"; + + +static status_t +info_prepare(const char *filename, BFile *file, BMessage *info) +{ + if (!filename) + return B_ERROR; + + BPath path; + if (find_directory(B_USER_CONFIG_DIRECTORY, &path) != B_OK + || path.Append(kPackagesDir) != B_OK + || path.Append(filename) != B_OK) + return B_ERROR; + + file->SetTo(path.Path(), B_READ_ONLY); + if (file->InitCheck() != B_OK) + return B_ERROR; + + status_t ret = info->Unflatten(file); + if (ret != B_OK || info->what != P_PACKAGE_INFO) + return B_ERROR; + + return B_OK; +} + + +const char * +info_get_package_name(const char *filename) +{ + BFile file; + BMessage info; + if (info_prepare(filename, &file, &info) != B_OK) + return NULL; + BString name; + info.FindString("package_name", &name); + return name.String(); +} + + +const char * +info_get_package_version(const char *filename) +{ + BFile file; + BMessage info; + if (info_prepare(filename, &file, &info) != B_OK) + return NULL; + BString version; + info.FindString("package_version", &version); + return version.String(); +} + + +InstalledPackageInfo::InstalledPackageInfo() + : + fStatus(B_NO_INIT), + fIsUpToDate(false), + fCreate(false), + fInstalledItems(10) +{ +} + + +InstalledPackageInfo::InstalledPackageInfo(const char *packageName, + const char *version, bool create) + : + fStatus(B_NO_INIT), + fIsUpToDate(false), + fInstalledItems(10) +{ + SetTo(packageName, version, create); +} + + +InstalledPackageInfo::~InstalledPackageInfo() +{ + _ClearItemList(); +} + + +status_t +InstalledPackageInfo::InitCheck() +{ + return fStatus; +} + + +status_t +InstalledPackageInfo::SetTo(const char *packageName, const char *version, + bool create) +{ + _ClearItemList(); + fCreate = create; + fStatus = B_NO_INIT; + fVersion = version; + + if (!packageName) + return fStatus; + + BPath configPath; + if (find_directory(B_USER_CONFIG_DIRECTORY, &configPath) != B_OK) { + fStatus = B_ERROR; + return fStatus; + } + + if (fPathToInfo.SetTo(configPath.Path(), kPackagesDir) != B_OK) { + fStatus = B_ERROR; + return fStatus; + } + + // Check whether the directory exists + BDirectory packageDir(fPathToInfo.Path()); + fStatus = packageDir.InitCheck(); + if (fStatus == B_ENTRY_NOT_FOUND) { + // If not, create it + packageDir.SetTo(configPath.Path()); + if (packageDir.CreateDirectory(kPackagesDir, &packageDir) != B_OK) { + fStatus = B_ERROR; + return fStatus; + } + } + + BString filename = packageName; + filename << version << ".pdb"; + if (fPathToInfo.Append(filename.String()) != B_OK) { + fStatus = B_ERROR; + return fStatus; + } + + BFile package(fPathToInfo.Path(), B_READ_ONLY); + fStatus = package.InitCheck(); + if (fStatus == B_OK) { + // The given package exists, so we can unflatten the data to a message + // and then pass it further + BMessage info; + if (info.Unflatten(&package) != B_OK || info.what != P_PACKAGE_INFO) { + fStatus = B_ERROR; + return fStatus; + } + + int32 count; + fStatus = info.FindString("package_name", &fName); + fStatus |= info.FindString("package_desc", &fDescription); + fStatus |= info.FindString("package_version", &fVersion); + int64 spaceNeeded = 0; + fStatus |= info.FindInt64("package_size", &spaceNeeded); + fSpaceNeeded = static_cast(spaceNeeded); + fStatus |= info.FindInt32("file_count", &count); + if (fStatus != B_OK) { + fStatus = B_ERROR; + return fStatus; + } + + int32 i; + BString itemPath; + for (i = 0; i < count; i++) { + if (info.FindString("items", i, &itemPath) != B_OK) { + fStatus = B_ERROR; + return fStatus; + } + fInstalledItems.AddItem(new BString(itemPath)); // Or maybe BPath better? + } + fIsUpToDate = true; + } + else if (fStatus == B_ENTRY_NOT_FOUND) { + if (create) { + fStatus = B_OK; + fIsUpToDate = false; + } + } + + return fStatus; +} + + +status_t +InstalledPackageInfo::AddItem(const char *itemName) +{ + if (!itemName) + return B_ERROR; + + return fInstalledItems.AddItem(new BString(itemName)); +} + + +status_t +InstalledPackageInfo::Uninstall() +{ + if (fStatus != B_OK) + return fStatus; + + BString *iter; + uint32 i, count = fInstalledItems.CountItems(); + BEntry entry; + status_t ret; + + // Try to remove all entries that are present in the list + for (i = 0; i < count; i++) { + iter = static_cast(fInstalledItems.ItemAt(count - i - 1)); + fprintf(stderr, "Removing: %s (%d/%d)\n", iter->String(), i, count); + ret = entry.SetTo(iter->String()); + if (ret == B_BUSY) { + // The entry's directory is locked - wait a few cycles for it to + // unlock itself + int32 tries = 0; + for (tries = 0; tries < P_BUSY_TRIES; tries++) { + ret = entry.SetTo(iter->String()); + if (ret != B_BUSY) + break; + // Wait a moment + usleep(1000); + } + } + + if (ret == B_ENTRY_NOT_FOUND) + continue; + else if (ret != B_OK) { + fStatus = B_ERROR; + return fStatus; + } + + fprintf(stderr, "...we continue\n"); + + if (entry.Exists() && entry.Remove() != B_OK) { + fprintf(stderr, "\n%s\n", strerror(ret)); + fStatus = B_ERROR; + return fStatus; + } + fInstalledItems.RemoveItem(count - i - 1); + } + + if (entry.SetTo(fPathToInfo.Path()) != B_OK) { + fStatus = B_ERROR; + return fStatus; + } + if (entry.Exists() && entry.Remove() != B_OK) { + fStatus = B_ERROR; + return fStatus; + } + + return fStatus; +} + + +status_t +InstalledPackageInfo::Save() +{ + // If the package info is not up to date and everything till now was + // done correctly, we will save all data as a flattened BMessage to the + // package info file + if (fIsUpToDate || fStatus != B_OK) + return fStatus; + + BFile package; + if (fCreate) { + fStatus = package.SetTo(fPathToInfo.Path(), B_WRITE_ONLY | B_CREATE_FILE + | B_ERASE_FILE); + } + else { + fStatus = package.SetTo(fPathToInfo.Path(), B_WRITE_ONLY | B_ERASE_FILE); + } + + if (fStatus != B_OK) + return fStatus; + + status_t ret; + int32 i, count = fInstalledItems.CountItems(); + BMessage info(P_PACKAGE_INFO); + ret = info.AddString("package_name", fName); + ret |= info.AddString("package_desc", fDescription); + ret |= info.AddString("package_version", fVersion); + ret |= info.AddInt64("package_size", fSpaceNeeded); + ret |= info.AddInt32("file_count", count); + if (ret != B_OK) { + fStatus = B_ERROR; + return fStatus; + } + + BString *iter; + for (i = 0; i < count; i++) { + iter = static_cast(fInstalledItems.ItemAt(i)); + if (info.AddString("items", *iter) != B_OK) { + fStatus = B_ERROR; + return fStatus; + } + } + + if (info.Flatten(&package) != B_OK) { + fStatus = B_ERROR; + return fStatus; + } + fIsUpToDate = true; + + return fStatus; +} + + +// #pragma mark - + + +void +InstalledPackageInfo::_ClearItemList() +{ + // Clear the items list + BString *iter; + uint32 i, count = fInstalledItems.CountItems(); + for (i = 0; i < count; i++) { + iter = static_cast(fInstalledItems.ItemAt(0)); + fInstalledItems.RemoveItem((int32)0); + delete iter; + } +} + Added: haiku/trunk/src/apps/packageinstaller/InstalledPackageInfo.h =================================================================== --- haiku/trunk/src/apps/packageinstaller/InstalledPackageInfo.h 2007-10-12 22:47:42 UTC (rev 22524) +++ haiku/trunk/src/apps/packageinstaller/InstalledPackageInfo.h 2007-10-13 04:46:32 UTC (rev 22525) @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2007, Haiku, Inc. + * Distributed under the terms of the MIT license. + * + * Author: + * ?ukasz 'Sil2100' Zemczak + */ +#ifndef INSTALLEDPACKAGEINFO_H +#define INSTALLEDPACKAGEINFO_H + +#include +#include +#include +#include + + +#define P_BUSY_TRIES 10 + +enum { + P_PACKAGE_INFO = 'ppki' +}; + +extern const char * kPackagesDir; + + +// Useful function for fetching the package name and version without parsing all +// other data +const char * info_get_package_name(const char *filename); +const char * info_get_package_version(const char *filename); + + +class InstalledPackageInfo { + public: + InstalledPackageInfo(); + InstalledPackageInfo(const char *packageName, const char *version = NULL, + bool create = false); + ~InstalledPackageInfo(); + + status_t InitCheck(); + status_t SetTo(const char *packageName, const char *version = NULL, + bool create = false); + + void SetName(const char *name) { fName = name; } + const char *GetName() { return fName.String(); } + void SetDescription(const char *description) { fDescription = description; } + const char *GetDescription() { return fDescription.String(); } + //void SetVersion(const char *version) { fVersion = version; } + const char *GetVersion() { return fVersion.String(); } + void SetSpaceNeeded(uint64 size) { fSpaceNeeded = size; } + uint64 GetSpaceNeeded() { return fSpaceNeeded; } + + status_t AddItem(const char *itemName); + + status_t Uninstall(); + status_t Save(); + + private: + void _ClearItemList(); + + status_t fStatus; + bool fIsUpToDate; + bool fCreate; + + BString fName; + BString fDescription; + BString fVersion; + uint64 fSpaceNeeded; + BList fInstalledItems; + + BPath fPathToInfo; +}; + + +#endif + Added: haiku/trunk/src/apps/packageinstaller/Jamfile =================================================================== --- haiku/trunk/src/apps/packageinstaller/Jamfile 2007-10-12 22:47:42 UTC (rev 22524) +++ haiku/trunk/src/apps/packageinstaller/Jamfile 2007-10-13 04:46:32 UTC (rev 22525) @@ -0,0 +1,21 @@ +SubDir HAIKU_TOP src apps packageinstaller ; + +UsePrivateHeaders shared interface ; +SubDirHdrs $(HAIKU_TOP) headers libs zlib ; + +#SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits interface ] ; + +Application PackageInstaller : + main.cpp + PackageWindow.cpp + PackageView.cpp + PackageInfo.cpp + PackageItem.cpp + PackageStatus.cpp + PackageTextViewer.cpp + PackageImageViewer.cpp + InstalledPackageInfo.cpp + : be tracker translation z + : PackageInstaller.rdef +; + Added: haiku/trunk/src/apps/packageinstaller/PackageImageViewer.cpp =================================================================== --- haiku/trunk/src/apps/packageinstaller/PackageImageViewer.cpp 2007-10-12 22:47:42 UTC (rev 22524) +++ haiku/trunk/src/apps/packageinstaller/PackageImageViewer.cpp 2007-10-13 04:46:32 UTC (rev 22525) @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2007, Haiku, Inc. + * Distributed under the terms of the MIT license. + * + * Author: + * ?ukasz 'Sil2100' Zemczak + */ + + +#include "PackageImageViewer.h" + +#include +#include +#include +#include + + +// Reserved +#define T(x) x + + +enum { + P_MSG_CLOSE = 'pmic' +}; + + + +ImageView::ImageView(BPositionIO *image) + : BView(BRect(0, 0, 1, 1), "image_view", B_FOLLOW_NONE, B_WILL_DRAW), + fSuccess(true) +{ + if (!image) { + fSuccess = false; + return; + } + // Initialize and translate the image + BTranslatorRoster *roster = BTranslatorRoster::Default(); + BBitmapStream stream; + if (roster->Translate(image, NULL, NULL, &stream, B_TRANSLATOR_BITMAP) + < B_OK) { + fSuccess = false; + return; + } + stream.DetachBitmap(&fImage); +} + + +ImageView::~ImageView() +{ +} + + +void +ImageView::AttachedToWindow() +{ + if (!fSuccess) { + ResizeTo(75, 75); + return; + } + + // We need to resize the view depending on what size has the screen and + // the image we will be viewing + BScreen screen(Window()); + BRect frame = screen.Frame(); + BRect image = fImage->Bounds(); + + if (image.Width() > (frame.Width() - 100.0f)) { + image.right = frame.Width() - 100.0f; + } + if (image.Height() > (frame.Height() - 100.0f)) { + image.bottom = frame.Height() - 100.f; + } + + ResizeTo(image.Width(), image.Height()); +} + + +void +ImageView::Draw(BRect updateRect) +{ + if (fSuccess) + DrawBitmapAsync(fImage, Bounds()); + else { + float length = StringWidth(T("Image not loaded correctly")); + DrawString(T("Image not loaded correctly"), + BPoint((Bounds().Width() - length) / 2.0f, 30.0f)); + } +} + + +void +ImageView::MouseUp(BPoint point) +{ + BWindow *parent = Window(); + if (parent) + parent->PostMessage(P_MSG_CLOSE); +} + + +// #pragma mark - + + +PackageImageViewer::PackageImageViewer(BPositionIO *image) + : BWindow(BRect(100, 100, 100, 100), "", B_MODAL_WINDOW, + B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_NOT_CLOSABLE) +{ + fBackground = new ImageView(image); + AddChild(fBackground); + + ResizeTo(fBackground->Bounds().Width(), fBackground->Bounds().Height()); + + BScreen screen(this); + BRect frame = screen.Frame(); + MoveTo((frame.Width() - Bounds().Width()) / 2.0f, + (frame.Height() - Bounds().Height()) / 2.0f); +} + + +PackageImageViewer::~PackageImageViewer() +{ +} + + +void +PackageImageViewer::Go() +{ + // Since this class can be thought of as a modified BAlert window, no use + // to reinvent a well fledged wheel. This concept has been borrowed from + // the current BAlert implementation + fSemaphore = create_sem(0, "ImageViewer"); + if (fSemaphore < B_OK) { + Quit(); + return; + } + + BWindow *parent = + dynamic_cast(BLooper::LooperForThread(find_thread(NULL))); + Show(); + + if (parent) { + status_t ret; + for (;;) { + do { + ret = acquire_sem_etc(fSemaphore, 1, B_RELATIVE_TIMEOUT, 50000); + } while (ret == B_INTERRUPTED); + + if (ret == B_BAD_SEM_ID) + break; + parent->UpdateIfNeeded(); + } + } + else { + // Since there are no spinlocks, wait until the semaphore is free + while (acquire_sem(fSemaphore) == B_INTERRUPTED) { + } + } + + if (Lock()) + Quit(); +} + + +void +PackageImageViewer::MessageReceived(BMessage *msg) +{ + if (msg->what == P_MSG_CLOSE) { + if (fSemaphore >= B_OK) { + delete_sem(fSemaphore); + fSemaphore = -1; + } + } + else + BWindow::MessageReceived(msg); +} + Added: haiku/trunk/src/apps/packageinstaller/PackageImageViewer.h =================================================================== --- haiku/trunk/src/apps/packageinstaller/PackageImageViewer.h 2007-10-12 22:47:42 UTC (rev 22524) +++ haiku/trunk/src/apps/packageinstaller/PackageImageViewer.h 2007-10-13 04:46:32 UTC (rev 22525) @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2007, Haiku, Inc. + * Distributed under the terms of the MIT license. + * + * Author: + * ?ukasz 'Sil2100' Zemczak + */ +#ifndef PACKAGEIMAGEVIEWER_H +#define PACKAGEIMAGEVIEWER_H + +#include +#include +#include +#include + + + +class ImageView : public BView { + public: + ImageView(BPositionIO *image); + ~ImageView(); + + void AttachedToWindow(); + void Draw(BRect updateRect); + void MouseUp(BPoint point); + + private: + BBitmap *fImage; + bool fSuccess; +}; + + +class PackageImageViewer : public BWindow { + public: + PackageImageViewer(BPositionIO *image); + ~PackageImageViewer(); + + void Go(); + + void MessageReceived(BMessage *msg); + + private: + ImageView *fBackground; + + sem_id fSemaphore; +}; + + +#endif + Added: haiku/trunk/src/apps/packageinstaller/PackageInfo.cpp =================================================================== --- haiku/trunk/src/apps/packageinstaller/PackageInfo.cpp 2007-10-12 22:47:42 UTC (rev 22524) +++ haiku/trunk/src/apps/packageinstaller/PackageInfo.cpp 2007-10-13 04:46:32 UTC (rev 22525) @@ -0,0 +1,1131 @@ +/* + * Copyright (c) 2007, Haiku, Inc. + * Distributed under the terms of the MIT license. + * + * Author: + * ?ukasz 'Sil2100' Zemczak + */ + + +#include "PackageInfo.h" + +#include +#include +#include +#include +#include + + +// Macro reserved for later localization +#define T(x) x + +const uint32 kSkipOffset = 33; + +// Section constants +enum { + P_GROUPS_SECTION = 0, + P_PATH_SECTION, + P_USER_PATH_SECTION, + P_LICENSE_SECTION +}; + + +// Element constants +enum { + P_NONE = 0, + P_FILE, + P_DIRECTORY, + P_LINK +}; + + +PackageInfo::PackageInfo() + : + fStatus(B_NO_INIT), + fPackageFile(0), + fDescription(T("No package available.")), + fProfiles(2), + fHasImage(false) +{ +} + + +PackageInfo::PackageInfo(const entry_ref *ref) + : + fStatus(B_NO_INIT), + fPackageFile(new BFile(ref, B_READ_ONLY)), + fDescription(T("No package selected.")), + fProfiles(2), + fHasImage(false) +{ + fStatus = Parse(); +} + + +PackageInfo::~PackageInfo() +{ + pkg_profile *iter = 0; + while (1) { + iter = static_cast(fProfiles.RemoveItem((long int)0)); + if (iter) + delete iter; + else + break; + } + + PkgItem *file = 0; + while (1) { + file = static_cast(fFiles.RemoveItem((long int)0)); + if (file) + delete file; + else + break; + } + + if (fPackageFile) + delete fPackageFile; +} + + +status_t +PackageInfo::Parse() +{ + // TODO: Clean up + if (!fPackageFile || fPackageFile->InitCheck() != B_OK) { + fStatus = B_ERROR; + return fStatus; + } + + // Check for the presence of the first AlB tag - as the 'magic number'. + // This also ensures that the file header section is present - which + // is a crucial pkg section + char buffer[16]; + fPackageFile->Read(buffer, 8); + if (buffer[0] != 'A' || buffer[1] != 'l' || buffer[2] != 'B' + || buffer[3] != 0x1a) { + fStatus = B_ERROR; + return fStatus; + } + + fHasImage = false; + + // Parse all known parts of the given .pkg file + + uint32 i; + int8 bytesRead; + off_t actualSize = 0; + fPackageFile->GetSize(&actualSize); + uint64 fileSize = 0; + + const char padding[7] = { 0, 0, 0, 0, 0, 0, 0 }; + + system_info sysinfo; + get_system_info(&sysinfo); + + uint64 infoOffset = 0, groupsOffset = 0; + uint64 length = 0; + + // Parse the file header + while (1) { + bytesRead = fPackageFile->Read(buffer, 7); + if (bytesRead != 7) { + fStatus = B_ERROR; + return fStatus; + } + + if (!memcmp(buffer, "PhIn", 5)) { + } + else if (!memcmp(buffer, "FVer", 5)) { + // Not used right now + fPackageFile->Seek(4, SEEK_CUR); + parser_debug("FVer\n"); + } + else if (!memcmp(buffer, "AFla", 5)) { + // Not used right now TODO: Check what this tag is for + fPackageFile->Seek(8, SEEK_CUR); + parser_debug("AFla\n"); + } + else if (!memcmp(buffer, "FSiz", 5)) { + fPackageFile->Read(&fileSize, 8); + swap_data(B_UINT64_TYPE, &fileSize, sizeof(uint64), + B_SWAP_BENDIAN_TO_HOST); + parser_debug("FSiz %llu\n", fileSize); + } + else if (!memcmp(buffer, "COff", 5)) { + fPackageFile->Read(&infoOffset, 8); + swap_data(B_UINT64_TYPE, &infoOffset, sizeof(uint64), + B_SWAP_BENDIAN_TO_HOST); + parser_debug("COff %llu\n", infoOffset); + } + else if (!memcmp(buffer, "AOff", 5)) { + fPackageFile->Read(&groupsOffset, 8); + swap_data(B_UINT64_TYPE, &groupsOffset, sizeof(uint64), + B_SWAP_BENDIAN_TO_HOST); + parser_debug("AOff %llu\n", groupsOffset); + } + else if (!memcmp(buffer, padding, 7)) { + // This means the end of this section - we should move to the + // groups section. + if (groupsOffset) { + fPackageFile->Seek(groupsOffset, SEEK_SET); + } + parser_debug("End!\n"); + break; + } + else { + fStatus = B_ERROR; + return fStatus; + } + } + + fPackageFile->Read(buffer, 7); + if (memcmp(buffer, "PkgA", 5) || !groupsOffset || !infoOffset) { + fStatus = B_ERROR; + return fStatus; + } + + // Section header identifying constant byte sequences: + const char groupsMarker[7] = { 0, 0, 0, 1, 0, 0, 4 }; + const char idMarker[7] = { 0, 0, 0, 2, 0, 0, 4 }; + const char pathMarker[7] = { 0, 0, 0, 3, 0, 0, 4 }; + const char upathMarker[7] = { 0, 0, 0, 4, 0, 0, 4 }; + const char licenseMarker[7] = { 0, 0, 0, 18, 0, 0, 4 }; + const char descMarker[7] = { 0, 0, 0, 5, 0, 0, 2 }; + const char helpMarker[7] = { 0, 0, 0, 10, 0, 0, 3 }; + + const char splashScreenMarker[7] = { 0, 0, 0, 8, 0, 0, 3 }; + const char disclaimerMarker[7] = { 0, 0, 0, 7, 0, 0, 3 }; + + const char nameMarker[7] = { 0, 0, 0, 13, 0, 0, 2 }; + const char versionMarker[7] = { 0, 0, 0, 14, 0, 0, 2 }; + const char devMarker[7] = { 0, 0, 0, 15, 0, 0, 2 }; + const char shortDescMarker[7] = { 0, 0, 0, 17, 0, 0, 2 }; + + int8 section = P_GROUPS_SECTION, installDirectoryFlag = 0; + + pkg_profile group; + BList groups(3), userPaths(3), systemPaths(10); + bool groupStarted = false; + parser_debug("Package Info reached!\n"); + // TODO: Maybe checking whether the needed number of bytes are read + // everytime would be a good idea + + // Parse the package info section + while (1) { + bytesRead = fPackageFile->Read(buffer, 7); + if (bytesRead != 7) { + parser_debug("EOF!\n"); + break; + } + + if (!memcmp(buffer, groupsMarker, 7)) { + section = P_GROUPS_SECTION; + parser_debug("Got to Groups section\n"); + continue; + } + else if (!memcmp(buffer, pathMarker, 7)) { + section = P_PATH_SECTION; + parser_debug("Got to System Paths\n"); + continue; + } + else if (!memcmp(buffer, upathMarker, 7)) { + section = P_USER_PATH_SECTION; + parser_debug("Got to User Paths\n"); + continue; + } + else if (!memcmp(buffer, licenseMarker, 7)) { + section = P_LICENSE_SECTION; + parser_debug("Got to License\n"); + continue; + } // After this, non sectioned tags follow + else if (!memcmp(buffer, disclaimerMarker, 7)) { + uint64 length; + fPackageFile->Read(&length, 8); + swap_data(B_UINT64_TYPE, &length, sizeof(uint64), B_SWAP_BENDIAN_TO_HOST); + + uint64 original; + if (fPackageFile->Read(&original, 8) != 8) { + fStatus = B_ERROR; + return fStatus; + } + swap_data(B_UINT64_TYPE, &original, sizeof(uint64), B_SWAP_BENDIAN_TO_HOST); + + fPackageFile->Seek(4, SEEK_CUR); + + uint8 *compressed = new uint8[length]; + if (fPackageFile->Read(compressed, length) != static_cast(length)) { + fStatus = B_ERROR; + delete compressed; + return fStatus; + } + + uint8 *disclaimer = new uint8[original + 1]; + status_t ret = inflate_data(compressed, length, disclaimer, original); + disclaimer[original] = 0; + delete compressed; + if (ret != B_OK) { + fStatus = B_ERROR; + delete disclaimer; + return ret; + } + + fDisclaimer = (char *)disclaimer; + delete disclaimer; + + continue; + } + else if (!memcmp(buffer, splashScreenMarker, 7)) { + uint64 length; + fPackageFile->Read(&length, 8); + swap_data(B_UINT64_TYPE, &length, sizeof(uint64), B_SWAP_BENDIAN_TO_HOST); + + uint64 original; + if (fPackageFile->Read(&original, 8) != 8) { + fStatus = B_ERROR; + return fStatus; + } [... truncated: 3242 lines follow ...] From leavengood at mail.berlios.de Sat Oct 13 07:02:10 2007 From: leavengood at mail.berlios.de (leavengood at BerliOS) Date: Sat, 13 Oct 2007 07:02:10 +0200 Subject: [Haiku-commits] r22526 - haiku/trunk/src/apps Message-ID: <200710130502.l9D52AYN010786@sheep.berlios.de> Author: leavengood Date: 2007-10-13 07:02:09 +0200 (Sat, 13 Oct 2007) New Revision: 22526 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22526&view=rev Modified: haiku/trunk/src/apps/Jamfile Log: Getting a little ahead of myself here... Modified: haiku/trunk/src/apps/Jamfile =================================================================== --- haiku/trunk/src/apps/Jamfile 2007-10-13 04:46:32 UTC (rev 22525) +++ haiku/trunk/src/apps/Jamfile 2007-10-13 05:02:09 UTC (rev 22526) @@ -12,7 +12,6 @@ SubInclude HAIKU_TOP src apps fontdemo ; SubInclude HAIKU_TOP src apps glteapot ; SubInclude HAIKU_TOP src apps icon-o-matic ; -SubInclude HAIKU_TOP src apps installedpackages ; SubInclude HAIKU_TOP src apps installer ; SubInclude HAIKU_TOP src apps launchbox ; SubInclude HAIKU_TOP src apps magnify ; @@ -38,4 +37,3 @@ SubInclude HAIKU_TOP src apps tv ; SubInclude HAIKU_TOP src apps workspaces ; -SubInclude HAIKU_TOP src apps test_app ; From sbenedetto at mail.berlios.de Sat Oct 13 11:44:24 2007 From: sbenedetto at mail.berlios.de (sbenedetto at BerliOS) Date: Sat, 13 Oct 2007 11:44:24 +0200 Subject: [Haiku-commits] r22527 - haiku/trunk/src/add-ons/kernel/busses/usb Message-ID: <200710130944.l9D9iO2A032171@sheep.berlios.de> Author: sbenedetto Date: 2007-10-13 11:44:23 +0200 (Sat, 13 Oct 2007) New Revision: 22527 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22527&view=rev Modified: haiku/trunk/src/add-ons/kernel/busses/usb/ohci.cpp haiku/trunk/src/add-ons/kernel/busses/usb/ohci.h haiku/trunk/src/add-ons/kernel/busses/usb/ohci_hardware.h Log: * Revert Copyright Modified: haiku/trunk/src/add-ons/kernel/busses/usb/ohci.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/usb/ohci.cpp 2007-10-13 05:02:09 UTC (rev 22526) +++ haiku/trunk/src/add-ons/kernel/busses/usb/ohci.cpp 2007-10-13 09:44:23 UTC (rev 22527) @@ -1,11 +1,27 @@ -/* - * Copyright 2005-2008, Haiku Inc. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * Jan-Rixt Van Hoye - * Salvatore Benedetto - */ +//------------------------------------------------------------------------------ +// Copyright (c) 2005, Jan-Rixt Van Hoye +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// +// ------------------------------------------------------------------------ +// Authors: +// Salvatore Benedetto #include #include Modified: haiku/trunk/src/add-ons/kernel/busses/usb/ohci.h =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/usb/ohci.h 2007-10-13 05:02:09 UTC (rev 22526) +++ haiku/trunk/src/add-ons/kernel/busses/usb/ohci.h 2007-10-13 09:44:23 UTC (rev 22527) @@ -1,12 +1,28 @@ -/* - * Copyright 2005-2008, Haiku Inc. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * Jan-Rixt Van Hoye - * Salvatore Benedetto - */ +//------------------------------------------------------------------------------ +// Copyright (c) 2005, Jan-Rixt Van Hoye +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +//------------------------------------------------------------------------------- +// Authors: +// Salvatore Benedetto + #ifndef OHCI_H #define OHCI_H Modified: haiku/trunk/src/add-ons/kernel/busses/usb/ohci_hardware.h =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/usb/ohci_hardware.h 2007-10-13 05:02:09 UTC (rev 22526) +++ haiku/trunk/src/add-ons/kernel/busses/usb/ohci_hardware.h 2007-10-13 09:44:23 UTC (rev 22527) @@ -1,12 +1,29 @@ -/* - * Copyright 2005-2008, Haiku Inc. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * Jan-Rixt Van Hoye - * Salvatore Benedetto - */ +//------------------------------------------------------------------------------ +// Copyright (c) 2005, Jan-Rixt Van Hoye +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// +// ---------------------------------------------------------------------------- +// Authors: +// Salvatore Benedetto + #ifndef OHCI_HARD_H #define OHCI_HARD_H From korli at users.berlios.de Sat Oct 13 12:12:47 2007 From: korli at users.berlios.de (=?ISO-8859-1?Q?J=E9r=F4me_Duval?=) Date: Sat, 13 Oct 2007 12:12:47 +0200 Subject: [Haiku-commits] r22527 - haiku/trunk/src/add-ons/kernel/busses/usb In-Reply-To: <200710130944.l9D9iO2A032171@sheep.berlios.de> References: <200710130944.l9D9iO2A032171@sheep.berlios.de> Message-ID: 2007/10/13, sbenedetto at BerliOS : > Log: > * Revert Copyright > Thanks. Alternatively, one could contact the original author for authorisation to change the license text. Bye, J?r?me From korli at mail.berlios.de Sat Oct 13 12:59:23 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Sat, 13 Oct 2007 12:59:23 +0200 Subject: [Haiku-commits] r22528 - haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auich Message-ID: <200710131059.l9DAxN8f013673@sheep.berlios.de> Author: korli Date: 2007-10-13 12:59:22 +0200 (Sat, 13 Oct 2007) New Revision: 22528 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22528&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auich/auich.c haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auich/io.c Log: increased snooze, ICH4 needs memory mapped io Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auich/auich.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auich/auich.c 2007-10-13 09:44:23 UTC (rev 22527) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auich/auich.c 2007-10-13 10:59:22 UTC (rev 22528) @@ -643,7 +643,11 @@ cmd = (*pci->read_pci_config)(card->info.bus, card->info.device, card->info.function, PCI_command, 2); PRINT(("PCI command before: %x\n", cmd)); - (*pci->write_pci_config)(card->info.bus, card->info.device, card->info.function, PCI_command, 2, cmd | PCI_command_io); + if (IS_ICH4(&card->config)) { + (*pci->write_pci_config)(card->info.bus, card->info.device, card->info.function, PCI_command, 2, cmd | PCI_command_memory); + } else { + (*pci->write_pci_config)(card->info.bus, card->info.device, card->info.function, PCI_command, 2, cmd | PCI_command_io); + } cmd = (*pci->read_pci_config)(card->info.bus, card->info.device, card->info.function, PCI_command, 2); PRINT(("PCI command after: %x\n", cmd)); Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auich/io.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auich/io.c 2007-10-13 09:44:23 UTC (rev 22527) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auich/io.c 2007-10-13 10:59:22 UTC (rev 22528) @@ -112,7 +112,7 @@ if ((auich_reg_read_8(config, AUICH_REG_ACC_SEMA) & 0x01) == 0) return B_OK; if (i > 100) - snooze(1); + snooze(10); } return B_TIMED_OUT; } From axeld at pinc-software.de Sat Oct 13 14:05:12 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Sat, 13 Oct 2007 14:05:12 +0200 CEST Subject: [Haiku-commits] r22522 - haiku/trunk/src/add-ons/kernel/busses/usb In-Reply-To: <12197868.1192229943984.JavaMail.ngmail@webmail16> Message-ID: <3168988023-BeMail@zon> Marcus Overhagen wrote: > This change is not allowed. Please revert it. The original copyright > notice and permission notice > must be preserved unmodified. Except Jan-Rixt Van Hoye allows you to - anyway, does it make sense at all to use this as a start? Bye, Axel. From emitrax at gmail.com Sat Oct 13 14:11:12 2007 From: emitrax at gmail.com (Salvatore Benedetto) Date: Sat, 13 Oct 2007 12:11:12 +0000 Subject: [Haiku-commits] r22522 - haiku/trunk/src/add-ons/kernel/busses/usb In-Reply-To: <3168988023-BeMail@zon> References: <12197868.1192229943984.JavaMail.ngmail@webmail16> <3168988023-BeMail@zon> Message-ID: On 10/13/07, Axel D?rfler wrote: > Marcus Overhagen wrote: > > This change is not allowed. Please revert it. The original copyright > > notice and permission notice > > must be preserved unmodified. > > Except Jan-Rixt Van Hoye allows you to - anyway, does it make sense at > all to use this as a start? You mean to use his code as a start for the driver ? > > Bye, > Axel. > > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > -- Salvatore Benedetto (a.k.a. emitrax) Student of Computer and Telecommunications Engineering University of Messina (Italy) www.messinalug.org Please do not send me any word, excel or power point file http://www.gnu.org/philosophy/no-word-attachments.html From korli at mail.berlios.de Sat Oct 13 14:14:26 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Sat, 13 Oct 2007 14:14:26 +0200 Subject: [Haiku-commits] r22529 - haiku/trunk/src/bin/coreutils/lib Message-ID: <200710131214.l9DCEQmP027057@sheep.berlios.de> Author: korli Date: 2007-10-13 14:14:25 +0200 (Sat, 13 Oct 2007) New Revision: 22529 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22529&view=rev Modified: haiku/trunk/src/bin/coreutils/lib/Jamfile haiku/trunk/src/bin/coreutils/lib/config.h Log: use regex from libroot Modified: haiku/trunk/src/bin/coreutils/lib/Jamfile =================================================================== --- haiku/trunk/src/bin/coreutils/lib/Jamfile 2007-10-13 10:59:22 UTC (rev 22528) +++ haiku/trunk/src/bin/coreutils/lib/Jamfile 2007-10-13 12:14:25 UTC (rev 22529) @@ -134,7 +134,7 @@ readtokens.c readtokens0.c # realloc.c - regex.c +# regex.c rename-dest-slash.c rename.c root-dev-ino.c Modified: haiku/trunk/src/bin/coreutils/lib/config.h =================================================================== --- haiku/trunk/src/bin/coreutils/lib/config.h 2007-10-13 10:59:22 UTC (rev 22528) +++ haiku/trunk/src/bin/coreutils/lib/config.h 2007-10-13 12:14:25 UTC (rev 22529) @@ -1824,37 +1824,37 @@ #define putenv rpl_putenv /* Define to rpl_re_comp if the replacement should be used. */ -#define re_comp rpl_re_comp +/* #undef re_comp rpl_re_comp */ /* Define to rpl_re_compile_fastmap if the replacement should be used. */ -#define re_compile_fastmap rpl_re_compile_fastmap +/* #undef re_compile_fastmap rpl_re_compile_fastmap */ /* Define to rpl_re_compile_pattern if the replacement should be used. */ -#define re_compile_pattern rpl_re_compile_pattern +/* #undef re_compile_pattern rpl_re_compile_pattern */ /* Define to rpl_re_exec if the replacement should be used. */ -#define re_exec rpl_re_exec +/* #undef re_exec rpl_re_exec */ /* Define to rpl_re_match if the replacement should be used. */ -#define re_match rpl_re_match +/* #undef re_match rpl_re_match */ /* Define to rpl_re_match_2 if the replacement should be used. */ -#define re_match_2 rpl_re_match_2 +/* #undef re_match_2 rpl_re_match_2 */ /* Define to rpl_re_search if the replacement should be used. */ -#define re_search rpl_re_search +/* #undef re_search rpl_re_search */ /* Define to rpl_re_search_2 if the replacement should be used. */ -#define re_search_2 rpl_re_search_2 +/* #undef re_search_2 rpl_re_search_2 */ /* Define to rpl_re_set_registers if the replacement should be used. */ -#define re_set_registers rpl_re_set_registers +/* #undef re_set_registers rpl_re_set_registers */ /* Define to rpl_re_set_syntax if the replacement should be used. */ -#define re_set_syntax rpl_re_set_syntax +/* #undef re_set_syntax rpl_re_set_syntax */ /* Define to rpl_re_syntax_options if the replacement should be used. */ -#define re_syntax_options rpl_re_syntax_options +/* #undef re_syntax_options rpl_re_syntax_options */ /* Define to rpl_realloc if the replacement function should be used. */ /* #undef realloc */ From korli at mail.berlios.de Sat Oct 13 14:50:37 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Sat, 13 Oct 2007 14:50:37 +0200 Subject: [Haiku-commits] r22530 - haiku/trunk/build/jam Message-ID: <200710131250.l9DCob7x028948@sheep.berlios.de> Author: korli Date: 2007-10-13 14:50:37 +0200 (Sat, 13 Oct 2007) New Revision: 22530 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22530&view=rev Modified: haiku/trunk/build/jam/HaikuImage Log: added base64, readlink, nohup, sha1sum, shred, shuf to the image Modified: haiku/trunk/build/jam/HaikuImage =================================================================== --- haiku/trunk/build/jam/HaikuImage 2007-10-13 12:14:25 UTC (rev 22529) +++ haiku/trunk/build/jam/HaikuImage 2007-10-13 12:50:37 UTC (rev 22530) @@ -22,7 +22,7 @@ GPL_ONLY = "" ; } -BEOS_BIN = "[" addattr alert arp basename bc beep bison bzip2 cat cardctl catattr +BEOS_BIN = "[" addattr alert arp base64 basename bc beep bison bzip2 cat cardctl catattr chgrp chmod chop chown cksum clear clockconfig cmp comm compress cp copyattr $(X86_ONLY)CortexAddOnHost csplit ctags cut date dc dd desklink df diff diff3 dircolors dirname @@ -33,11 +33,11 @@ keymap kill less lessecho lesskey link listarea listattr listdev listimage listport listres listsem ln locate logger login logname ls lsindex m4 make makebootable md5sum merge mimeset mkdos mkdir mkindex modifiers mount - mount_nfs mountvolume mv nc netstat nl od open pack_cis paste patch pathchk pc + mount_nfs mountvolume mv nc netstat nl nohup od open pack_cis paste patch pathchk pc ping play playfile playsound playwav pr prio printenv printf ps ptx pwd - query quit release renice rescan rlog rm rmattr rmindex rmdir roster route - safemode screen_blanker sed setdecor settype setversion setvolume seq sh shar - shutdown sleep sort split strace stty su sum sync sysinfo tac tail tar + query quit readlink release renice rescan rlog rm rmattr rmindex rmdir roster route + safemode screen_blanker sed setdecor settype setversion setvolume seq sh sha1sum shar + shred shuf shutdown sleep sort split stat strace stty su sum sync sysinfo tac tail tar tcpdump tcptester tee telnet telnetd test top touch tput tr traceroute translate true tsort tty uname unchop unexpand unmount uniq unrar unshar unzip unzipsfx updatedb uptime urlwrapper usb_dev_info uudecode uuencode vdir From korli at mail.berlios.de Sat Oct 13 15:06:34 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Sat, 13 Oct 2007 15:06:34 +0200 Subject: [Haiku-commits] r22531 - in haiku/trunk/src/preferences: appearance keyboard Message-ID: <200710131306.l9DD6YtU031085@sheep.berlios.de> Author: korli Date: 2007-10-13 15:06:33 +0200 (Sat, 13 Oct 2007) New Revision: 22531 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22531&view=rev Modified: haiku/trunk/src/preferences/appearance/APRView.cpp haiku/trunk/src/preferences/appearance/defs.h haiku/trunk/src/preferences/keyboard/KeyboardView.cpp Log: Patch from Pier Luigi Fiorini for layouts of Appearance and Keyboard preferences Modified: haiku/trunk/src/preferences/appearance/APRView.cpp =================================================================== --- haiku/trunk/src/preferences/appearance/APRView.cpp 2007-10-13 12:50:37 UTC (rev 22530) +++ haiku/trunk/src/preferences/appearance/APRView.cpp 2007-10-13 13:06:33 UTC (rev 22531) @@ -48,7 +48,7 @@ { SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - BRect rect(Bounds().InsetByCopy(10,10)); + BRect rect(Bounds().InsetByCopy(kBorderSpace,kBorderSpace)); #ifdef HAIKU_TARGET_PLATFORM_HAIKU @@ -139,7 +139,7 @@ rect.right = wellrect.right; rect.OffsetTo((Bounds().Width()-rect.Width())/2,rect.top); - fPicker = new BColorControl(BPoint(10,fScrollView->Frame().bottom+20),B_CELLS_32x8,5.0,"fPicker", + fPicker = new BColorControl(BPoint(fScrollView->Frame().left,fScrollView->Frame().bottom+kBorderSpace),B_CELLS_32x8,5.0,"fPicker", new BMessage(UPDATE_COLOR)); AddChild(fPicker); @@ -148,19 +148,19 @@ B_FOLLOW_LEFT |B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE); fDefaults->ResizeToPreferred(); fDefaults->SetEnabled(false); - fDefaults->MoveTo((fPicker->Frame().right-(fDefaults->Frame().Width()*2)-20)/2,fPicker->Frame().bottom+20); + fDefaults->MoveTo(fPicker->Frame().left,fPicker->Frame().bottom+kBorderSpace); AddChild(fDefaults); BRect cvrect(fDefaults->Frame()); - cvrect.OffsetBy(cvrect.Width() + 20,0); + cvrect.OffsetBy(cvrect.Width() + kItemSpace,0); fRevert = new BButton(cvrect,"RevertButton","Revert", new BMessage(REVERT_SETTINGS), B_FOLLOW_LEFT |B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE); + fRevert->ResizeToPreferred(); fRevert->SetEnabled(false); AddChild(fRevert); - } APRView::~APRView(void) Modified: haiku/trunk/src/preferences/appearance/defs.h =================================================================== --- haiku/trunk/src/preferences/appearance/defs.h 2007-10-13 12:50:37 UTC (rev 22530) +++ haiku/trunk/src/preferences/appearance/defs.h 2007-10-13 13:06:33 UTC (rev 22531) @@ -35,4 +35,9 @@ #define SET_UI_COLORS 'suic' #define PREFS_CHOSEN 'prch' + +// user interface +const uint32 kBorderSpace = 10; +const uint32 kItemSpace = 7; + #endif Modified: haiku/trunk/src/preferences/keyboard/KeyboardView.cpp =================================================================== --- haiku/trunk/src/preferences/keyboard/KeyboardView.cpp 2007-10-13 12:50:37 UTC (rev 22530) +++ haiku/trunk/src/preferences/keyboard/KeyboardView.cpp 2007-10-13 13:06:33 UTC (rev 22531) @@ -19,6 +19,9 @@ #include "KeyboardView.h" #include "KeyboardMessages.h" +// user interface +const uint32 kBorderSpace = 10; +const uint32 kItemSpace = 7; KeyboardView::KeyboardView(BRect rect) : BView(rect, "keyboard_view", B_FOLLOW_LEFT | B_FOLLOW_TOP, @@ -40,7 +43,7 @@ fontHeight.leading; // Create the "Key repeat rate" slider... - frame.Set(10,10,10 + labelwidth,10 + (labelheight*2) + 20); + frame.Set(kBorderSpace,kBorderSpace,kBorderSpace + labelwidth,kBorderSpace + (labelheight*2) + (kBorderSpace*2)); fRepeatSlider = new BSlider(frame,"key_repeat_rate", "Key repeat rate", new BMessage(SLIDER_REPEAT_RATE), @@ -52,7 +55,7 @@ // Create the "Delay until key repeat" slider... - frame.OffsetBy(0,frame.Height() + 10); + frame.OffsetBy(0,frame.Height() + kBorderSpace); fDelaySlider = new BSlider(frame,"delay_until_key_repeat", "Delay until key repeat", new BMessage(SLIDER_DELAY_RATE),250000,1000000, @@ -64,7 +67,7 @@ // Create the "Typing test area" text box... frame.OffsetBy(0,frame.Height() + 15); frame.right = fDelaySlider->Frame().right + fIconBitmap->Bounds().Width() + - 10; + kBorderSpace; BTextControl *textcontrol = new BTextControl(frame,"typing_test_area",NULL, "Typing test area", new BMessage('TTEA'), @@ -76,10 +79,10 @@ textcontrol->ResizeTo(frame.Width(),height); // Create the box for the sliders... - frame.left = frame.top = 10; + frame.left = frame.top = kBorderSpace; frame.right = frame.left + fDelaySlider->Frame().right + - fClockBitmap->Bounds().Width() + 20; - frame.bottom = textcontrol->Frame().bottom + 20; + fClockBitmap->Bounds().Width() + (kBorderSpace*2); + frame.bottom = textcontrol->Frame().bottom + (kBorderSpace*2); fBox = new BBox(frame,"keyboard_box",B_FOLLOW_LEFT,B_WILL_DRAW, B_FANCY_BORDER); AddChild(fBox); @@ -89,8 +92,8 @@ fBox->AddChild(textcontrol); //Add the "Default" button.. - frame.left = 10; - frame.top = fBox->Frame().bottom + 10; + frame.left = kBorderSpace; + frame.top = fBox->Frame().bottom + kBorderSpace; frame.right = frame.left + 1; frame.bottom = frame.top + 1; BButton *button = new BButton(frame,"keyboard_defaults","Defaults", @@ -100,13 +103,14 @@ // Add the "Revert" button... frame = button->Frame(); - frame.OffsetBy(frame.Width() + 10, 0); + frame.OffsetBy(frame.Width() + kItemSpace, 0); button = new BButton(frame,"keyboard_revert","Revert", new BMessage(BUTTON_REVERT)); + button->ResizeToPreferred(); button->SetEnabled(false); AddChild(button); - ResizeTo(fBox->Frame().right + 10, button->Frame().bottom + 10); + ResizeTo(fBox->Frame().right + kBorderSpace, button->Frame().bottom + kBorderSpace); } void From axeld at pinc-software.de Sat Oct 13 15:57:09 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Sat, 13 Oct 2007 15:57:09 +0200 CEST Subject: [Haiku-commits] =?iso-8859-15?q?r22522_-_haiku/trunk/src/add-ons/?= =?iso-8859-15?q?kernel/busses/usb?= In-Reply-To: Message-ID: <9885279569-BeMail@zon> "Salvatore Benedetto" wrote: > On 10/13/07, Axel D?rfler wrote: > > Marcus Overhagen wrote: > > > This change is not allowed. Please revert it. The original > > > copyright > > > notice and permission notice must be preserved unmodified. > > Except Jan-Rixt Van Hoye allows you to - anyway, does it make sense > > at > > all to use this as a start? > You mean to use his code as a start for the driver ? Yes - I didn't have a look at it myself, but I didn't hear anything good about OHCI yet. Bye, Axel. From sbenedetto at mail.berlios.de Sat Oct 13 16:00:38 2007 From: sbenedetto at mail.berlios.de (sbenedetto at BerliOS) Date: Sat, 13 Oct 2007 16:00:38 +0200 Subject: [Haiku-commits] r22532 - haiku/trunk/src/add-ons/kernel/busses/usb Message-ID: <200710131400.l9DE0cIT001655@sheep.berlios.de> Author: sbenedetto Date: 2007-10-13 16:00:37 +0200 (Sat, 13 Oct 2007) New Revision: 22532 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22532&view=rev Removed: haiku/trunk/src/add-ons/kernel/busses/usb/ohci_software.h Modified: haiku/trunk/src/add-ons/kernel/busses/usb/ohci_rh.cpp Log: * Clean up ohci_rh.cpp, following the style used in the others *hci_rh.cpp files * Forgot to remove ohci_software in my previous patch Modified: haiku/trunk/src/add-ons/kernel/busses/usb/ohci_rh.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/usb/ohci_rh.cpp 2007-10-13 13:06:33 UTC (rev 22531) +++ haiku/trunk/src/add-ons/kernel/busses/usb/ohci_rh.cpp 2007-10-13 14:00:37 UTC (rev 22532) @@ -25,20 +25,23 @@ static usb_device_descriptor sOHCIRootHubDevice = { - 0x12, //Descriptor size - USB_DESCRIPTOR_DEVICE , //Type of descriptor - 0x110, //USB 1.1 - 0x09 , //Hub type - 0 , //Subclass - 0 , //Protocol - 64 , //Max packet size - 0 , //Vendor - 0 , //Product - 0x110 , //Version - 1 , 2 , 0 , //Other data - 1 //Number of configurations + 0x12, // Descriptor size + USB_DESCRIPTOR_DEVICE, // Type of descriptor + 0x110, // USB 1.1 + 0x09, // Hub type + 0, // Subclass + 0, // Protocol + 64, // Max packet size + 0, // Vendor + 0, // Product + 0x110, // Version + 1, // Index of manufacture string + 2, // Index of product string + 0, // Index of serial number string + 1 // Number of configurations }; + struct ohci_root_hub_configuration_s { usb_configuration_descriptor configuration; usb_interface_descriptor interface; @@ -46,47 +49,50 @@ usb_hub_descriptor hub; } _PACKED; -static ohci_root_hub_configuration_s sOHCIRootHubConfig = { + +static ohci_root_hub_configuration_s sOHCIRootHubConfig = +{ { // configuration descriptor - 9, //Size - USB_DESCRIPTOR_CONFIGURATION, - 34, //Total size of the configuration - 1, //Number interfaces - 1, //Value of configuration - 0, //Number of configuration - 0x40, //Self powered - 0 //Max power (0, because of self power) + 9, // Descriptor length + USB_DESCRIPTOR_CONFIGURATION, // Descriptor type + 34, // Total size of the configuration + 1, // Number interfaces + 1, // Value of configuration + 0, // Number of configuration + 0x40, // Self powered + 0 // Max power (0, because of self power) }, { // interface descriptor - 9, //Size - USB_DESCRIPTOR_INTERFACE, - 0, //Interface number - 0, //Alternate setting - 1, //Num endpoints - 0x09, //Interface class - 0, //Interface subclass - 0, //Interface protocol - 0 //Interface + 9, // Size + USB_DESCRIPTOR_INTERFACE, // Type + 0, // Interface number + 0, // Alternate setting + 1, // Num endpoints + 0x09, // Interface class + 0, // Interface subclass + 0, // Interface protocol + 0 // Interface }, { // endpoint descriptor - 7, //Size - USB_DESCRIPTOR_ENDPOINT, - USB_REQTYPE_DEVICE_IN | 1, //1 from freebsd driver - 0x3, // Interrupt - 8, // Max packet size - 0xFF // Interval 256 + 7, // Size + USB_DESCRIPTOR_ENDPOINT, // Type + USB_REQTYPE_DEVICE_IN | 1, // Endpoint address (first in IN endpoint) + 0x03, // Attributes (0x03 = interrupt endpoint) + 8, // Max packet size + 0xFF // Interval 256 }, - { - 9, //Including deprecated powerctrlmask - USB_DESCRIPTOR_HUB, - 0, //Number of ports - 0x0000, //Hub characteristics FIXME - 50, //Power on to power good + { // hub descriptor + 9, // Lenght (including deprecated power + // control mask) + USB_DESCRIPTOR_HUB, // Type + 0, // Number of ports + 0x0000, // Hub characteristics + 50, // Power on to power good 0, // Current - 0x00, //Both ports are removable + 0x00, // Both ports are removable 0xff // Depricated power control mask } }; @@ -128,44 +134,44 @@ }; -OHCIRootHub::OHCIRootHub(OHCI *ohci, int8 deviceAddress) - : Hub(ohci->RootObject(), sOHCIRootHubDevice, deviceAddress , USB_SPEED_FULLSPEED ) +OHCIRootHub::OHCIRootHub(Object *rootObject, int8 deviceAddress) + : Hub(rootObject, sOHCIRootHubDevice, deviceAddress, USB_SPEED_FULLSPEED) { } status_t -OHCIRootHub::ProcessTransfer(Transfer *t, OHCI *ohci) +OHCIRootHub::ProcessTransfer(OHCI *ohci, Transfer *transfer) { - if ((t->TransferPipe()->Type() & USB_OBJECT_CONTROL_PIPE) == 0) + if ((transfer->TransferPipe()->Type() & USB_OBJECT_CONTROL_PIPE) == 0) return B_ERROR; - usb_request_data *request = t->RequestData(); - TRACE(("OHCIRootHub::ProcessTransfer(): request: %d\n", request->Request)); + usb_request_data *request = transfer->RequestData(); - uint32 status = B_TIMED_OUT; + TRACE(("usb_ohci_roothub(): request: %d\n", request->Request)); + + status_t status = B_TIMED_OUT; size_t actualLength = 0; switch (request->Request) { case USB_REQUEST_GET_STATUS: { if (request->Index == 0) { // get hub status actualLength = MIN(sizeof(usb_port_status), - t->DataLength()); + transfer->DataLength()); // the hub reports whether the local power failed (bit 0) // and if there is a over-current condition (bit 1). // everything as 0 means all is ok. // TODO (?) actually check for the value - memset(t->Data(), 0, actualLength); + memset(transfer->Data(), 0, actualLength); status = B_OK; break; } usb_port_status portStatus; - if (ohci->GetPortStatus(request->Index, &portStatus) >= B_OK) { - actualLength = MIN(sizeof(usb_port_status), t->DataLength()); - memcpy(t->Data(), (void *)&portStatus, actualLength); + if (ohci->GetPortStatus(request->Index - 1, &portStatus) >= B_OK) { + actualLength = MIN(sizeof(usb_port_status), transfer->DataLength()); + memcpy(transfer->Data(), (void *)&portStatus, actualLength); status = B_OK; } - break; } @@ -175,30 +181,28 @@ break; } - TRACE(("OHCIRootHub::ProcessTransfer(): set address: %d\n", request->Value)); + TRACE(("usb_ohci_roothub(): set address: %d\n", request->Value)); status = B_OK; break; case USB_REQUEST_GET_DESCRIPTOR: - TRACE(("OHCIRootHub::ProcessTransfer(): get descriptor: %d\n", request->Value >> 8)); + TRACE(("usb_ohci_roothub(): get descriptor: %d\n", request->Value >> 8)); switch (request->Value >> 8) { case USB_DESCRIPTOR_DEVICE: { actualLength = MIN(sizeof(usb_device_descriptor), - t->DataLength()); - memcpy(t->Data(), (void *)&sOHCIRootHubDevice, + transfer->DataLength()); + memcpy(transfer->Data(), (void *)&sOHCIRootHubDevice, actualLength); status = B_OK; break; } case USB_DESCRIPTOR_CONFIGURATION: { - //Make sure we have the correct number of ports + actualLength = MIN(sizeof(ohci_root_hub_configuration_s), + transfer->DataLength()); sOHCIRootHubConfig.hub.num_ports = ohci->PortCount(); - - actualLength = MIN(sizeof(sOHCIRootHubConfig), - t->DataLength()); - memcpy(t->Data(), (void *)&(sOHCIRootHubConfig), + memcpy(transfer->Data(), (void *)&sOHCIRootHubConfig, actualLength); status = B_OK; break; @@ -210,20 +214,18 @@ break; actualLength = MIN(sOHCIRootHubStrings[index].length, - t->DataLength()); - memcpy(t->Data(), (void *)&sOHCIRootHubStrings[index], + transfer->DataLength()); + memcpy(transfer->Data(), (void *)&sOHCIRootHubStrings[index], actualLength); status = B_OK; break; } case USB_DESCRIPTOR_HUB: { - //Make sure we have the correct number of ports + actualLength = MIN(sizeof(usb_hub_descriptor), + transfer->DataLength()); sOHCIRootHubConfig.hub.num_ports = ohci->PortCount(); - - actualLength = MIN(sizeof(usb_hub_descriptor), - t->DataLength()); - memcpy(t->Data(), (void *)&sOHCIRootHubConfig.hub, + memcpy(transfer->Data(), (void *)&sOHCIRootHubConfig.hub, actualLength); status = B_OK; break; @@ -238,12 +240,12 @@ case USB_REQUEST_CLEAR_FEATURE: { if (request->Index == 0) { // we don't support any hub changes - TRACE_ERROR(("OHCIRootHub::ProcessTransfer(): clear feature: no hub changes\n")); + TRACE_ERROR(("usb_ohci_roothub(): clear feature: no hub changes\n")); break; } - TRACE(("OHCIRootHub::ProcessTransfer(): clear feature: %d\n", request->Value)); - if (ohci->ClearPortFeature(request->Index, request->Value) >= B_OK) + TRACE(("usb_ohci_roothub(): clear feature: %d\n", request->Value)); + if (ohci->ClearPortFeature(request->Index - 1, request->Value) >= B_OK) status = B_OK; break; } @@ -251,19 +253,18 @@ case USB_REQUEST_SET_FEATURE: { if (request->Index == 0) { // we don't support any hub changes - TRACE_ERROR(("OHCIRootHub::ProcessTransfer(): set feature: no hub changes\n")); + TRACE_ERROR(("usb_ohci_roothub(): set feature: no hub changes\n")); break; } - TRACE(("OHCIRootHub::ProcessTransfer(): set feature: %d\n", request->Value)); - if (ohci->SetPortFeature(request->Index, request->Value) >= B_OK) + TRACE(("usb_ohci_roothub(): set feature: %d\n", request->Value)); + if (ohci->SetPortFeature(request->Index - 1, request->Value) >= B_OK) status = B_OK; break; } } - t->Finished(status, actualLength); - delete t; + transfer->Finished(status, actualLength); + delete transfer; return B_OK; -} - +} Deleted: haiku/trunk/src/add-ons/kernel/busses/usb/ohci_software.h From emitrax at gmail.com Sat Oct 13 16:04:40 2007 From: emitrax at gmail.com (Salvatore Benedetto) Date: Sat, 13 Oct 2007 14:04:40 +0000 Subject: [Haiku-commits] r22522 - haiku/trunk/src/add-ons/kernel/busses/usb In-Reply-To: <9885279569-BeMail@zon> References: <9885279569-BeMail@zon> Message-ID: On 10/13/07, Axel D?rfler wrote: > "Salvatore Benedetto" wrote: > > On 10/13/07, Axel D?rfler wrote: > > > Marcus Overhagen wrote: > > > > This change is not allowed. Please revert it. The original > > > > copyright > > > > notice and permission notice must be preserved unmodified. > > > Except Jan-Rixt Van Hoye allows you to - anyway, does it make sense > > > at > > > all to use this as a start? > > You mean to use his code as a start for the driver ? > > Yes - I didn't have a look at it myself, but I didn't hear anything > good about OHCI yet. Well, it's always better than starting from scratch I guess. I'll try and contact the guy to see if I can change the license. Salvo > > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > -- Salvatore Benedetto (a.k.a. emitrax) Student of Computer and Telecommunications Engineering University of Messina (Italy) www.messinalug.org Please do not send me any word, excel or power point file http://www.gnu.org/philosophy/no-word-attachments.html From korli at mail.berlios.de Sat Oct 13 17:34:20 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Sat, 13 Oct 2007 17:34:20 +0200 Subject: [Haiku-commits] r22533 - in haiku/trunk/src/system/libroot: . posix/glibc posix/glibc/iconv posix/glibc/include posix/glibc/include/arch/ppc/bits posix/glibc/include/arch/x86/bits posix/glibc/include/bits posix/glibc/include/sys posix/glibc/libio posix/glibc/locale posix/glibc/misc posix/glibc/wcsmbs Message-ID: <200710131534.l9DFYKCQ005636@sheep.berlios.de> Author: korli Date: 2007-10-13 17:34:19 +0200 (Sat, 13 Oct 2007) New Revision: 22533 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22533&view=rev Added: haiku/trunk/src/system/libroot/posix/glibc/iconv/Jamfile haiku/trunk/src/system/libroot/posix/glibc/include/arch/ppc/bits/byteswap.h haiku/trunk/src/system/libroot/posix/glibc/include/arch/x86/bits/string.h haiku/trunk/src/system/libroot/posix/glibc/include/bits/stat.h haiku/trunk/src/system/libroot/posix/glibc/include/byteswap.h haiku/trunk/src/system/libroot/posix/glibc/include/search.h haiku/trunk/src/system/libroot/posix/glibc/include/sys/stat.h haiku/trunk/src/system/libroot/posix/glibc/libio/__fsetlocking.c haiku/trunk/src/system/libroot/posix/glibc/misc/ haiku/trunk/src/system/libroot/posix/glibc/misc/Jamfile haiku/trunk/src/system/libroot/posix/glibc/misc/search.h haiku/trunk/src/system/libroot/posix/glibc/misc/tsearch.c Modified: haiku/trunk/src/system/libroot/Jamfile haiku/trunk/src/system/libroot/posix/glibc/Jamfile haiku/trunk/src/system/libroot/posix/glibc/iconv/gconv_cache.c haiku/trunk/src/system/libroot/posix/glibc/iconv/gconv_conf.c haiku/trunk/src/system/libroot/posix/glibc/iconv/gconv_db.c haiku/trunk/src/system/libroot/posix/glibc/iconv/gconv_dl.c haiku/trunk/src/system/libroot/posix/glibc/iconv/gconv_simple.c haiku/trunk/src/system/libroot/posix/glibc/include/arch/x86/bits/byteswap.h haiku/trunk/src/system/libroot/posix/glibc/include/fcntl.h haiku/trunk/src/system/libroot/posix/glibc/include/string.h haiku/trunk/src/system/libroot/posix/glibc/include/unistd.h haiku/trunk/src/system/libroot/posix/glibc/libio/Jamfile haiku/trunk/src/system/libroot/posix/glibc/locale/Jamfile haiku/trunk/src/system/libroot/posix/glibc/wcsmbs/Jamfile haiku/trunk/src/system/libroot/posix/glibc/wcsmbs/wcsmbsload.c Log: added some tsearch and iconv functions, Modified: haiku/trunk/src/system/libroot/Jamfile =================================================================== --- haiku/trunk/src/system/libroot/Jamfile 2007-10-13 14:00:37 UTC (rev 22532) +++ haiku/trunk/src/system/libroot/Jamfile 2007-10-13 15:34:19 UTC (rev 22533) @@ -22,8 +22,10 @@ posix_gnu_arch_$(TARGET_ARCH).o posix_gnu_ctype.o posix_gnu_ext.o + posix_gnu_iconv.o posix_gnu_libio.o posix_gnu_locale.o + posix_gnu_misc.o posix_gnu_regex.o posix_gnu_stdio.o posix_gnu_stdlib.o Modified: haiku/trunk/src/system/libroot/posix/glibc/Jamfile =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/Jamfile 2007-10-13 14:00:37 UTC (rev 22532) +++ haiku/trunk/src/system/libroot/posix/glibc/Jamfile 2007-10-13 15:34:19 UTC (rev 22533) @@ -3,8 +3,10 @@ SubInclude HAIKU_TOP src system libroot posix glibc arch ; SubInclude HAIKU_TOP src system libroot posix glibc ctype ; SubInclude HAIKU_TOP src system libroot posix glibc extensions ; +SubInclude HAIKU_TOP src system libroot posix glibc iconv ; SubInclude HAIKU_TOP src system libroot posix glibc locale ; SubInclude HAIKU_TOP src system libroot posix glibc libio ; +SubInclude HAIKU_TOP src system libroot posix glibc misc ; SubInclude HAIKU_TOP src system libroot posix glibc regex ; SubInclude HAIKU_TOP src system libroot posix glibc stdio-common ; SubInclude HAIKU_TOP src system libroot posix glibc stdlib ; Added: haiku/trunk/src/system/libroot/posix/glibc/iconv/Jamfile =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/iconv/Jamfile 2007-10-13 14:00:37 UTC (rev 22532) +++ haiku/trunk/src/system/libroot/posix/glibc/iconv/Jamfile 2007-10-13 15:34:19 UTC (rev 22533) @@ -0,0 +1,23 @@ +SubDir HAIKU_TOP src system libroot posix glibc iconv ; + +SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc include arch + $(TARGET_ARCH) ; +SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc include arch generic ; +SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc include ; +SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc libio ; +SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc ctype ; +SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc iconv ; +SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc locale ; +#SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc string ; +SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc ; + +SubDirCcFlags -D_GNU_SOURCE -DUSE_IN_LIBIO ; + +MergeObject posix_gnu_iconv.o : + gconv_builtin.c + gconv_cache.c + gconv_conf.c + gconv_db.c +# gconv_dl.c + gconv_simple.c +; Modified: haiku/trunk/src/system/libroot/posix/glibc/iconv/gconv_cache.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/iconv/gconv_cache.c 2007-10-13 14:00:37 UTC (rev 22532) +++ haiku/trunk/src/system/libroot/posix/glibc/iconv/gconv_cache.c 2007-10-13 15:34:19 UTC (rev 22533) @@ -23,7 +23,7 @@ #include #include #include -#include +//#include #include #include @@ -53,10 +53,11 @@ /* We cannot use the cache if the GCONV_PATH environment variable is set. */ - __gconv_path_envvar = getenv ("GCONV_PATH"); - if (__gconv_path_envvar != NULL) +// __gconv_path_envvar = getenv ("GCONV_PATH"); +// if (__gconv_path_envvar != NULL) return -1; +#if 0 /* See whether the cache file exists. */ fd = __open (GCONV_MODULES_CACHE, O_RDONLY); if (__builtin_expect (fd, 0) == -1) @@ -137,6 +138,7 @@ /* That worked. */ return 0; +#endif } @@ -177,7 +179,7 @@ return -1; } - +#if 0 #ifndef STATIC_GCONV static int internal_function @@ -213,6 +215,7 @@ return status; } #endif +#endif int @@ -240,6 +243,8 @@ __gconv_lookup_cache (const char *toset, const char *fromset, struct __gconv_step **handle, size_t *nsteps, int flags) { + return __GCONV_NODB; +#if 0 const struct gconvcache_header *header; const char *strtab; size_t fromidx; @@ -433,6 +438,7 @@ } return __GCONV_OK; +#endif } Modified: haiku/trunk/src/system/libroot/posix/glibc/iconv/gconv_conf.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/iconv/gconv_conf.c 2007-10-13 14:00:37 UTC (rev 22532) +++ haiku/trunk/src/system/libroot/posix/glibc/iconv/gconv_conf.c 2007-10-13 15:34:19 UTC (rev 22533) @@ -35,9 +35,8 @@ #include #include - /* This is the default path where we look for module lists. */ -static const char default_gconv_path[] = GCONV_PATH; +static const char default_gconv_path[] = ""; //GCONV_PATH; /* The path elements, as determined by the __gconv_get_path function. All path elements end in a slash. */ Modified: haiku/trunk/src/system/libroot/posix/glibc/iconv/gconv_db.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/iconv/gconv_db.c 2007-10-13 14:00:37 UTC (rev 22532) +++ haiku/trunk/src/system/libroot/posix/glibc/iconv/gconv_db.c 2007-10-13 15:34:19 UTC (rev 22533) @@ -19,7 +19,7 @@ 02111-1307 USA. */ #include -#include +//#include #include #include #include @@ -29,7 +29,9 @@ #include #include +#define STATIC_GCONV + /* Simple data structure for alias mapping. We have two names, `from' and `to'. */ void *__gconv_alias_db; @@ -214,6 +216,7 @@ } } +#if 0 static int internal_function gen_steps (struct derivation_step *best, const char *toset, @@ -635,8 +638,8 @@ return result; } +#endif - /* Control of initialization. */ __libc_once_define (static, once); @@ -676,6 +679,8 @@ struct __gconv_step **handle, size_t *nsteps, int flags) { + return __GCONV_NOCONV; +#if 0 const char *fromset_expand; const char *toset_expand; int result; @@ -732,6 +737,7 @@ return (result == __GCONV_OK ? (*handle == NULL ? __GCONV_NOCONV : __GCONV_OK) : result); +#endif } Modified: haiku/trunk/src/system/libroot/posix/glibc/iconv/gconv_dl.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/iconv/gconv_dl.c 2007-10-13 14:00:37 UTC (rev 22532) +++ haiku/trunk/src/system/libroot/posix/glibc/iconv/gconv_dl.c 2007-10-13 15:34:19 UTC (rev 22533) @@ -67,6 +67,8 @@ internal_function __gconv_find_shlib (const char *name) { + return NULL; +#if 0 struct __gconv_loaded_object *found; void *keyp; @@ -142,6 +144,7 @@ } return found; +#endif } Modified: haiku/trunk/src/system/libroot/posix/glibc/iconv/gconv_simple.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/iconv/gconv_simple.c 2007-10-13 14:00:37 UTC (rev 22532) +++ haiku/trunk/src/system/libroot/posix/glibc/iconv/gconv_simple.c 2007-10-13 15:34:19 UTC (rev 22533) @@ -1,5 +1,5 @@ /* Simple transformations functions. - Copyright (C) 1997-2002, 2003 Free Software Foundation, Inc. + Copyright (C) 1997-2003, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 1997. @@ -72,6 +72,7 @@ static inline int +__attribute ((always_inline)) internal_ucs4_loop (struct __gconv_step *step, struct __gconv_step_data *step_data, const unsigned char **inptrp, const unsigned char *inend, @@ -86,12 +87,13 @@ #if __BYTE_ORDER == __LITTLE_ENDIAN /* Sigh, we have to do some real work. */ size_t cnt; + uint32_t *outptr32 = (uint32_t *) outptr; for (cnt = 0; cnt < n_convert; ++cnt, inptr += 4) - *((uint32_t *) outptr)++ = bswap_32 (*(const uint32_t *) inptr); + *outptr32++ = bswap_32 (*(const uint32_t *) inptr); *inptrp = inptr; - *outptrp = outptr; + *outptrp = (unsigned char *) outptr32; #elif __BYTE_ORDER == __BIG_ENDIAN /* Simply copy the data. */ *inptrp = inptr + n_convert * 4; @@ -113,6 +115,7 @@ #ifndef _STRING_ARCH_unaligned static inline int +__attribute ((always_inline)) internal_ucs4_loop_unaligned (struct __gconv_step *step, struct __gconv_step_data *step_data, const unsigned char **inptrp, @@ -161,6 +164,7 @@ static inline int +__attribute ((always_inline)) internal_ucs4_loop_single (struct __gconv_step *step, struct __gconv_step_data *step_data, const unsigned char **inptrp, @@ -189,13 +193,16 @@ (*outptrp)[2] = state->__value.__wchb[1]; (*outptrp)[3] = state->__value.__wchb[0]; - *outptrp += 4; #elif __BYTE_ORDER == __BIG_ENDIAN /* XXX unaligned */ - *(*((uint32_t **) outptrp)++) = state->__value.__wch; + (*outptrp)[0] = state->__value.__wchb[0]; + (*outptrp)[1] = state->__value.__wchb[1]; + (*outptrp)[2] = state->__value.__wchb[2]; + (*outptrp)[3] = state->__value.__wchb[3]; #else # error "This endianess is not supported." #endif + *outptrp += 4; /* Clear the state buffer. */ state->__count &= ~7; @@ -219,6 +226,7 @@ static inline int +__attribute ((always_inline)) ucs4_internal_loop (struct __gconv_step *step, struct __gconv_step_data *step_data, const unsigned char **inptrp, const unsigned char *inend, @@ -264,7 +272,8 @@ return __GCONV_ILLEGAL_INPUT; } - *((uint32_t *) outptr)++ = inval; + *((uint32_t *) outptr) = inval; + outptr += sizeof (uint32_t); } *inptrp = inptr; @@ -283,6 +292,7 @@ #ifndef _STRING_ARCH_unaligned static inline int +__attribute ((always_inline)) ucs4_internal_loop_unaligned (struct __gconv_step *step, struct __gconv_step_data *step_data, const unsigned char **inptrp, @@ -352,6 +362,7 @@ static inline int +__attribute ((always_inline)) ucs4_internal_loop_single (struct __gconv_step *step, struct __gconv_step_data *step_data, const unsigned char **inptrp, @@ -426,6 +437,7 @@ static inline int +__attribute ((always_inline)) internal_ucs4le_loop (struct __gconv_step *step, struct __gconv_step_data *step_data, const unsigned char **inptrp, const unsigned char *inend, @@ -440,9 +452,11 @@ #if __BYTE_ORDER == __BIG_ENDIAN /* Sigh, we have to do some real work. */ size_t cnt; + uint32_t *outptr32 = (uint32_t *) outptr; for (cnt = 0; cnt < n_convert; ++cnt, inptr += 4) - *((uint32_t *) outptr)++ = bswap_32 (*(const uint32_t *) inptr); + *outptr32++ = bswap_32 (*(const uint32_t *) inptr); + outptr = (unsigned char *) outptr32; *inptrp = inptr; *outptrp = outptr; @@ -467,6 +481,7 @@ #ifndef _STRING_ARCH_unaligned static inline int +__attribute ((always_inline)) internal_ucs4le_loop_unaligned (struct __gconv_step *step, struct __gconv_step_data *step_data, const unsigned char **inptrp, @@ -518,6 +533,7 @@ static inline int +__attribute ((always_inline)) internal_ucs4le_loop_single (struct __gconv_step *step, struct __gconv_step_data *step_data, const unsigned char **inptrp, @@ -546,12 +562,17 @@ (*outptrp)[2] = state->__value.__wchb[1]; (*outptrp)[3] = state->__value.__wchb[0]; - *outptrp += 4; #else /* XXX unaligned */ - *(*((uint32_t **) outptrp)++) = state->__value.__wch; + (*outptrp)[0] = state->__value.__wchb[0]; + (*outptrp)[1] = state->__value.__wchb[1]; + (*outptrp)[2] = state->__value.__wchb[2]; + (*outptrp)[3] = state->__value.__wchb[3]; + #endif + *outptrp += 4; + /* Clear the state buffer. */ state->__count &= ~7; @@ -573,6 +594,7 @@ static inline int +__attribute ((always_inline)) ucs4le_internal_loop (struct __gconv_step *step, struct __gconv_step_data *step_data, const unsigned char **inptrp, const unsigned char *inend, @@ -616,7 +638,8 @@ return __GCONV_ILLEGAL_INPUT; } - *((uint32_t *) outptr)++ = inval; + *((uint32_t *) outptr) = inval; + outptr += sizeof (uint32_t); } *inptrp = inptr; @@ -638,6 +661,7 @@ #ifndef _STRING_ARCH_unaligned static inline int +__attribute ((always_inline)) ucs4le_internal_loop_unaligned (struct __gconv_step *step, struct __gconv_step_data *step_data, const unsigned char **inptrp, @@ -711,6 +735,7 @@ static inline int +__attribute ((always_inline)) ucs4le_internal_loop_single (struct __gconv_step *step, struct __gconv_step_data *step_data, const unsigned char **inptrp, @@ -796,7 +821,8 @@ } \ else \ /* It's an one byte sequence. */ \ - *((uint32_t *) outptr)++ = *inptr++; \ + *((uint32_t *) outptr) = *inptr++; \ + outptr += sizeof (uint32_t); \ } #define LOOP_NEED_FLAGS #include @@ -826,7 +852,8 @@ } \ else \ /* It's an one byte sequence. */ \ - *outptr++ = *((const uint32_t *) inptr)++; \ + *outptr++ = *((const uint32_t *) inptr); \ + inptr += sizeof (uint32_t); \ } #define LOOP_NEED_FLAGS #include @@ -875,13 +902,12 @@ start = outptr; \ *outptr = (unsigned char) (~0xff >> step); \ outptr += step; \ - --step; \ do \ { \ - start[step] = 0x80 | (wc & 0x3f); \ + start[--step] = 0x80 | (wc & 0x3f); \ wc >>= 6; \ } \ - while (--step > 0); \ + while (step > 1); \ start[0] |= wc; \ } \ else \ @@ -963,18 +989,17 @@ } \ else \ { \ - int skipped; \ - \ /* Search the end of this ill-formed UTF-8 character. This \ is the next byte with (x & 0xc0) != 0x80. */ \ - skipped = 0; \ + i = 0; \ do \ - ++skipped; \ - while (inptr + skipped < inend \ - && (*(inptr + skipped) & 0xc0) == 0x80 \ - && skipped < 5); \ + ++i; \ + while (inptr + i < inend \ + && (*(inptr + i) & 0xc0) == 0x80 \ + && i < 5); \ \ - STANDARD_FROM_LOOP_ERR_HANDLER (skipped); \ + errout: \ + STANDARD_FROM_LOOP_ERR_HANDLER (i); \ } \ \ if (__builtin_expect (inptr + cnt > inend, 0)) \ @@ -991,7 +1016,7 @@ break; \ } \ \ - STANDARD_FROM_LOOP_ERR_HANDLER (i); \ + goto errout; \ } \ \ /* Read the possible remaining bytes. */ \ @@ -1013,14 +1038,15 @@ if (i < cnt || (cnt > 2 && (ch >> (5 * cnt - 4)) == 0)) \ { \ /* This is an illegal encoding. */ \ - STANDARD_FROM_LOOP_ERR_HANDLER (i); \ + goto errout; \ } \ \ inptr += cnt; \ } \ \ /* Now adjust the pointers and store the result. */ \ - *((uint32_t *) outptr)++ = ch; \ + *((uint32_t *) outptr) = ch; \ + outptr += sizeof (uint32_t); \ } #define LOOP_NEED_FLAGS @@ -1132,7 +1158,7 @@ #define LOOPFCT FROM_LOOP #define BODY \ { \ - uint16_t u1 = *((const uint16_t *) inptr); \ + uint16_t u1 = get16 (inptr); \ \ if (__builtin_expect (u1 >= 0xd800 && u1 < 0xe000, 0)) \ { \ @@ -1141,7 +1167,8 @@ STANDARD_FROM_LOOP_ERR_HANDLER (2); \ } \ \ - *((uint32_t *) outptr)++ = u1; \ + *((uint32_t *) outptr) = u1; \ + outptr += sizeof (uint32_t); \ inptr += 2; \ } #define LOOP_NEED_FLAGS @@ -1189,7 +1216,8 @@ } \ else \ { \ - *((uint16_t *) outptr)++ = val; \ + put16 (outptr, val); \ + outptr += sizeof (uint16_t); \ inptr += 4; \ } \ } @@ -1214,7 +1242,7 @@ #define LOOPFCT FROM_LOOP #define BODY \ { \ - uint16_t u1 = bswap_16 (*((const uint16_t *) inptr)); \ + uint16_t u1 = bswap_16 (get16 (inptr)); \ \ if (__builtin_expect (u1 >= 0xd800 && u1 < 0xe000, 0)) \ { \ @@ -1230,7 +1258,8 @@ continue; \ } \ \ - *((uint32_t *) outptr)++ = u1; \ + *((uint32_t *) outptr) = u1; \ + outptr += sizeof (uint32_t); \ inptr += 2; \ } #define LOOP_NEED_FLAGS @@ -1279,7 +1308,8 @@ } \ else \ { \ - *((uint16_t *) outptr)++ = bswap_16 (val); \ + put16 (outptr, bswap_16 (val)); \ + outptr += sizeof (uint16_t); \ inptr += 4; \ } \ } Added: haiku/trunk/src/system/libroot/posix/glibc/include/arch/ppc/bits/byteswap.h =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/include/arch/ppc/bits/byteswap.h 2007-10-13 14:00:37 UTC (rev 22532) +++ haiku/trunk/src/system/libroot/posix/glibc/include/arch/ppc/bits/byteswap.h 2007-10-13 15:34:19 UTC (rev 22533) @@ -0,0 +1,84 @@ +/* Macros to swap the order of bytes in integer values. + Copyright (C) 1997, 1998, 2000, 2001, 2002 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#if !defined _BYTESWAP_H && !defined _NETINET_IN_H +# error "Never use directly; include instead." +#endif + +#ifndef _BITS_BYTESWAP_H +#define _BITS_BYTESWAP_H 1 + +/* Swap bytes in 16 bit value. */ +#ifdef __GNUC__ +# define __bswap_16(x) \ + (__extension__ \ + ({ unsigned short int __bsx = (x); \ + ((((__bsx) >> 8) & 0xff) | (((__bsx) & 0xff) << 8)); })) +#else +static __inline unsigned short int +__bswap_16 (unsigned short int __bsx) +{ + return ((((__bsx) >> 8) & 0xff) | (((__bsx) & 0xff) << 8)); +} +#endif + +/* Swap bytes in 32 bit value. */ +#ifdef __GNUC__ +# define __bswap_32(x) \ + (__extension__ \ + ({ unsigned int __bsx = (x); \ + ((((__bsx) & 0xff000000) >> 24) | (((__bsx) & 0x00ff0000) >> 8) | \ + (((__bsx) & 0x0000ff00) << 8) | (((__bsx) & 0x000000ff) << 24)); })) +#else +static __inline unsigned int +__bswap_32 (unsigned int __bsx) +{ + return ((((__bsx) & 0xff000000) >> 24) | (((__bsx) & 0x00ff0000) >> 8) | + (((__bsx) & 0x0000ff00) << 8) | (((__bsx) & 0x000000ff) << 24)); +} +#endif + +#if defined __GNUC__ && __GNUC__ >= 2 +/* Swap bytes in 64 bit value. */ +# define __bswap_constant_64(x) \ + ((((x) & 0xff00000000000000ull) >> 56) \ + | (((x) & 0x00ff000000000000ull) >> 40) \ + | (((x) & 0x0000ff0000000000ull) >> 24) \ + | (((x) & 0x000000ff00000000ull) >> 8) \ + | (((x) & 0x00000000ff000000ull) << 8) \ + | (((x) & 0x0000000000ff0000ull) << 24) \ + | (((x) & 0x000000000000ff00ull) << 40) \ + | (((x) & 0x00000000000000ffull) << 56)) + +# define __bswap_64(x) \ + (__extension__ \ + ({ union { __extension__ unsigned long long int __ll; \ + unsigned int __l[2]; } __w, __r; \ + if (__builtin_constant_p (x)) \ + __r.__ll = __bswap_constant_64 (x); \ + else \ + { \ + __w.__ll = (x); \ + __r.__l[0] = __bswap_32 (__w.__l[1]); \ + __r.__l[1] = __bswap_32 (__w.__l[0]); \ + } \ + __r.__ll; })) +#endif + +#endif /* _BITS_BYTESWAP_H */ Modified: haiku/trunk/src/system/libroot/posix/glibc/include/arch/x86/bits/byteswap.h =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/include/arch/x86/bits/byteswap.h 2007-10-13 14:00:37 UTC (rev 22532) +++ haiku/trunk/src/system/libroot/posix/glibc/include/arch/x86/bits/byteswap.h 2007-10-13 15:34:19 UTC (rev 22533) @@ -1,5 +1,5 @@ /* Macros to swap the order of bytes in integer values. - Copyright (C) 1997, 1998, 2000, 2002 Free Software Foundation, Inc. + Copyright (C) 1997, 1998, 2000, 2002, 2003 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -64,7 +64,8 @@ # if __GNUC__ >= 2 /* To swap the bytes in a word the i486 processors and up provide the `bswap' opcode. On i386 we have to use three instructions. */ -# if !defined __i486__ && !defined __pentium__ && !defined __pentiumpro__ +# if !defined __i486__ && !defined __pentium__ && !defined __pentiumpro__ \ + && !defined __pentium4__ # define __bswap_32(x) \ (__extension__ \ ({ register unsigned int __v, __x = (x); \ Added: haiku/trunk/src/system/libroot/posix/glibc/include/arch/x86/bits/string.h =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/include/arch/x86/bits/string.h 2007-10-13 14:00:37 UTC (rev 22532) +++ haiku/trunk/src/system/libroot/posix/glibc/include/arch/x86/bits/string.h 2007-10-13 15:34:19 UTC (rev 22533) @@ -0,0 +1,922 @@ +/* Optimized, inlined string functions. i386 version. + Copyright (C) 1997,1998,1999,2000,2003 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _STRING_H +# error "Never use directly; include instead." +#endif + +/* The ix86 processors can access unaligned multi-byte variables. */ +#define _STRING_ARCH_unaligned 1 + + +/* We only provide optimizations if the user selects them and if + GNU CC is used. */ +#if !defined __NO_STRING_INLINES && defined __USE_STRING_INLINES \ + && defined __GNUC__ && __GNUC__ >= 2 && !__BOUNDED_POINTERS__ + +#ifndef __STRING_INLINE +# ifdef __cplusplus +# define __STRING_INLINE inline +# else +# define __STRING_INLINE extern __inline +# endif +#endif + + +/* Copy N bytes of SRC to DEST. */ +#define _HAVE_STRING_ARCH_memcpy 1 +#define memcpy(dest, src, n) \ + (__extension__ (__builtin_constant_p (n) \ + ? __memcpy_c ((dest), (src), (n)) \ + : memcpy ((dest), (src), (n)))) +/* This looks horribly ugly, but the compiler can optimize it totally, + as the count is constant. */ +__STRING_INLINE void *__memcpy_c (void *__dest, __const void *__src, + size_t __n); + +__STRING_INLINE void * +__memcpy_c (void *__dest, __const void *__src, size_t __n) +{ + register unsigned long int __d0, __d1, __d2; + union { + unsigned int __ui; + unsigned short int __usi; + unsigned char __uc; + } *__u = __dest; + switch (__n) + { + case 0: + return __dest; + case 1: + __u->__uc = *(const unsigned char *) __src; + return __dest; + case 2: + __u->__usi = *(const unsigned short int *) __src; + return __dest; + case 3: + __u->__usi = *(const unsigned short int *) __src; + __u = (void *) __u + 2; + __u->__uc = *(2 + (const unsigned char *) __src); + return __dest; + case 4: + __u->__ui = *(const unsigned int *) __src; + return __dest; + case 6: + __u->__ui = *(const unsigned int *) __src; + __u = (void *) __u + 4; + __u->__usi = *(2 + (const unsigned short int *) __src); + return __dest; + case 8: + __u->__ui = *(const unsigned int *) __src; + __u = (void *) __u + 4; + __u->__ui = *(1 + (const unsigned int *) __src); + return __dest; + case 12: + __u->__ui = *(const unsigned int *) __src; + __u = (void *) __u + 4; + __u->__ui = *(1 + (const unsigned int *) __src); + __u = (void *) __u + 4; + __u->__ui = *(2 + (const unsigned int *) __src); + return __dest; + case 16: + __u->__ui = *(const unsigned int *) __src; + __u = (void *) __u + 4; + __u->__ui = *(1 + (const unsigned int *) __src); + __u = (void *) __u + 4; + __u->__ui = *(2 + (const unsigned int *) __src); + __u = (void *) __u + 4; + __u->__ui = *(3 + (const unsigned int *) __src); + return __dest; + case 20: + __u->__ui = *(const unsigned int *) __src; + __u = (void *) __u + 4; + __u->__ui = *(1 + (const unsigned int *) __src); + __u = (void *) __u + 4; + __u->__ui = *(2 + (const unsigned int *) __src); + __u = (void *) __u + 4; + __u->__ui = *(3 + (const unsigned int *) __src); + __u = (void *) __u + 4; + __u->__ui = *(4 + (const unsigned int *) __src); + return __dest; + } +#define __COMMON_CODE(x) \ + __asm__ __volatile__ \ + ("cld\n\t" \ + "rep; movsl" \ + x \ + : "=&c" (__d0), "=&D" (__d1), "=&S" (__d2) \ + : "0" (__n / 4), "1" (&__u->__uc), "2" (__src) \ + : "memory"); + + switch (__n % 4) + { + case 0: + __COMMON_CODE (""); + break; + case 1: + __COMMON_CODE ("\n\tmovsb"); + break; + case 2: + __COMMON_CODE ("\n\tmovsw"); + break; + case 3: + __COMMON_CODE ("\n\tmovsw\n\tmovsb"); + break; + } + return __dest; +#undef __COMMON_CODE +} + + +/* Copy N bytes of SRC to DEST, guaranteeing + correct behavior for overlapping strings. */ +#define _HAVE_STRING_ARCH_memmove 1 +#ifndef _FORCE_INLINES +__STRING_INLINE void * +memmove (void *__dest, __const void *__src, size_t __n) +{ + register unsigned long int __d0, __d1, __d2; + if (__dest < __src) + __asm__ __volatile__ + ("cld\n\t" + "rep\n\t" + "movsb" + : "=&c" (__d0), "=&S" (__d1), "=&D" (__d2) + : "0" (__n), "1" (__src), "2" (__dest) + : "memory"); + else + __asm__ __volatile__ + ("std\n\t" + "rep\n\t" + "movsb\n\t" + "cld" + : "=&c" (__d0), "=&S" (__d1), "=&D" (__d2) + : "0" (__n), "1" (__n - 1 + (const char *) __src), + "2" (__n - 1 + (char *) __dest) + : "memory"); + return __dest; +} +#endif + +/* Set N bytes of S to C. */ +#define _HAVE_STRING_ARCH_memset 1 +#define _USE_STRING_ARCH_memset 1 +#define memset(s, c, n) \ + (__extension__ (__builtin_constant_p (c) \ + ? (__builtin_constant_p (n) \ + ? __memset_cc (s, 0x01010101UL * (unsigned char) (c), n) \ + : __memset_cg (s, 0x01010101UL * (unsigned char) (c), n))\ + : __memset_gg (s, c, n))) + +__STRING_INLINE void *__memset_cc (void *__s, unsigned long int __pattern, + size_t __n); + +__STRING_INLINE void * +__memset_cc (void *__s, unsigned long int __pattern, size_t __n) +{ + register unsigned long int __d0, __d1; + union { + unsigned int __ui; + unsigned short int __usi; + unsigned char __uc; + } *__u = __s; + switch (__n) + { + case 0: + return __s; + case 1: + __u->__uc = __pattern; + return __s; + case 2: + __u->__usi = __pattern; + return __s; + case 3: + __u->__usi = __pattern; + __u = __extension__ ((void *) __u + 2); + __u->__uc = __pattern; + return __s; + case 4: + __u->__ui = __pattern; + return __s; + } +#define __COMMON_CODE(x) \ + __asm__ __volatile__ \ + ("cld\n\t" \ + "rep; stosl" \ + x \ + : "=&c" (__d0), "=&D" (__d1) \ + : "a" (__pattern), "0" (__n / 4), "1" (&__u->__uc) \ + : "memory") + + switch (__n % 4) + { + case 0: + __COMMON_CODE (""); + break; + case 1: + __COMMON_CODE ("\n\tstosb"); + break; + case 2: + __COMMON_CODE ("\n\tstosw"); + break; + case 3: + __COMMON_CODE ("\n\tstosw\n\tstosb"); + break; + } + return __s; +#undef __COMMON_CODE +} + +__STRING_INLINE void *__memset_cg (void *__s, unsigned long __c, size_t __n); + +__STRING_INLINE void * +__memset_cg (void *__s, unsigned long __c, size_t __n) +{ + register unsigned long int __d0, __d1; + __asm__ __volatile__ + ("cld\n\t" + "rep; stosl\n\t" + "testb $2,%b3\n\t" + "je 1f\n\t" + "stosw\n" + "1:\n\t" + "testb $1,%b3\n\t" + "je 2f\n\t" + "stosb\n" + "2:" + : "=&c" (__d0), "=&D" (__d1) + : "a" (__c), "q" (__n), "0" (__n / 4), "1" (__s) + : "memory"); + return __s; +} + +__STRING_INLINE void *__memset_gg (void *__s, char __c, size_t __n); + +__STRING_INLINE void * +__memset_gg (void *__s, char __c, size_t __n) +{ + register unsigned long int __d0, __d1; + __asm__ __volatile__ + ("cld\n\t" + "rep; stosb" + : "=&D" (__d0), "=&c" (__d1) + : "a" (__c), "0" (__s), "1" (__n) + : "memory"); + return __s; +} + + + + +/* Search N bytes of S for C. */ +#define _HAVE_STRING_ARCH_memchr 1 +#ifndef _FORCE_INLINES +__STRING_INLINE void * +memchr (__const void *__s, int __c, size_t __n) +{ + register unsigned long int __d0; + register void *__res; + if (__n == 0) + return NULL; + __asm__ __volatile__ + ("cld\n\t" + "repne; scasb\n\t" + "je 1f\n\t" + "movl $1,%0\n" + "1:" + : "=D" (__res), "=&c" (__d0) + : "a" (__c), "0" (__s), "1" (__n), + "m" ( *(struct { __extension__ char __x[__n]; } *)__s) + : "cc"); + return __res - 1; +} +#endif + +#define _HAVE_STRING_ARCH_memrchr 1 +#ifndef _FORCE_INLINES [... truncated: 1901 lines follow ...] From bonefish at mail.berlios.de Sat Oct 13 18:15:49 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sat, 13 Oct 2007 18:15:49 +0200 Subject: [Haiku-commits] r22534 - haiku/trunk/src/servers/registrar Message-ID: <200710131615.l9DGFnML007459@sheep.berlios.de> Author: bonefish Date: 2007-10-13 18:15:49 +0200 (Sat, 13 Oct 2007) New Revision: 22534 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22534&view=rev Modified: haiku/trunk/src/servers/registrar/TRoster.cpp Log: ppInfoList deletes its elements on destruction, and we didn't clear our temporary list after deleting its elements manually. Modified: haiku/trunk/src/servers/registrar/TRoster.cpp =================================================================== --- haiku/trunk/src/servers/registrar/TRoster.cpp 2007-10-13 15:34:19 UTC (rev 22533) +++ haiku/trunk/src/servers/registrar/TRoster.cpp 2007-10-13 16:15:49 UTC (rev 22534) @@ -1279,13 +1279,16 @@ if (!(*it)->IsRunning()) obsoleteApps.AddInfo(*it); } + // remove the apps for (AppInfoList::Iterator it = obsoleteApps.It(); it.IsValid(); ++it) { RemoveApp(*it); delete *it; } + obsoleteApps.MakeEmpty(false); + // don't delete infos a second time + // early pre-registered applications - obsoleteApps.MakeEmpty(); bigtime_t timeLimit = system_time() - kMaximalEarlyPreRegistrationPeriod; for (AppInfoList::Iterator it = fEarlyPreRegisteredApps.It(); it.IsValid(); @@ -1293,11 +1296,14 @@ if ((*it)->registration_time < timeLimit) obsoleteApps.AddInfo(*it); } + // remove the apps for (AppInfoList::Iterator it = obsoleteApps.It(); it.IsValid(); ++it) { fEarlyPreRegisteredApps.RemoveInfo(*it); delete *it; } + obsoleteApps.MakeEmpty(false); + // don't delete infos a second time } // SetShuttingDown From bonefish at mail.berlios.de Sat Oct 13 18:18:47 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sat, 13 Oct 2007 18:18:47 +0200 Subject: [Haiku-commits] r22535 - haiku/trunk/src/kits/app Message-ID: <200710131618.l9DGIlNr007625@sheep.berlios.de> Author: bonefish Date: 2007-10-13 18:18:47 +0200 (Sat, 13 Oct 2007) New Revision: 22535 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22535&view=rev Modified: haiku/trunk/src/kits/app/RegistrarThreadManager.cpp Log: Fixed some instances of incorrect erase() while iterating. Shouldn't have been a problem though, since the iterated container is a list. Modified: haiku/trunk/src/kits/app/RegistrarThreadManager.cpp =================================================================== --- haiku/trunk/src/kits/app/RegistrarThreadManager.cpp 2007-10-13 16:15:49 UTC (rev 22534) +++ haiku/trunk/src/kits/app/RegistrarThreadManager.cpp 2007-10-13 16:18:47 UTC (rev 22535) @@ -94,12 +94,13 @@ err = thread->Run(); if (err) { std::list::iterator i; - for (i = fThreads.begin(); i != fThreads.end(); i++) { + for (i = fThreads.begin(); i != fThreads.end();) { if ((*i) == thread) { - fThreads.erase(i); + i = fThreads.erase(i); fThreadCount--; break; - } + } else + ++i; } } } @@ -120,22 +121,19 @@ { std::list::iterator i; for (i = fThreads.begin(); i != fThreads.end(); ) { - std::list::iterator next = i; - next++; - if (*i) { if ((*i)->IsFinished()) { DBG(OUT("RegistrarThreadManager::CleanupThreads(): Cleaning up thread %ld\n", (*i)->Id())); RemoveThread(i); - } + // adjusts i + } else + ++i; } else { OUT("WARNING: RegistrarThreadManager::CleanupThreads(): NULL mime_update_thread_shared_data " "pointer found in and removed from RegistrarThreadManager::fThreads list\n"); - fThreads.erase(i); + i = fThreads.erase(i); } - - i = next; } return B_OK; } @@ -152,26 +150,23 @@ { std::list::iterator i; for (i = fThreads.begin(); i != fThreads.end(); ) { - std::list::iterator next = i; - next++; - if (*i) { if ((*i)->IsFinished()) { DBG(OUT("RegistrarThreadManager::ShutdownThreads(): Cleaning up thread %ld\n", (*i)->Id())); RemoveThread(i); + // adjusts i } else { DBG(OUT("RegistrarThreadManager::ShutdownThreads(): Shutting down thread %ld\n", (*i)->Id())); (*i)->AskToExit(); + ++i; } } else { OUT("WARNING: RegistrarThreadManager::ShutdownThreads(): NULL mime_update_thread_shared_data " "pointer found in and removed from RegistrarThreadManager::fThreads list\n"); - fThreads.erase(i); + i = fThreads.erase(i); } - - i = next; } /*! \todo We may want to iterate back through the list at this point, @@ -193,9 +188,6 @@ { std::list::iterator i; for (i = fThreads.begin(); i != fThreads.end(); ) { - std::list::iterator next = i; - next++; - if (*i) { if (!(*i)->IsFinished()) { DBG(OUT("RegistrarThreadManager::KillThreads(): Killing thread %ld\n", @@ -208,13 +200,12 @@ DBG(OUT("RegistrarThreadManager::KillThreads(): Cleaning up thread %ld\n", (*i)->Id())); RemoveThread(i); + // adjusts i } else { OUT("WARNING: RegistrarThreadManager::KillThreads(): NULL mime_update_thread_shared_data " "pointer found in and removed from RegistrarThreadManager::fThreads list\n"); - fThreads.erase(i); + i = fThreads.erase(i); } - - i = next; } return B_OK; } From bonefish at mail.berlios.de Sat Oct 13 19:14:18 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sat, 13 Oct 2007 19:14:18 +0200 Subject: [Haiku-commits] r22536 - haiku/trunk/src/apps/glteapot Message-ID: <200710131714.l9DHEIUH011989@sheep.berlios.de> Author: bonefish Date: 2007-10-13 19:14:17 +0200 (Sat, 13 Oct 2007) New Revision: 22536 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22536&view=rev Modified: haiku/trunk/src/apps/glteapot/GLObject.cpp Log: Patch by Vasilis Kaoutsis: Fixed warning. Modified: haiku/trunk/src/apps/glteapot/GLObject.cpp =================================================================== --- haiku/trunk/src/apps/glteapot/GLObject.cpp 2007-10-13 16:18:47 UTC (rev 22535) +++ haiku/trunk/src/apps/glteapot/GLObject.cpp 2007-10-13 17:14:17 UTC (rev 22536) @@ -60,12 +60,13 @@ GLObject::GLObject(ObjectView *ov) - : rotX(0), + : + rotX(0), rotY(0), + spinX(2), + spinY(2), lastRotX(0), lastRotY(0), - spinX(2), - spinY(2), x(0), y(0), z(-2.0), From bonefish at mail.berlios.de Sat Oct 13 19:18:38 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sat, 13 Oct 2007 19:18:38 +0200 Subject: [Haiku-commits] r22537 - in haiku/trunk/src/system/libroot/posix: glibc/libio pthread string sys time unistd Message-ID: <200710131718.l9DHIcPd029764@sheep.berlios.de> Author: bonefish Date: 2007-10-13 19:18:34 +0200 (Sat, 13 Oct 2007) New Revision: 22537 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22537&view=rev Modified: haiku/trunk/src/system/libroot/posix/glibc/libio/flockfile.c haiku/trunk/src/system/libroot/posix/pthread/pthread_mutexattr.c haiku/trunk/src/system/libroot/posix/string/strchrnul.c haiku/trunk/src/system/libroot/posix/string/strdup.c haiku/trunk/src/system/libroot/posix/sys/mkdir.c haiku/trunk/src/system/libroot/posix/sys/select.c haiku/trunk/src/system/libroot/posix/time/asctime.c haiku/trunk/src/system/libroot/posix/time/time.c haiku/trunk/src/system/libroot/posix/unistd/access.c haiku/trunk/src/system/libroot/posix/unistd/dup.c haiku/trunk/src/system/libroot/posix/unistd/ioctl.c haiku/trunk/src/system/libroot/posix/unistd/pipe.c haiku/trunk/src/system/libroot/posix/unistd/read.c haiku/trunk/src/system/libroot/posix/unistd/ttyname.c haiku/trunk/src/system/libroot/posix/unistd/write.c Log: Patch by Vasilis Kaoutsis: Style cleanup, "OpenBeOS license" -> "MIT license". Modified: haiku/trunk/src/system/libroot/posix/glibc/libio/flockfile.c =================================================================== --- haiku/trunk/src/system/libroot/posix/glibc/libio/flockfile.c 2007-10-13 17:14:17 UTC (rev 22536) +++ haiku/trunk/src/system/libroot/posix/glibc/libio/flockfile.c 2007-10-13 17:18:34 UTC (rev 22537) @@ -1,7 +1,7 @@ /* -** Copyright 2003, Axel D?rfler, axeld at pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ + * Copyright 2003-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ #include "libioP.h" Modified: haiku/trunk/src/system/libroot/posix/pthread/pthread_mutexattr.c =================================================================== --- haiku/trunk/src/system/libroot/posix/pthread/pthread_mutexattr.c 2007-10-13 17:14:17 UTC (rev 22536) +++ haiku/trunk/src/system/libroot/posix/pthread/pthread_mutexattr.c 2007-10-13 17:18:34 UTC (rev 22537) @@ -1,7 +1,7 @@ /* -** Copyright 2003, Axel D?rfler, axeld at pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ + * Copyright 2003-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ #include @@ -155,4 +155,3 @@ // not implemented return B_NOT_ALLOWED; } - Modified: haiku/trunk/src/system/libroot/posix/string/strchrnul.c =================================================================== --- haiku/trunk/src/system/libroot/posix/string/strchrnul.c 2007-10-13 17:14:17 UTC (rev 22536) +++ haiku/trunk/src/system/libroot/posix/string/strchrnul.c 2007-10-13 17:18:34 UTC (rev 22537) @@ -1,19 +1,18 @@ /* -** Copyright 2003, Axel D?rfler, axeld at pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ + * Copyright 2003-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ #include #include -char * -strchrnul(const char *string, int c) +char* +strchrnul(const char* string, int c) { while (string[0] != (char)c && string[0]) string++; - return (char *)string; + return (char*)string; } - Modified: haiku/trunk/src/system/libroot/posix/string/strdup.c =================================================================== --- haiku/trunk/src/system/libroot/posix/string/strdup.c 2007-10-13 17:14:17 UTC (rev 22536) +++ haiku/trunk/src/system/libroot/posix/string/strdup.c 2007-10-13 17:18:34 UTC (rev 22537) @@ -1,17 +1,17 @@ /* -** Copyright 2003, Axel D?rfler, axeld at pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ + * Copyright 2003-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ #include #include -char * +char* strdup(const char *string) { - char *copied; + char* copied; size_t length; // unlike the standard strdup() function, the BeOS implementation @@ -27,4 +27,3 @@ memcpy(copied, string, length); return copied; } - Modified: haiku/trunk/src/system/libroot/posix/sys/mkdir.c =================================================================== --- haiku/trunk/src/system/libroot/posix/sys/mkdir.c 2007-10-13 17:14:17 UTC (rev 22536) +++ haiku/trunk/src/system/libroot/posix/sys/mkdir.c 2007-10-13 17:18:34 UTC (rev 22537) @@ -1,7 +1,7 @@ /* -** Copyright 2002-2004, Axel D?rfler, axeld at pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ + * Copyright 2002-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ #include @@ -18,10 +18,9 @@ int -mkdir(const char *path, mode_t mode) +mkdir(const char* path, mode_t mode) { status_t status = _kern_create_dir(-1, path, mode); RETURN_AND_SET_ERRNO(status); } - Modified: haiku/trunk/src/system/libroot/posix/sys/select.c =================================================================== --- haiku/trunk/src/system/libroot/posix/sys/select.c 2007-10-13 17:14:17 UTC (rev 22536) +++ haiku/trunk/src/system/libroot/posix/sys/select.c 2007-10-13 17:18:34 UTC (rev 22537) @@ -1,6 +1,6 @@ /* * Copyright 2002-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. - * Distributed under the terms of the OpenBeOS License. + * Distributed under the terms of the MIT License. */ Modified: haiku/trunk/src/system/libroot/posix/time/asctime.c =================================================================== --- haiku/trunk/src/system/libroot/posix/time/asctime.c 2007-10-13 17:14:17 UTC (rev 22536) +++ haiku/trunk/src/system/libroot/posix/time/asctime.c 2007-10-13 17:18:34 UTC (rev 22537) @@ -1,15 +1,15 @@ /* -** Copyright 2004, Axel D?rfler, axeld at pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ + * Copyright 2004-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ #include #include -static char * -print_time(char *buffer, size_t bufferSize, const struct tm *tm) +static char* +print_time(char* buffer, size_t bufferSize, const struct tm* tm) { // ToDo: this should probably use the locale kit to get these names @@ -31,8 +31,8 @@ } -char * -asctime(const struct tm *tm) +char* +asctime(const struct tm* tm) { static char buffer[28]; // is enough to hold normal dates @@ -41,10 +41,9 @@ } -char * -asctime_r(const struct tm *tm, char *buffer) +char* +asctime_r(const struct tm* tm, char* buffer) { return print_time(buffer, 26, tm); // 26 bytes seems to be required by the standard, so we can't write more } - Modified: haiku/trunk/src/system/libroot/posix/time/time.c =================================================================== --- haiku/trunk/src/system/libroot/posix/time/time.c 2007-10-13 17:14:17 UTC (rev 22536) +++ haiku/trunk/src/system/libroot/posix/time/time.c 2007-10-13 17:18:34 UTC (rev 22537) @@ -1,7 +1,7 @@ /* -** Copyright 2003, Axel D?rfler, axeld at pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ + * Copyright 2003-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ #include @@ -9,7 +9,7 @@ time_t -time(time_t *timer) +time(time_t* timer) { time_t secs = real_time_clock(); @@ -18,4 +18,3 @@ return secs; } - Modified: haiku/trunk/src/system/libroot/posix/unistd/access.c =================================================================== --- haiku/trunk/src/system/libroot/posix/unistd/access.c 2007-10-13 17:14:17 UTC (rev 22536) +++ haiku/trunk/src/system/libroot/posix/unistd/access.c 2007-10-13 17:18:34 UTC (rev 22537) @@ -1,7 +1,7 @@ /* -** Copyright 2002-2004, Axel D?rfler, axeld at pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ + * Copyright 2002-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ #include @@ -18,10 +18,9 @@ int -access(const char *path, int accessMode) +access(const char* path, int accessMode) { status_t status = _kern_access(path, accessMode); RETURN_AND_SET_ERRNO(status); } - Modified: haiku/trunk/src/system/libroot/posix/unistd/dup.c =================================================================== --- haiku/trunk/src/system/libroot/posix/unistd/dup.c 2007-10-13 17:14:17 UTC (rev 22536) +++ haiku/trunk/src/system/libroot/posix/unistd/dup.c 2007-10-13 17:18:34 UTC (rev 22537) @@ -1,7 +1,7 @@ /* -** Copyright 2004, Axel D?rfler, axeld at pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ + * Copyright 2004-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ #include Modified: haiku/trunk/src/system/libroot/posix/unistd/ioctl.c =================================================================== --- haiku/trunk/src/system/libroot/posix/unistd/ioctl.c 2007-10-13 17:14:17 UTC (rev 22536) +++ haiku/trunk/src/system/libroot/posix/unistd/ioctl.c 2007-10-13 17:18:34 UTC (rev 22537) @@ -1,7 +1,7 @@ /* -** Copyright 2002-2004, Axel D?rfler, axeld at pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ + * Copyright 2002-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ #include @@ -22,12 +22,12 @@ ioctl(int fd, ulong cmd, ...) { va_list args; - void *argument; + void* argument; size_t size; int status; va_start(args, cmd); - argument = va_arg(args, void *); + argument = va_arg(args, void*); size = va_arg(args, size_t); va_end(args); @@ -35,4 +35,3 @@ RETURN_AND_SET_ERRNO(status) } - Modified: haiku/trunk/src/system/libroot/posix/unistd/pipe.c =================================================================== --- haiku/trunk/src/system/libroot/posix/unistd/pipe.c 2007-10-13 17:14:17 UTC (rev 22536) +++ haiku/trunk/src/system/libroot/posix/unistd/pipe.c 2007-10-13 17:18:34 UTC (rev 22537) @@ -1,7 +1,7 @@ /* -** Copyright 2003, Axel D?rfler, axeld at pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ + * Copyright 2003-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ #include @@ -34,4 +34,3 @@ return 0; } - Modified: haiku/trunk/src/system/libroot/posix/unistd/read.c =================================================================== --- haiku/trunk/src/system/libroot/posix/unistd/read.c 2007-10-13 17:14:17 UTC (rev 22536) +++ haiku/trunk/src/system/libroot/posix/unistd/read.c 2007-10-13 17:18:34 UTC (rev 22537) @@ -1,12 +1,12 @@ /* -** Copyright 2001, Manuel J. Petit. All rights reserved. -** Distributed under the terms of the NewOS License. -*/ + * Copyright 2001, Manuel J. Petit. All rights reserved. + * Distributed under the terms of the NewOS License. + */ /* -** Copyright 2002, Axel D?rfler, axeld at pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ + * Copyright 2002-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ #include @@ -23,7 +23,7 @@ ssize_t -read(int fd, void *buffer, size_t bufferSize) +read(int fd, void* buffer, size_t bufferSize) { ssize_t status = _kern_read(fd, -1, buffer, bufferSize); @@ -32,7 +32,7 @@ ssize_t -read_pos(int fd, off_t pos, void *buffer, size_t bufferSize) +read_pos(int fd, off_t pos, void* buffer, size_t bufferSize) { ssize_t status; if (pos < 0) { @@ -46,7 +46,7 @@ ssize_t -pread(int fd, void *buffer, size_t bufferSize, off_t pos) +pread(int fd, void* buffer, size_t bufferSize, off_t pos) { ssize_t status; if (pos < 0) { @@ -57,4 +57,3 @@ RETURN_AND_SET_ERRNO(status); } - Modified: haiku/trunk/src/system/libroot/posix/unistd/ttyname.c =================================================================== --- haiku/trunk/src/system/libroot/posix/unistd/ttyname.c 2007-10-13 17:14:17 UTC (rev 22536) +++ haiku/trunk/src/system/libroot/posix/unistd/ttyname.c 2007-10-13 17:18:34 UTC (rev 22537) @@ -1,8 +1,8 @@ /* -** Copyright 2003, Daniel Reinhold, danielre at users.sf.net. All rights reserved. -** Copyright 2007, Fran?ois Revol, mmu_man at users.sf.net. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ + * Copyright 2003, Daniel Reinhold, danielre at users.sf.net. All rights reserved. + * Copyright 2007, Fran?ois Revol, mmu_man at users.sf.net. All rights reserved. + * Distributed under the terms of the MIT License. + */ #include Modified: haiku/trunk/src/system/libroot/posix/unistd/write.c =================================================================== --- haiku/trunk/src/system/libroot/posix/unistd/write.c 2007-10-13 17:14:17 UTC (rev 22536) +++ haiku/trunk/src/system/libroot/posix/unistd/write.c 2007-10-13 17:18:34 UTC (rev 22537) @@ -1,10 +1,10 @@ /* -** Copyright 2002-2004, Axel D?rfler, axeld at pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -** -** Copyright 2001, Manuel J. Petit. All rights reserved. -** Distributed under the terms of the NewOS License. -*/ + * Copyright 2002-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Copyright 2001, Manuel J. Petit. All rights reserved. + * Distributed under the terms of the NewOS License. + */ #include @@ -55,4 +55,3 @@ RETURN_AND_SET_ERRNO(status); } - From bonefish at mail.berlios.de Sat Oct 13 23:13:03 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sat, 13 Oct 2007 23:13:03 +0200 Subject: [Haiku-commits] r22538 - in haiku/trunk: headers/private/storage src/kits/storage Message-ID: <200710132113.l9DLD3d5012750@sheep.berlios.de> Author: bonefish Date: 2007-10-13 23:13:02 +0200 (Sat, 13 Oct 2007) New Revision: 22538 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22538&view=rev Modified: haiku/trunk/headers/private/storage/Partition.h haiku/trunk/src/kits/storage/Partition.cpp Log: * Added fDelegate member. * Removed private AutoDeleter class. The shared ArrayDeleter is used instead. Modified: haiku/trunk/headers/private/storage/Partition.h =================================================================== --- haiku/trunk/headers/private/storage/Partition.h 2007-10-13 17:18:34 UTC (rev 22537) +++ haiku/trunk/headers/private/storage/Partition.h 2007-10-13 21:13:02 UTC (rev 22538) @@ -173,9 +173,10 @@ friend class BDiskSystem; friend class BMutablePartition; - BDiskDevice *fDevice; - BPartition *fParent; - user_partition_data *fPartitionData; + BDiskDevice* fDevice; + BPartition* fParent; + user_partition_data* fPartitionData; + Delegate* fDelegate; }; #endif // _PARTITION_H Modified: haiku/trunk/src/kits/storage/Partition.cpp =================================================================== --- haiku/trunk/src/kits/storage/Partition.cpp 2007-10-13 17:18:34 UTC (rev 22537) +++ haiku/trunk/src/kits/storage/Partition.cpp 2007-10-13 21:13:02 UTC (rev 22538) @@ -6,10 +6,11 @@ * Ingo Weinhold, bonefish at cs.tu-berlin.de */ +#include +#include +#include +#include -#include -#include - #include #include #include @@ -23,12 +24,12 @@ #include #include -#include -#include -#include -#include +#include +#include +#include + using std::nothrow; /*! \class BPartition @@ -41,33 +42,7 @@ (\see IsEmpty()). */ -// AutoDeleter -/*! \brief Helper class deleting objects automatically. -*/ -template -class AutoDeleter { -public: - inline AutoDeleter(C *data = NULL, bool array = false) - : fData(data), fArray(array) {} - inline ~AutoDeleter() - { - if (fArray) - delete[] fData; - else - delete fData; - } - - inline void SetTo(C *data, bool array = false) - { - fData = data; - fArray = array; - } - - C *fData; - bool fArray; -}; - // compare_string /*! \brief \c NULL aware strcmp(). @@ -97,7 +72,8 @@ BPartition::BPartition() : fDevice(NULL), fParent(NULL), - fPartitionData(NULL) + fPartitionData(NULL), + fDelegate(NULL) { } @@ -739,14 +715,14 @@ int32 descendantCount = _CountDescendants(); partition_id *unmovableIDs = NULL; partition_id *needUnmountingIDs = NULL; - AutoDeleter deleter1; - AutoDeleter deleter2; + ArrayDeleter deleter1; + ArrayDeleter deleter2; if (descendantCount > 0) { // allocate arrays unmovableIDs = new(nothrow) partition_id[descendantCount]; needUnmountingIDs = new(nothrow) partition_id[descendantCount]; - deleter1.SetTo(unmovableIDs, true); - deleter2.SetTo(needUnmountingIDs, true); + deleter1.SetTo(unmovableIDs); + deleter2.SetTo(needUnmountingIDs); if (!unmovableIDs || !needUnmountingIDs) return false; // init arrays From bonefish at mail.berlios.de Sat Oct 13 23:17:28 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sat, 13 Oct 2007 23:17:28 +0200 Subject: [Haiku-commits] r22539 - in haiku/trunk: headers/private/storage src/kits/storage Message-ID: <200710132117.l9DLHS2Z013061@sheep.berlios.de> Author: bonefish Date: 2007-10-13 23:17:26 +0200 (Sat, 13 Oct 2007) New Revision: 22539 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22539&view=rev Modified: haiku/trunk/headers/private/storage/PartitioningInfo.h haiku/trunk/src/kits/storage/PartitioningInfo.cpp Log: The info about partitionable space will be provided by the userland disk system add-ons. First work to make this class usable for them. Modified: haiku/trunk/headers/private/storage/PartitioningInfo.h =================================================================== --- haiku/trunk/headers/private/storage/PartitioningInfo.h 2007-10-13 21:13:02 UTC (rev 22538) +++ haiku/trunk/headers/private/storage/PartitioningInfo.h 2007-10-13 21:17:26 UTC (rev 22539) @@ -12,25 +12,35 @@ class BPartitioningInfo { public: - BPartitioningInfo(); - virtual ~BPartitioningInfo(); + BPartitioningInfo(); + virtual ~BPartitioningInfo(); - void Unset(); + status_t SetTo(off_t offset, off_t size); + void Unset(); - partition_id PartitionID() const; + status_t ExcludeOccupiedSpace(off_t offset, + off_t size); - status_t GetPartitionableSpaceAt(int32 index, off_t *offset, - off_t *size) const; - int32 CountPartitionableSpaces() const; +// TODO: We don't need the partition ID. + partition_id PartitionID() const; + status_t GetPartitionableSpaceAt(int32 index, + off_t* offset, off_t*size) const; + int32 CountPartitionableSpaces() const; + private: - status_t _SetTo(partition_id partition, int32 changeCounter); + status_t _SetTo(partition_id partition, + int32 changeCounter); + status_t _InsertSpaces(int32 index, int32 count); + void _RemoveSpaces(int32 index, int32 count); + friend class BPartition; - partition_id fPartitionID; - partitionable_space_data *fSpaces; - int32 fCount; + partition_id fPartitionID; + partitionable_space_data* fSpaces; + int32 fCount; + int32 fCapacity; }; #endif // _PARTITIONING_INFO_H Modified: haiku/trunk/src/kits/storage/PartitioningInfo.cpp =================================================================== --- haiku/trunk/src/kits/storage/PartitioningInfo.cpp 2007-10-13 21:13:02 UTC (rev 22538) +++ haiku/trunk/src/kits/storage/PartitioningInfo.cpp 2007-10-13 21:17:26 UTC (rev 22539) @@ -3,6 +3,8 @@ // by the OpenBeOS license. //--------------------------------------------------------------------- +#include + #include #include @@ -10,22 +12,53 @@ #include #include + using namespace std; + // constructor BPartitioningInfo::BPartitioningInfo() : fPartitionID(-1), fSpaces(NULL), - fCount(0) + fCount(0), + fCapacity(0) { } + // destructor BPartitioningInfo::~BPartitioningInfo() { Unset(); } + +// SetTo +status_t +BPartitioningInfo::SetTo(off_t offset, off_t size) +{ + fPartitionID = -1; + delete[] fSpaces; + + if (size > 0) { + fSpaces = new(nothrow) partitionable_space_data[1]; + if (!fSpaces) + return B_NO_MEMORY; + + fCount = 1; + fSpaces[0].offset = offset; + fSpaces[0].size = size; + } else { + fSpaces = NULL; + fCount = 0; + } + + fCapacity = fCount; + + return B_OK; +} + + // Unset void BPartitioningInfo::Unset() @@ -34,8 +67,80 @@ fPartitionID = -1; fSpaces = NULL; fCount = 0; + fCapacity = 0; } + +// ExcludeOccupiedSpace +status_t +BPartitioningInfo::ExcludeOccupiedSpace(off_t offset, off_t size) +{ + if (size <= 0) + return B_OK; + + int32 leftIndex = -1; + int32 rightIndex = -1; + for (int32 i = 0; i < fCount; i++) { + if (leftIndex == -1 + && offset < fSpaces[i].offset + fSpaces[i].size) { + leftIndex = i; + } + + if (fSpaces[i].offset < offset + size) + rightIndex = i; + } + + // If there's no intersection with any free space, we're done. + if (leftIndex == -1 || rightIndex == -1 || leftIndex > rightIndex) + return B_OK; + + partitionable_space_data& leftSpace = fSpaces[leftIndex]; + partitionable_space_data& rightSpace = fSpaces[rightIndex]; + + off_t rightSpaceEnd = rightSpace.offset + rightSpace.size; + + // special case: split a single space in two + if (leftIndex == rightIndex && leftSpace.offset < offset + && rightSpaceEnd > offset + size) { + // add a space after this one + status_t error = _InsertSpaces(leftIndex + 1, 1); + if (error != B_OK) + return error; + + partitionable_space_data& space = fSpaces[leftIndex]; + partitionable_space_data& newSpace = fSpaces[leftIndex + 1]; + + space.size = offset - space.offset; + + newSpace.offset = offset + size; + newSpace.size = rightSpaceEnd - newSpace.offset; + + return B_OK; + } + + // check whether the first affected space is eaten completely + int32 deleteFirst = leftIndex; + if (leftSpace.offset < offset) { + leftSpace.size = offset - leftSpace.offset; + deleteFirst++; + } + + // check whether the last affected space is eaten completely + int32 deleteLast = rightIndex; + if (rightSpaceEnd > offset + size) { + rightSpace.offset = offset + size; + rightSpace.size = rightSpaceEnd - rightSpace.offset; + deleteLast--; + } + + // remove all spaces that are completely eaten + if (deleteFirst <= deleteLast) + _RemoveSpaces(deleteFirst, deleteLast - deleteFirst + 1); + + return B_OK; +} + + // PartitionID partition_id BPartitioningInfo::PartitionID() const @@ -43,6 +148,7 @@ return fPartitionID; } + // GetPartitionableSpaceAt status_t BPartitioningInfo::GetPartitionableSpaceAt(int32 index, off_t *offset, @@ -55,6 +161,7 @@ return B_OK; } + // CountPartitionableSpaces int32 BPartitioningInfo::CountPartitionableSpaces() const @@ -62,6 +169,7 @@ return fCount; } + // _SetTo status_t BPartitioningInfo::_SetTo(partition_id partition, int32 changeCounter) @@ -100,3 +208,55 @@ return error; } + +// _InsertSpaces +status_t +BPartitioningInfo::_InsertSpaces(int32 index, int32 count) +{ + if (index <= 0 || index > fCount || count <= 0) + return B_BAD_VALUE; + + // If the capacity is sufficient, we just need to copy the spaces to create + // a gap. + if (fCount + count <= fCapacity) { + memmove(fSpaces + index + count, fSpaces + index, fCount - index); + fCount += count; + return B_OK; + } + + // alloc new array + int32 capacity = (fCount + count) * 2; + // add a bit room for further resizing + + partitionable_space_data* spaces + = new(nothrow) partitionable_space_data[capacity]; + if (!spaces) + return B_NO_MEMORY; + + // copy items + memcpy(spaces, fSpaces, index); + memcpy(spaces + index + count, fSpaces + index, fCount - index); + + delete[] fSpaces; + fSpaces = spaces; + fCapacity = capacity; + fCount += count; + + return B_OK; +} + + +// _RemoveSpaces +void +BPartitioningInfo::_RemoveSpaces(int32 index, int32 count) +{ + if (index <= 0 || count <= 0 || index + count > fCount) + return; + + if (count < fCount) { + int32 endIndex = index + count; + memmove(fSpaces + index, fSpaces + endIndex, fCount - endIndex); + } + + fCount -= count; +} From bonefish at mail.berlios.de Sat Oct 13 23:32:44 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sat, 13 Oct 2007 23:32:44 +0200 Subject: [Haiku-commits] r22541 - haiku/trunk/src/add-ons/kernel/partitioning_systems/intel Message-ID: <200710132132.l9DLWiGx014032@sheep.berlios.de> Author: bonefish Date: 2007-10-13 23:32:43 +0200 (Sat, 13 Oct 2007) New Revision: 22541 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22541&view=rev Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMap.cpp haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMap.h Log: Added a few handy methods. The PartitionType::Set*() methods return bool (valid), now. Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMap.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMap.cpp 2007-10-13 21:29:33 UTC (rev 22540) +++ haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMap.cpp 2007-10-13 21:32:43 UTC (rev 22541) @@ -193,11 +193,12 @@ \brief Sets the \a type via its ID. \param type ID of the partition type, it is in the range [0..255]. */ -void +bool PartitionType::SetType(uint8 type) { fType = type; fValid = partition_type_string(type); + return fValid; } // SetType @@ -205,17 +206,18 @@ \brief Sets the type via its string name. \param typeName Name of the partition type. */ -void +bool PartitionType::SetType(const char *typeName) { for (int32 i = 0; kPartitionTypes[i].name ; i++) { if (!strcmp(typeName, kPartitionTypes[i].name)) { fType = kPartitionTypes[i].type; fValid = true; - return; + return fValid; } } fValid = false; + return fValid; } // SetContentType @@ -223,17 +225,18 @@ \brief Converts content type to the partition type that fits best. \param content_type Name of the content type, it is standardized by system. */ -void +bool PartitionType::SetContentType(const char *contentType) { for (int32 i = 0; kPartitionContentTypes[i].name ; i++) { if (!strcmp(contentType, kPartitionContentTypes[i].name)) { fType = kPartitionContentTypes[i].type; fValid = true; - return; + return fValid; } } fValid = false; + return fValid; } // FindNext @@ -314,15 +317,30 @@ off_t baseOffset) { TRACE(("Partition::SetTo(): active: %x\n", descriptor->active)); + SetTo(baseOffset + (off_t)descriptor->start * SECTOR_SIZE, + (off_t)descriptor->size * SECTOR_SIZE, + descriptor->type, + descriptor->active, + ptsOffset); +} + + +// SetTo +void +Partition::SetTo(off_t offset, off_t size, uint8 type, bool active, + off_t ptsOffset) +{ fPTSOffset = ptsOffset; - fOffset = baseOffset + (off_t)descriptor->start * SECTOR_SIZE; - fSize = (off_t)descriptor->size * SECTOR_SIZE; - fType = descriptor->type; - fActive = descriptor->active; + fOffset = offset; + fSize = size; + fType = type; + fActive = active; + if (fSize == 0) Unset(); } + // Unset void Partition::Unset() @@ -394,6 +412,16 @@ Partition::SetTo(descriptor, ptsOffset, 0); } + +// SetTo +void +PrimaryPartition::SetTo(off_t offset, off_t size, uint8 type, bool active) +{ + Unset(); + Partition::SetTo(offset, size, type, active, 0); +} + + // Unset void PrimaryPartition::Unset() @@ -527,6 +555,20 @@ } } + +// SetTo +void +LogicalPartition::SetTo(off_t offset, off_t size, uint8 type, bool active, + off_t ptsOffset, PrimaryPartition *primary) +{ + Unset(); + if (primary) { + Partition::SetTo(offset, size, type, active, ptsOffset); + fPrimary = primary; + } +} + + // Unset void LogicalPartition::Unset() @@ -597,6 +639,33 @@ } +// CountNonEmptyPrimaryPartitions +int32 +PartitionMap::CountNonEmptyPrimaryPartitions() const +{ + int32 count = 0; + for (int32 i = 0; i < 4; i++) { + if (!fPrimaries[i].IsEmpty()) + count++; + } + + return count; +} + + +// ExtendedPartitionIndex +int32 +PartitionMap::ExtendedPartitionIndex() const +{ + for (int32 i = 0; i < 4; i++) { + if (fPrimaries[i].IsExtended()) + return i; + } + + return -1; +} + + // CountPartitions int32 PartitionMap::CountPartitions() const Modified: haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMap.h =================================================================== --- haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMap.h 2007-10-13 21:29:33 UTC (rev 22540) +++ haiku/trunk/src/add-ons/kernel/partitioning_systems/intel/PartitionMap.h 2007-10-13 21:32:43 UTC (rev 22541) @@ -101,9 +101,9 @@ public: PartitionType(); - void SetType(uint8 type); - void SetType(const char *typeName); - void SetContentType(const char *contentType); + bool SetType(uint8 type); + bool SetType(const char *typeName); + bool SetContentType(const char *contentType); bool IsValid() const { return fValid; } bool IsEmpty() const { return is_empty_type(fType); } @@ -127,6 +127,8 @@ void SetTo(const partition_descriptor *descriptor, off_t ptsOffset, off_t baseOffset); + void SetTo(off_t offset, off_t size, uint8 type, bool active, + off_t ptsOffset); void Unset(); bool IsEmpty() const { return is_empty_type(fType); } @@ -167,6 +169,7 @@ PrimaryPartition(); void SetTo(const partition_descriptor *descriptor, off_t ptsOffset); + void SetTo(off_t offset, off_t size, uint8 type, bool active); void Unset(); status_t Assign(const PrimaryPartition& other); @@ -197,6 +200,8 @@ void SetTo(const partition_descriptor *descriptor, off_t ptsOffset, PrimaryPartition *primary); + void SetTo(off_t offset, off_t size, uint8 type, bool active, + off_t ptsOffset, PrimaryPartition *primary); void Unset(); void SetPrimaryPartition(PrimaryPartition *primary) { fPrimary = primary; } @@ -227,7 +232,10 @@ PrimaryPartition *PrimaryPartitionAt(int32 index); const PrimaryPartition *PrimaryPartitionAt(int32 index) const; int32 IndexOfPrimaryPartition(const PrimaryPartition* partition) const; + int32 CountNonEmptyPrimaryPartitions() const; + int32 ExtendedPartitionIndex() const; + int32 CountPartitions() const; int32 CountNonEmptyPartitions() const; Partition *PartitionAt(int32 index); From bonefish at mail.berlios.de Sat Oct 13 23:34:22 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sat, 13 Oct 2007 23:34:22 +0200 Subject: [Haiku-commits] r22542 - in haiku/trunk/src/add-ons: . disk_systems disk_systems/intel Message-ID: <200710132134.l9DLYMqw014121@sheep.berlios.de> Author: bonefish Date: 2007-10-13 23:34:15 +0200 (Sat, 13 Oct 2007) New Revision: 22542 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22542&view=rev Added: haiku/trunk/src/add-ons/disk_systems/ haiku/trunk/src/add-ons/disk_systems/intel/ haiku/trunk/src/add-ons/disk_systems/intel/ExtendedPartitionAddOn.cpp haiku/trunk/src/add-ons/disk_systems/intel/ExtendedPartitionAddOn.h haiku/trunk/src/add-ons/disk_systems/intel/IntelDiskSystem.cpp haiku/trunk/src/add-ons/disk_systems/intel/IntelDiskSystem.h haiku/trunk/src/add-ons/disk_systems/intel/Jamfile haiku/trunk/src/add-ons/disk_systems/intel/PartitionMapAddOn.cpp haiku/trunk/src/add-ons/disk_systems/intel/PartitionMapAddOn.h Modified: haiku/trunk/src/add-ons/Jamfile Log: Beginnings of a userland intel disk system add-on. Modified: haiku/trunk/src/add-ons/Jamfile =================================================================== --- haiku/trunk/src/add-ons/Jamfile 2007-10-13 21:32:43 UTC (rev 22541) +++ haiku/trunk/src/add-ons/Jamfile 2007-10-13 21:34:15 UTC (rev 22542) @@ -2,6 +2,7 @@ SubInclude HAIKU_TOP src add-ons accelerants ; SubInclude HAIKU_TOP src add-ons decorators ; +SubInclude HAIKU_TOP src add-ons disk_systems ; SubInclude HAIKU_TOP src add-ons input_server ; SubInclude HAIKU_TOP src add-ons kernel ; SubInclude HAIKU_TOP src add-ons mail_daemon ; Added: haiku/trunk/src/add-ons/disk_systems/intel/ExtendedPartitionAddOn.cpp =================================================================== --- haiku/trunk/src/add-ons/disk_systems/intel/ExtendedPartitionAddOn.cpp 2007-10-13 21:32:43 UTC (rev 22541) +++ haiku/trunk/src/add-ons/disk_systems/intel/ExtendedPartitionAddOn.cpp 2007-10-13 21:34:15 UTC (rev 22542) @@ -0,0 +1,109 @@ +/* + * Copyright 2007, Ingo Weinhold, bonefish at users.sf.net. + * Distributed under the terms of the MIT License. + */ + +#include "ExtendedPartitionAddOn.h" + +#include + +#include +#include + + +using std::nothrow; + + +// #pragma mark - ExtendedPartitionAddOn + + +// constructor +ExtendedPartitionAddOn::ExtendedPartitionAddOn() + : BDiskSystemAddOn(kPartitionTypeIntel, 0) +{ +} + + +// destructor +ExtendedPartitionAddOn::~ExtendedPartitionAddOn() +{ +} + + +// CreatePartitionHandle +status_t +ExtendedPartitionAddOn::CreatePartitionHandle(BMutablePartition* partition, + BPartitionHandle** _handle) +{ + ExtendedPartitionHandle* handle + = new(nothrow) ExtendedPartitionHandle(partition); + if (!handle) + return B_NO_MEMORY; + + status_t error = handle->Init(); + if (error != B_OK) { + delete handle; + return error; + } + + *_handle = handle; + return B_OK; +} + + +// #pragma mark - ExtendedPartitionHandle + + +// constructor +ExtendedPartitionHandle::ExtendedPartitionHandle(BMutablePartition* partition) + : BPartitionHandle(partition) +{ +} + + +// destructor +ExtendedPartitionHandle::~ExtendedPartitionHandle() +{ +} + + +// Init +status_t +ExtendedPartitionHandle::Init() +{ + // initialize the extended partition from the mutable partition + + BMutablePartition* partition = Partition(); + + // our parent has already set the child cookie to the primary partition. + fPrimaryPartition = (PrimaryPartition*)partition->ChildCookie(); + if (!fPrimaryPartition) + return B_BAD_VALUE; + + if (!fPrimaryPartition->IsExtended()) + return B_BAD_VALUE; + + // init the child partitions + int32 count = partition->CountChildren(); + for (int32 i = 0; i < count; i++) { + BMutablePartition* child = partition->ChildAt(i); + PartitionType type; + if (!type.SetType(child->Type())) + return B_BAD_VALUE; + + // TODO: Get these from the parameters. + bool active = false; + off_t ptsOffset = 0; + + LogicalPartition* logical = new(nothrow) LogicalPartition; + if (!logical) + return B_NO_MEMORY; + + logical->SetTo(child->Offset(), child->Size(), type.Type(), active, + ptsOffset, fPrimaryPartition); + + child->SetChildCookie(logical); + } + + return B_OK; +} Added: haiku/trunk/src/add-ons/disk_systems/intel/ExtendedPartitionAddOn.h =================================================================== --- haiku/trunk/src/add-ons/disk_systems/intel/ExtendedPartitionAddOn.h 2007-10-13 21:32:43 UTC (rev 22541) +++ haiku/trunk/src/add-ons/disk_systems/intel/ExtendedPartitionAddOn.h 2007-10-13 21:34:15 UTC (rev 22542) @@ -0,0 +1,38 @@ +/* + * Copyright 2007, Ingo Weinhold, bonefish at users.sf.net. + * Distributed under the terms of the MIT License. + */ +#ifndef _EXTENDED_PARTITION_ADD_ON_H +#define _EXTENDED_PARTITION_ADD_ON_H + +#include + +#include "PartitionMap.h" + + +class ExtendedPartitionAddOn : public BDiskSystemAddOn { +public: + ExtendedPartitionAddOn(); + virtual ~ExtendedPartitionAddOn(); + + virtual status_t CreatePartitionHandle( + BMutablePartition* partition, + BPartitionHandle** handle); + +}; + + +class ExtendedPartitionHandle : public BPartitionHandle { +public: + ExtendedPartitionHandle( + BMutablePartition* partition); + virtual ~ExtendedPartitionHandle(); + + status_t Init(); + +private: + PrimaryPartition* fPrimaryPartition; +}; + + +#endif // _EXTENDED_PARTITION_ADD_ON_H Added: haiku/trunk/src/add-ons/disk_systems/intel/IntelDiskSystem.cpp =================================================================== --- haiku/trunk/src/add-ons/disk_systems/intel/IntelDiskSystem.cpp 2007-10-13 21:32:43 UTC (rev 22541) +++ haiku/trunk/src/add-ons/disk_systems/intel/IntelDiskSystem.cpp 2007-10-13 21:34:15 UTC (rev 22542) @@ -0,0 +1,43 @@ +/* + * Copyright 2007, Ingo Weinhold, bonefish at users.sf.net. + * Distributed under the terms of the MIT License. + */ + +#include + +#include + +#include + +#include "ExtendedPartitionAddOn.h" +#include "PartitionMapAddOn.h" + + +using std::nothrow; + + +// get_disk_system_add_ons +status_t +get_disk_system_add_ons(BList* addOns) +{ + PartitionMapAddOn* partitionMapAddOn = new(nothrow) PartitionMapAddOn; + ExtendedPartitionAddOn* extendedPartitionAddOn + = new(nothrow) ExtendedPartitionAddOn; + + ObjectDeleter mapAddOnDeleter(partitionMapAddOn); + ObjectDeleter extendedAddOnDeleter( + extendedPartitionAddOn); + + BList list; + if (!partitionMapAddOn || !extendedPartitionAddOn + || !list.AddItem(partitionMapAddOn) + || !list.AddItem(extendedPartitionAddOn) + || !addOns->AddList(&list)) { + return B_NO_MEMORY; + } + + mapAddOnDeleter.Detach(); + extendedAddOnDeleter.Detach(); + + return B_OK; +} Added: haiku/trunk/src/add-ons/disk_systems/intel/IntelDiskSystem.h =================================================================== --- haiku/trunk/src/add-ons/disk_systems/intel/IntelDiskSystem.h 2007-10-13 21:32:43 UTC (rev 22541) +++ haiku/trunk/src/add-ons/disk_systems/intel/IntelDiskSystem.h 2007-10-13 21:34:15 UTC (rev 22542) @@ -0,0 +1,18 @@ +/* + * Copyright 2007, Ingo Weinhold, bonefish at users.sf.net. + * Distributed under the terms of the MIT License. + */ +#ifndef _INTEL_DISK_SYSTEM_H +#define _INTEL_DISK_SYSTEM_H + +#include "PartitionMap.h" + + +static inline off_t +sector_align(off_t offset) +{ + return offset / SECTOR_SIZE * SECTOR_SIZE; +} + + +#endif // _INTEL_DISK_SYSTEM_H Added: haiku/trunk/src/add-ons/disk_systems/intel/Jamfile =================================================================== --- haiku/trunk/src/add-ons/disk_systems/intel/Jamfile 2007-10-13 21:32:43 UTC (rev 22541) +++ haiku/trunk/src/add-ons/disk_systems/intel/Jamfile 2007-10-13 21:34:15 UTC (rev 22542) @@ -0,0 +1,24 @@ +SubDir HAIKU_TOP src add-ons disk_systems intel ; + +UsePrivateHeaders shared ; +UsePrivateHeaders storage ; + +SEARCH_SOURCE + += [ FDirName $(HAIKU_TOP) src add-ons kernel partitioning_systems intel ] ; + +{ + local defines = [ FDefines _USER_MODE ] ; + SubDirCcFlags $(defines) ; + SubDirC++Flags $(defines) ; +} + +Addon intel : + IntelDiskSystem.cpp + ExtendedPartitionAddOn.cpp + PartitionMapAddOn.cpp + + # kernel sources + PartitionMap.cpp + + : be +; Added: haiku/trunk/src/add-ons/disk_systems/intel/PartitionMapAddOn.cpp =================================================================== --- haiku/trunk/src/add-ons/disk_systems/intel/PartitionMapAddOn.cpp 2007-10-13 21:32:43 UTC (rev 22541) +++ haiku/trunk/src/add-ons/disk_systems/intel/PartitionMapAddOn.cpp 2007-10-13 21:34:15 UTC (rev 22542) @@ -0,0 +1,483 @@ +/* + * Copyright 2007, Ingo Weinhold, bonefish at users.sf.net. + * Distributed under the terms of the MIT License. + */ + +#include "PartitionMapAddOn.h" + +#include + +#include +#include +#include + +#include + +#include "IntelDiskSystem.h" + + +using std::nothrow; + + +static const uint32 kDiskSystemFlags = + 0 +// | B_DISK_SYSTEM_SUPPORTS_CHECKING +// | B_DISK_SYSTEM_SUPPORTS_REPAIRING + | B_DISK_SYSTEM_SUPPORTS_RESIZING + | B_DISK_SYSTEM_SUPPORTS_MOVING +// | B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME + | B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS + | B_DISK_SYSTEM_SUPPORTS_INITIALIZING +// | B_DISK_SYSTEM_SUPPORTS_CONTENT_NAME + + | B_DISK_SYSTEM_SUPPORTS_RESIZING_CHILD + | B_DISK_SYSTEM_SUPPORTS_MOVING_CHILD +// | B_DISK_SYSTEM_SUPPORTS_SETTING_NAME + | B_DISK_SYSTEM_SUPPORTS_SETTING_TYPE +// | B_DISK_SYSTEM_SUPPORTS_SETTING_PARAMETERS + | B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD + | B_DISK_SYSTEM_SUPPORTS_DELETING_CHILD +// | B_DISK_SYSTEM_SUPPORTS_NAME +; + + +// #pragma mark - PartitionMapAddOn + + +// constructor +PartitionMapAddOn::PartitionMapAddOn() + : BDiskSystemAddOn(kPartitionTypeIntel, kDiskSystemFlags) +{ +} + + +// destructor +PartitionMapAddOn::~PartitionMapAddOn() +{ +} + + +// CreatePartitionHandle +status_t +PartitionMapAddOn::CreatePartitionHandle(BMutablePartition* partition, + BPartitionHandle** _handle) +{ + PartitionMapHandle* handle = new(nothrow) PartitionMapHandle(partition); + if (!handle) + return B_NO_MEMORY; + + status_t error = handle->Init(); + if (error != B_OK) { + delete handle; + return error; + } + + *_handle = handle; + return B_OK; +} + + +// CanInitialize +bool +PartitionMapAddOn::CanInitialize(const BMutablePartition* partition) +{ + // If it's big enough, we can initialize it. + return partition->Size() >= 2 * SECTOR_SIZE; +} + + +// GetInitializationParameterEditor +status_t +PartitionMapAddOn::GetInitializationParameterEditor( + const BMutablePartition* partition, BDiskDeviceParameterEditor** editor) +{ + // Nothing to edit, really. + *editor = NULL; + return B_OK; +} + + +// ValidateInitialize +status_t +PartitionMapAddOn::ValidateInitialize(const BMutablePartition* partition, + BString* name, const char* parameters) +{ + if (!CanInitialize(partition) + || parameters != NULL && strlen(parameters) > 0) { + return B_BAD_VALUE; + } + + // we don't support a content name + if (name != NULL) + name->Truncate(0); + + return B_OK; +} + + +// Initialize +status_t +PartitionMapAddOn::Initialize(BMutablePartition* partition, const char* name, + const char* parameters, BPartitionHandle** _handle) +{ + if (!CanInitialize(partition) + || name != NULL && strlen(name) > 0 + || parameters != NULL && strlen(parameters) > 0) { + return B_BAD_VALUE; + } + + // create the handle + PartitionMapHandle* handle = new(nothrow) PartitionMapHandle(partition); + if (!handle) + return B_NO_MEMORY; + ObjectDeleter handleDeleter(handle); + + // init the partition + status_t error = partition->SetContentType(Name()); + if (error != B_OK) + return error; +// TODO: The content type could as well be set by the caller. + + partition->SetContentName(NULL); + partition->SetContentParameters(NULL); + partition->SetBlockSize(SECTOR_SIZE); + partition->SetContentSize(partition->Size() / SECTOR_SIZE * SECTOR_SIZE); + + *_handle = handleDeleter.Detach(); + + return B_OK; +} + + +// #pragma mark - PartitionMapHandle + + +// constructor +PartitionMapHandle::PartitionMapHandle(BMutablePartition* partition) + : BPartitionHandle(partition) +{ +} + + +// destructor +PartitionMapHandle::~PartitionMapHandle() +{ +} + + +// Init +status_t +PartitionMapHandle::Init() +{ + // initialize the partition map from the mutable partition + + BMutablePartition* partition = Partition(); + + int32 count = partition->CountChildren(); + if (count > 4) + return B_BAD_VALUE; + + int32 extendedCount = 0; + + for (int32 i = 0; i < count; i++) { + BMutablePartition* child = partition->ChildAt(i); + PartitionType type; + if (!type.SetType(child->Type())) + return B_BAD_VALUE; + + // only one extended partition is allowed + if (type.IsExtended()) { + if (++extendedCount > 1) + return B_BAD_VALUE; + } + + // TODO: Get these from the parameters. + int32 index = i; + bool active = false; + + PrimaryPartition* primary = fPartitionMap.PrimaryPartitionAt(index); + primary->SetTo(child->Offset(), child->Size(), type.Type(), active); + + child->SetChildCookie(primary); + } + + // The extended partition (if any) is initialized by + // ExtendedPartitionHandle::Init(). + + return B_OK; +} + + +// SupportedOperations +uint32 +PartitionMapHandle::SupportedOperations(uint32 mask) +{ + BMutablePartition* partition = Partition(); + + uint32 flags = B_DISK_SYSTEM_SUPPORTS_RESIZING + | B_DISK_SYSTEM_SUPPORTS_MOVING + | B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS + | B_DISK_SYSTEM_SUPPORTS_INITIALIZING; + + // creating child + if (mask & B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD) { + BPartitioningInfo info; + if (partition->CountChildren() < 4 + && GetPartitioningInfo(&info) == B_OK + && info.CountPartitionableSpaces() > 1) { + flags |= B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD; + } + } + + return flags; +} + + +// SupportedChildOperations +uint32 +PartitionMapHandle::SupportedChildOperations(const BMutablePartition* child, + uint32 mask) +{ + return B_DISK_SYSTEM_SUPPORTS_RESIZING_CHILD + | B_DISK_SYSTEM_SUPPORTS_MOVING_CHILD + | B_DISK_SYSTEM_SUPPORTS_SETTING_TYPE + | B_DISK_SYSTEM_SUPPORTS_DELETING_CHILD; +} + + +// GetPartitioningInfo +status_t +PartitionMapHandle::GetPartitioningInfo(BPartitioningInfo* info) +{ + // init to the full size (minus the first sector) + off_t size = Partition()->ContentSize(); + status_t error = info->SetTo(SECTOR_SIZE, size - SECTOR_SIZE); + if (error != B_OK) + return error; + + // exclude the space of the existing partitions + for (int32 i = 0; i < 4; i++) { + PrimaryPartition* primary = fPartitionMap.PrimaryPartitionAt(i); + if (!primary->IsEmpty()) { + error = info->ExcludeOccupiedSpace(primary->Offset(), + primary->Size()); + if (error != B_OK) + return error; + } + } + + return B_OK; +} + + +// GetChildCreationParameterEditor +status_t +PartitionMapHandle::GetChildCreationParameterEditor(const char* type, + BDiskDeviceParameterEditor** editor) +{ + // TODO: We actually need an editor here. + *editor = NULL; + return B_OK; +} + + +// ValidateCreateChild +status_t +PartitionMapHandle::ValidateCreateChild(off_t* _offset, off_t* _size, + const char* typeString, BString* name, const char* parameters) +{ + // check type + PartitionType type; + if (!type.SetType(typeString) || type.IsEmpty()) + return B_BAD_VALUE; + if (type.IsExtended() && fPartitionMap.ExtendedPartitionIndex() >= 0) + return B_BAD_VALUE; + + // check name + if (name) + name->Truncate(0); + + // check parameters + // TODO:... + + // do we have a spare primary partition? + if (fPartitionMap.CountNonEmptyPrimaryPartitions() == 4) + return B_BAD_VALUE; + + // check the free space situation + BPartitioningInfo info; + status_t error = GetPartitioningInfo(&info); + if (error != B_OK) + return error; + + // any space in the partition at all? + int32 spacesCount = info.CountPartitionableSpaces(); + if (spacesCount == 0) + return B_BAD_VALUE; + + // check offset and size + off_t offset = sector_align(*_offset); + off_t size = sector_align(*_size); + // TODO: Rather round size up? + off_t end = offset + size; + + // get the first partitionable space the requested interval intersects with + int32 spaceIndex = -1; + int32 closestSpaceIndex = -1; + off_t closestSpaceDistance = 0; + for (int32 i = 0; i < spacesCount; i++) { + off_t spaceOffset, spaceSize; + info.GetPartitionableSpaceAt(i, &spaceOffset, &spaceSize); + off_t spaceEnd = spaceOffset + spaceSize; + + if (spaceOffset >= offset && spaceOffset < end + || offset >= spaceOffset && offset < spaceEnd) { + spaceIndex = i; + break; + } + + off_t distance; + if (offset < spaceOffset) + distance = spaceOffset - end; + else + distance = spaceEnd - offset; + + if (closestSpaceIndex == -1 || distance < closestSpaceDistance) { + closestSpaceIndex = i; + closestSpaceDistance = distance; + } + } + + // get the space we found + off_t spaceOffset, spaceSize; + info.GetPartitionableSpaceAt( + spaceIndex >= 0 ? spaceIndex : closestSpaceIndex, &spaceOffset, + &spaceSize); + off_t spaceEnd = spaceOffset + spaceSize; + + // If the requested intervald doesn't intersect with any space yet, move + // it, so that it does. + if (spaceIndex < 0) { + spaceIndex = closestSpaceIndex; + if (offset < spaceOffset) { + offset = spaceOffset; + end = offset + size; + } else { + end = spaceEnd; + offset = end - size; + } + } + + // move/shrink the interval, so that it fully lies within the space + if (offset < spaceOffset) { + offset = spaceOffset; + end = offset + size; + if (end > spaceEnd) { + end = spaceEnd; + size = end - offset; + } + } else if (end > spaceEnd) { + end = spaceEnd; + offset = end - size; + if (offset < spaceOffset) { + offset = spaceOffset; + size = end - offset; + } + } + + *_offset = offset; + *_size = size; + + return B_OK; +} + + +// CreateChild +status_t +PartitionMapHandle::CreateChild(off_t offset, off_t size, + const char* typeString, const char* name, const char* parameters, + BMutablePartition** _child) +{ + // check type + PartitionType type; + if (!type.SetType(typeString) || type.IsEmpty()) + return B_BAD_VALUE; + if (type.IsExtended() && fPartitionMap.ExtendedPartitionIndex() >= 0) + return B_BAD_VALUE; + + // check name + if (name && strlen(name) > 0) + return B_BAD_VALUE; + + // check parameters + // TODO:... + + // get a spare primary partition + PrimaryPartition* primary = NULL; + for (int32 i = 0; i < 4; i++) { + if (fPartitionMap.PrimaryPartitionAt(i)->IsEmpty()) { + primary = fPartitionMap.PrimaryPartitionAt(i); + break; + } + } + if (!primary) + return B_BAD_VALUE; + + // offset properly aligned? + if (offset != sector_align(offset) || size != sector_align(size)) + return B_BAD_VALUE; + + // check the free space situation + BPartitioningInfo info; + status_t error = GetPartitioningInfo(&info); + if (error != B_OK) + return error; + + bool foundSpace = false; + off_t end = offset + size; + int32 spacesCount = info.CountPartitionableSpaces(); + for (int32 i = 0; i < spacesCount; i++) { + off_t spaceOffset, spaceSize; + info.GetPartitionableSpaceAt(i, &spaceOffset, &spaceSize); + off_t spaceEnd = spaceOffset + spaceSize; + + if (offset >= spaceOffset && end <= spaceEnd) { + foundSpace = true; + break; + } + } + + if (!foundSpace) + return B_BAD_VALUE; + + // everything looks good, do it + + // create the child + // (Note: the primary partition index is indeed the child index, since + // we picked the first empty primary partition.) + BMutablePartition* partition = Partition(); + BMutablePartition* child; + error = partition->CreateChild(primary->Index(), typeString, NULL, + parameters, &child); + if (error != B_OK) + return error; + + // init the child + child->SetOffset(offset); + child->SetSize(size); + child->SetBlockSize(SECTOR_SIZE); + //child->SetFlags(0); + child->SetChildCookie(primary); + + // init the primary partition + bool active = false; + // TODO: Get from parameters! + primary->SetTo(offset, size, type.Type(), active); + +// TODO: If the child is an extended partition, we should trigger its +// initialization. + + *_child = child; + return B_OK; +} + Added: haiku/trunk/src/add-ons/disk_systems/intel/PartitionMapAddOn.h =================================================================== --- haiku/trunk/src/add-ons/disk_systems/intel/PartitionMapAddOn.h 2007-10-13 21:32:43 UTC (rev 22541) +++ haiku/trunk/src/add-ons/disk_systems/intel/PartitionMapAddOn.h 2007-10-13 21:34:15 UTC (rev 22542) @@ -0,0 +1,67 @@ +/* + * Copyright 2007, Ingo Weinhold, bonefish at users.sf.net. + * Distributed under the terms of the MIT License. + */ +#ifndef _PARTITION_MAP_ADD_ON_H +#define _PARTITION_MAP_ADD_ON_H + +#include + +#include "PartitionMap.h" + + +class PartitionMapAddOn : public BDiskSystemAddOn { +public: + PartitionMapAddOn(); + virtual ~PartitionMapAddOn(); + + virtual status_t CreatePartitionHandle( + BMutablePartition* partition, + BPartitionHandle** handle); + + virtual bool CanInitialize( + const BMutablePartition* partition); + virtual status_t GetInitializationParameterEditor( + const BMutablePartition* partition, + BDiskDeviceParameterEditor** editor); + virtual status_t ValidateInitialize( + const BMutablePartition* partition, + BString* name, const char* parameters); + virtual status_t Initialize(BMutablePartition* partition, + const char* name, const char* parameters, + BPartitionHandle** handle); +}; + + +class PartitionMapHandle : public BPartitionHandle { +public: + PartitionMapHandle( + BMutablePartition* partition); + virtual ~PartitionMapHandle(); + + status_t Init(); + + virtual uint32 SupportedOperations(uint32 mask); + virtual uint32 SupportedChildOperations( + const BMutablePartition* child, + uint32 mask); + + virtual status_t GetPartitioningInfo(BPartitioningInfo* info); + + virtual status_t GetChildCreationParameterEditor( + const char* type, + BDiskDeviceParameterEditor** editor); + virtual status_t ValidateCreateChild(off_t* offset, + off_t* size, const char* type, + BString* name, const char* parameters); + virtual status_t CreateChild(off_t offset, off_t size, + const char* type, const char* name, + const char* parameters, + BMutablePartition** child); + +private: + PartitionMap fPartitionMap; +}; + + +#endif // _PARTITION_MAP_ADD_ON_H From bonefish at mail.berlios.de Sat Oct 13 23:29:34 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sat, 13 Oct 2007 23:29:34 +0200 Subject: [Haiku-commits] r22540 - in haiku/trunk: headers/private/storage src/kits/storage Message-ID: <200710132129.l9DLTYMx013728@sheep.berlios.de> Author: bonefish Date: 2007-10-13 23:29:33 +0200 (Sat, 13 Oct 2007) New Revision: 22540 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22540&view=rev Modified: haiku/trunk/headers/private/storage/DiskSystemAddOn.h haiku/trunk/headers/private/storage/MutablePartition.h haiku/trunk/src/kits/storage/DiskSystemAddOn.cpp haiku/trunk/src/kits/storage/MutablePartition.cpp haiku/trunk/src/kits/storage/PartitionDelegate.cpp haiku/trunk/src/kits/storage/PartitionDelegate.h Log: * Initialization of BPartition::Delegate is now two-phased. The first phase builds the object hierarchy, the second will (in case of MutableDelegate) let the disk systems do their initialization. This way the disk systems already find a fully functional object hierarchy they can work with. * Child creation also takes a partition name as a parameter, now. * Implemented BMutablePartition child creation/deletion. * The BDiskSystemAddOn/BPartitionHandle::Validate*() methods return a status_t instead of a bool, now. Modified: haiku/trunk/headers/private/storage/DiskSystemAddOn.h =================================================================== --- haiku/trunk/headers/private/storage/DiskSystemAddOn.h 2007-10-13 21:17:26 UTC (rev 22539) +++ haiku/trunk/headers/private/storage/DiskSystemAddOn.h 2007-10-13 21:29:33 UTC (rev 22540) @@ -34,7 +34,7 @@ virtual status_t GetInitializationParameterEditor( const BMutablePartition* partition, BDiskDeviceParameterEditor** editor); - virtual bool ValidateInitialize( + virtual status_t ValidateInitialize( const BMutablePartition* partition, BString* name, const char* parameters); virtual status_t Initialize(BMutablePartition* partition, @@ -77,30 +77,30 @@ virtual status_t Defragment(); virtual status_t Repair(bool checkOnly); - virtual bool ValidateResize(off_t* size); - virtual bool ValidateResizeChild( + virtual status_t ValidateResize(off_t* size); + virtual status_t ValidateResizeChild( const BMutablePartition* child, off_t* size); virtual status_t Resize(off_t size); virtual status_t ResizeChild(BMutablePartition* child, off_t size); - virtual bool ValidateMove(off_t* offset); - virtual bool ValidateMoveChild( + virtual status_t ValidateMove(off_t* offset); + virtual status_t ValidateMoveChild( const BMutablePartition* child, off_t* offset); virtual status_t Move(off_t offset); virtual status_t MoveChild(BMutablePartition* child, off_t offset); - virtual bool ValidateSetContentName(BString* name); - virtual bool ValidateSetName(const BMutablePartition* child, + virtual status_t ValidateSetContentName(BString* name); + virtual status_t ValidateSetName(const BMutablePartition* child, BString* name); virtual status_t SetContentName(const char* name); virtual status_t SetName(BMutablePartition* child, const char* name); - virtual bool ValidateSetType(const BMutablePartition* child, + virtual status_t ValidateSetType(const BMutablePartition* child, const char* type); virtual status_t SetType(BMutablePartition* child, const char* type); @@ -110,9 +110,9 @@ virtual status_t GetParameterEditor( const BMutablePartition* child, BDiskDeviceParameterEditor** editor); - virtual bool ValidateSetContentParameters( + virtual status_t ValidateSetContentParameters( const char* parameters); - virtual bool ValidateSetParameters( + virtual status_t ValidateSetParameters( const BMutablePartition* child, const char* parameters); virtual status_t SetContentParameters(const char* parameters); @@ -122,11 +122,12 @@ virtual status_t GetChildCreationParameterEditor( const char* type, BDiskDeviceParameterEditor** editor); - virtual bool ValidateCreateChild(off_t* offset, + virtual status_t ValidateCreateChild(off_t* offset, off_t* size, const char* type, - const char* parameters); + BString* name, const char* parameters); virtual status_t CreateChild(off_t offset, off_t size, - const char* type, const char* parameters, + const char* type, const char* name, + const char* parameters, BMutablePartition** child); virtual status_t DeleteChild(BMutablePartition* child); Modified: haiku/trunk/headers/private/storage/MutablePartition.h =================================================================== --- haiku/trunk/headers/private/storage/MutablePartition.h 2007-10-13 21:17:26 UTC (rev 22539) +++ haiku/trunk/headers/private/storage/MutablePartition.h 2007-10-13 21:29:33 UTC (rev 22540) @@ -55,10 +55,16 @@ status_t CreateChild(int32 index, BMutablePartition** child); + status_t CreateChild(int32 index, const char* type, + const char* name, const char* parameters, + BMutablePartition** child); status_t DeleteChild(int32 index); + status_t DeleteChild(BMutablePartition* child); + BMutablePartition* Parent() const; BMutablePartition* ChildAt(int32 index) const; int32 CountChildren() const; + int32 IndexOfChild(BMutablePartition* child) const; // for the partitioning system managing the parent void* ChildCookie() const; @@ -69,7 +75,8 @@ BPartition::MutableDelegate* delegate); ~BMutablePartition(); - status_t Init(const user_partition_data* partitionData); + status_t Init(const user_partition_data* partitionData, + BMutablePartition* parent); const user_partition_data* PartitionData() const; @@ -80,6 +87,7 @@ BPartition::MutableDelegate* fDelegate; user_partition_data* fData; + BMutablePartition* fParent; BList fChildren; void* fChildCookie; }; Modified: haiku/trunk/src/kits/storage/DiskSystemAddOn.cpp =================================================================== --- haiku/trunk/src/kits/storage/DiskSystemAddOn.cpp 2007-10-13 21:17:26 UTC (rev 22539) +++ haiku/trunk/src/kits/storage/DiskSystemAddOn.cpp 2007-10-13 21:29:33 UTC (rev 22540) @@ -59,11 +59,11 @@ // ValidateInitialize -bool +status_t BDiskSystemAddOn::ValidateInitialize(const BMutablePartition* partition, BString* name, const char* parameters) { - return false; + return B_BAD_VALUE; } @@ -176,19 +176,19 @@ // ValidateResize -bool +status_t BPartitionHandle::ValidateResize(off_t* size) { - return false; + return B_BAD_VALUE; } // ValidateResizeChild -bool +status_t BPartitionHandle::ValidateResizeChild(const BMutablePartition* child, off_t* size) { - return false; + return B_BAD_VALUE; } @@ -209,21 +209,21 @@ // ValidateMove -bool +status_t BPartitionHandle::ValidateMove(off_t* offset) { // Usually moving a disk system is a no-op for the content disk system, // so we default to true here. - return true; + return B_OK; } // ValidateMoveChild -bool +status_t BPartitionHandle::ValidateMoveChild(const BMutablePartition* child, off_t* offset) { - return false; + return B_BAD_VALUE; } @@ -246,19 +246,19 @@ // ValidateSetContentName -bool +status_t BPartitionHandle::ValidateSetContentName(BString* name) { - return false; + return B_BAD_VALUE; } // ValidateSetName -bool +status_t BPartitionHandle::ValidateSetName(const BMutablePartition* child, BString* name) { - return false; + return B_BAD_VALUE; } @@ -279,11 +279,11 @@ // ValidateSetType -bool +status_t BPartitionHandle::ValidateSetType(const BMutablePartition* child, const char* type) { - return false; + return B_BAD_VALUE; } @@ -313,19 +313,19 @@ // ValidateSetContentParameters -bool +status_t BPartitionHandle::ValidateSetContentParameters(const char* parameters) { - return false; + return B_BAD_VALUE; } // ValidateSetParameters -bool +status_t BPartitionHandle::ValidateSetParameters(const BMutablePartition* child, const char* parameters) { - return false; + return B_BAD_VALUE; } @@ -356,18 +356,18 @@ // ValidateCreateChild -bool +status_t BPartitionHandle::ValidateCreateChild(off_t* offset, off_t* size, - const char* type, const char* parameters) + const char* type, BString* name, const char* parameters) { - return false; + return B_BAD_VALUE; } // CreateChild status_t BPartitionHandle::CreateChild(off_t offset, off_t size, const char* type, - const char* parameters, BMutablePartition** child) + const char* name, const char* parameters, BMutablePartition** child) { return B_NOT_SUPPORTED; } Modified: haiku/trunk/src/kits/storage/MutablePartition.cpp =================================================================== --- haiku/trunk/src/kits/storage/MutablePartition.cpp 2007-10-13 21:17:26 UTC (rev 22539) +++ haiku/trunk/src/kits/storage/MutablePartition.cpp 2007-10-13 21:29:33 UTC (rev 22540) @@ -10,9 +10,13 @@ #include +#include + #include +#include "PartitionDelegate.h" + using std::nothrow; @@ -244,22 +248,101 @@ // CreateChild status_t -BMutablePartition::CreateChild(int32 index, BMutablePartition** child) +BMutablePartition::CreateChild(int32 index, BMutablePartition** _child) { - // TODO: ... - return B_ERROR; + if (index < 0) + index = fChildren.CountItems(); + else if (index > fChildren.CountItems()) + return B_BAD_VALUE; + + // create the BPartition + BPartition* partition = new(nothrow) BPartition; + if (!partition) + return B_NO_MEMORY; + + // create the MutableDelegate + BPartition::MutableDelegate* delegate + = new(nothrow) BPartition::MutableDelegate(partition); + if (!delegate) { + delete partition; + return B_NO_MEMORY; + } + partition->fDelegate = delegate; +// TODO: Any further initialization required? + + // add the child + BMutablePartition* child = delegate->MutablePartition(); + if (!fChildren.AddItem(child, index)) { + delete partition; + return B_NO_MEMORY; + } + child->fParent = this; + + *_child = child; + + return B_OK; } +// CreateChild +status_t +BMutablePartition::CreateChild(int32 index, const char* type, const char* name, + const char* parameters, BMutablePartition** _child) +{ + // create the child + BMutablePartition* child; + status_t error = CreateChild(index, &child); + if (error != B_OK) + return error; + + // set the name, type, and parameters + error = SetType(type); + if (error == B_OK) + error = SetName(name); + if (error == B_OK) + error = SetParameters(parameters); + + // cleanup on error + if (error != B_OK) { + DeleteChild(child); + return error; + } + + *_child = child; + return B_OK; +} + + // DeleteChild status_t BMutablePartition::DeleteChild(int32 index) { - // TODO: ... - return B_ERROR; + BMutablePartition* child = (BMutablePartition*)fChildren.RemoveItem(index); + if (!child) + return B_BAD_VALUE; + + delete child->fDelegate->Partition(); + + return B_OK; } +// DeleteChild +status_t +BMutablePartition::DeleteChild(BMutablePartition* child) +{ + return DeleteChild(IndexOfChild(child)); +} + + +// Parent +BMutablePartition* +BMutablePartition::Parent() const +{ + return fParent; +} + + // ChildAt BMutablePartition* BMutablePartition::ChildAt(int32 index) const @@ -276,6 +359,16 @@ } +// IndexOfChild +int32 +BMutablePartition::IndexOfChild(BMutablePartition* child) const +{ + if (!child) + return -1; + return fChildren.IndexOf(child); +} + + // ChildCookie void* BMutablePartition::ChildCookie() const @@ -296,6 +389,7 @@ BMutablePartition::BMutablePartition(BPartition::MutableDelegate* delegate) : fDelegate(delegate), fData(NULL), + fParent(NULL), fChildCookie(NULL) { } @@ -303,8 +397,17 @@ // Init status_t -BMutablePartition::Init(const user_partition_data* partitionData) +BMutablePartition::Init(const user_partition_data* partitionData, + BMutablePartition* parent) { + fParent = parent; + + // add to the parent's child list + if (fParent) { + if (!fParent->fChildren.AddItem(this)) + return B_NO_MEMORY; + } + // allocate data structure fData = new(nothrow) user_partition_data; if (!fData) Modified: haiku/trunk/src/kits/storage/PartitionDelegate.cpp =================================================================== --- haiku/trunk/src/kits/storage/PartitionDelegate.cpp 2007-10-13 21:17:26 UTC (rev 22539) +++ haiku/trunk/src/kits/storage/PartitionDelegate.cpp 2007-10-13 21:29:33 UTC (rev 22540) @@ -61,14 +61,21 @@ } -// Init +// InitHierarchy status_t -BPartition::MutableDelegate::Init(const user_partition_data* partitionData) +BPartition::MutableDelegate::InitHierarchy( + const user_partition_data* partitionData, Delegate* _parent) { - status_t error = fMutablePartition.Init(partitionData); - if (error != B_OK) - return error; + MutableDelegate* parent = dynamic_cast(_parent); + return fMutablePartition.Init(partitionData, + parent ? &parent->fMutablePartition : NULL); +} + +// InitAfterHierarchy +status_t +BPartition::MutableDelegate::InitAfterHierarchy() +{ if (!fMutablePartition.ContentType()) return B_OK; @@ -80,13 +87,13 @@ return B_ENTRY_NOT_FOUND; BPartitionHandle* handle; - error = addOn->CreatePartitionHandle(&fMutablePartition, &handle); + status_t error = addOn->CreatePartitionHandle(&fMutablePartition, &handle); if (error != B_OK) { manager->PutAddOn(addOn); return error; } - // everything went fine --keep the disk system add-on reference and the + // everything went fine -- keep the disk system add-on reference and the // handle fDiskSystem = addOn; fPartitionHandle = handle; @@ -169,7 +176,7 @@ if (!fPartitionHandle) return B_NO_INIT; - return fPartitionHandle->ValidateResize(size) ? B_OK : B_BAD_VALUE; + return fPartitionHandle->ValidateResize(size); } @@ -184,7 +191,7 @@ return B_NO_INIT; return fPartitionHandle->ValidateResizeChild(&child->fMutablePartition, - size) ? B_OK : B_BAD_VALUE; + size); } @@ -219,7 +226,7 @@ if (!fPartitionHandle) return B_NO_INIT; - return fPartitionHandle->ValidateMove(offset) ? B_OK : B_BAD_VALUE; + return fPartitionHandle->ValidateMove(offset); } @@ -234,7 +241,7 @@ return B_NO_INIT; return fPartitionHandle->ValidateMoveChild(&child->fMutablePartition, - offset) ? B_OK : B_BAD_VALUE; + offset); } @@ -269,7 +276,7 @@ if (!fPartitionHandle) return B_NO_INIT; - return fPartitionHandle->ValidateSetContentName(name) ? B_OK : B_BAD_VALUE; + return fPartitionHandle->ValidateSetContentName(name); } @@ -283,8 +290,7 @@ if (!fPartitionHandle || !child) return B_NO_INIT; - return fPartitionHandle->ValidateSetName(&child->fMutablePartition, name) - ? B_OK : B_BAD_VALUE; + return fPartitionHandle->ValidateSetName(&child->fMutablePartition, name); } @@ -322,8 +328,7 @@ if (!fPartitionHandle || !child) return B_NO_INIT; - return fPartitionHandle->ValidateSetType(&child->fMutablePartition, type) - ? B_OK : B_BAD_VALUE; + return fPartitionHandle->ValidateSetType(&child->fMutablePartition, type); } @@ -444,13 +449,13 @@ if (!addOn) return B_ENTRY_NOT_FOUND; - bool result = addOn->ValidateInitialize(&fMutablePartition, + status_t result = addOn->ValidateInitialize(&fMutablePartition, name, parameters); // put the add-on manager->PutAddOn(addOn); - return result ? B_OK : B_BAD_VALUE; + return result; } @@ -513,26 +518,27 @@ // ValidateCreateChild status_t BPartition::MutableDelegate::ValidateCreateChild(off_t* start, off_t* size, - const char* type, const char* parameters) const + const char* type, BString* name, const char* parameters) const { if (!fPartitionHandle) return B_NO_INIT; - return fPartitionHandle->ValidateCreateChild(start, size, type, parameters) - ? B_OK : B_BAD_VALUE; + return fPartitionHandle->ValidateCreateChild(start, size, type, name, + parameters); } // CreateChild status_t BPartition::MutableDelegate::CreateChild(off_t start, off_t size, - const char* type, const char* parameters, BPartition** child) + const char* type, const char* name, const char* parameters, + BPartition** child) { if (!fPartitionHandle) return B_NO_INIT; BMutablePartition* mutableChild; - status_t error = fPartitionHandle->CreateChild(start, size, type, + status_t error = fPartitionHandle->CreateChild(start, size, type, name, parameters, &mutableChild); if (error != B_OK) return error; Modified: haiku/trunk/src/kits/storage/PartitionDelegate.h =================================================================== --- haiku/trunk/src/kits/storage/PartitionDelegate.h 2007-10-13 21:17:26 UTC (rev 22539) +++ haiku/trunk/src/kits/storage/PartitionDelegate.h 2007-10-13 21:29:33 UTC (rev 22540) @@ -18,8 +18,10 @@ Delegate(BPartition* partition); virtual ~Delegate(); - virtual status_t Init(const user_partition_data* partitionData) - = 0; + virtual status_t InitHierarchy( + const user_partition_data* partitionData, + Delegate* parent) = 0; + virtual status_t InitAfterHierarchy() = 0; BPartition* Partition() const { return fPartition; } @@ -89,10 +91,11 @@ BDiskDeviceParameterEditor** editor) const = 0; virtual status_t ValidateCreateChild(off_t* start, off_t* size, - const char* type, + const char* type, BString* name, const char* parameters) const = 0; virtual status_t CreateChild(off_t start, off_t size, - const char* type, const char* parameters, + const char* type, const char* name, + const char* parameters, BPartition** child) = 0; virtual status_t DeleteChild(Delegate* child) = 0; @@ -103,7 +106,7 @@ }; -class BPartition::MutableDelegate : BPartition::Delegate { +class BPartition::MutableDelegate : public BPartition::Delegate { public: MutableDelegate(BPartition* partition); virtual ~MutableDelegate(); @@ -111,7 +114,10 @@ BMutablePartition* MutablePartition(); const BMutablePartition* MutablePartition() const; - virtual status_t Init(const user_partition_data* partitionData); + virtual status_t InitHierarchy( + const user_partition_data* partitionData, + Delegate* parent); + virtual status_t InitAfterHierarchy(); virtual const user_partition_data* PartitionData() const; @@ -127,17 +133,17 @@ virtual status_t Defragment(); virtual status_t Repair(bool checkOnly); - virtual status_t ValidateResize(off_t* size) const = 0; + virtual status_t ValidateResize(off_t* size) const; virtual status_t ValidateResizeChild(Delegate* child, - off_t* size) const = 0; - virtual status_t Resize(off_t size) = 0; - virtual status_t ResizeChild(Delegate* child, off_t size) = 0; + off_t* size) const; + virtual status_t Resize(off_t size); + virtual status_t ResizeChild(Delegate* child, off_t size); - virtual status_t ValidateMove(off_t* offset) const = 0; + virtual status_t ValidateMove(off_t* offset) const; virtual status_t ValidateMoveChild(Delegate* child, - off_t* offset) const = 0; - virtual status_t Move(off_t offset) = 0; - virtual status_t MoveChild(Delegate* child, off_t offset) = 0; + off_t* offset) const; + virtual status_t Move(off_t offset); + virtual status_t MoveChild(Delegate* child, off_t offset); virtual status_t ValidateSetContentName(BString* name) const; virtual status_t ValidateSetName(Delegate* child, @@ -174,11 +180,11 @@ const char* system, BDiskDeviceParameterEditor** editor) const; virtual status_t ValidateCreateChild(off_t* start, off_t* size, - const char* type, + const char* type, BString* name, const char* parameters) const; virtual status_t CreateChild(off_t start, off_t size, - const char* type, const char* parameters, - BPartition** child); + const char* type, const char* name, + const char* parameters, BPartition** child); virtual status_t DeleteChild(Delegate* child); From nielx at mail.berlios.de Sun Oct 14 00:13:42 2007 From: nielx at mail.berlios.de (nielx at BerliOS) Date: Sun, 14 Oct 2007 00:13:42 +0200 Subject: [Haiku-commits] r22543 - haiku/trunk/docs/user/support Message-ID: <200710132213.l9DMDgKF016381@sheep.berlios.de> Author: nielx Date: 2007-10-14 00:13:42 +0200 (Sun, 14 Oct 2007) New Revision: 22543 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22543&view=rev Modified: haiku/trunk/docs/user/support/Locker.dox Log: Correct typo. Fix bug #1548 Modified: haiku/trunk/docs/user/support/Locker.dox =================================================================== --- haiku/trunk/docs/user/support/Locker.dox 2007-10-13 21:34:15 UTC (rev 22542) +++ haiku/trunk/docs/user/support/Locker.dox 2007-10-13 22:13:42 UTC (rev 22543) @@ -46,7 +46,7 @@ Flower::Grow(int length) { if (fLock->Lock()) { - fLength += lenght; + fLength += length; fLock->Unlock(); return B_OK; } else { From bonefish at mail.berlios.de Sun Oct 14 01:17:46 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sun, 14 Oct 2007 01:17:46 +0200 Subject: [Haiku-commits] r22544 - haiku/trunk/src/kits/storage Message-ID: <200710132317.l9DNHkkV004885@sheep.berlios.de> Author: bonefish Date: 2007-10-14 01:17:44 +0200 (Sun, 14 Oct 2007) New Revision: 22544 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22544&view=rev Modified: haiku/trunk/src/kits/storage/DiskSystemAddOnManager.cpp haiku/trunk/src/kits/storage/DiskSystemAddOnManager.h Log: Implemented loading/unloading of add-ons. Modified: haiku/trunk/src/kits/storage/DiskSystemAddOnManager.cpp =================================================================== --- haiku/trunk/src/kits/storage/DiskSystemAddOnManager.cpp 2007-10-13 22:13:42 UTC (rev 22543) +++ haiku/trunk/src/kits/storage/DiskSystemAddOnManager.cpp 2007-10-13 23:17:44 UTC (rev 22544) @@ -5,9 +5,17 @@ #include "DiskSystemAddOnManager.h" +#include +#include +#include + +#include +#include #include +#include #include +#include #include #include @@ -19,6 +27,17 @@ // AddOnImage struct DiskSystemAddOnManager::AddOnImage { + AddOnImage(image_id image) + : image(image), + refCount(0) + { + } + + ~AddOnImage() + { + unload_add_on(image); + } + image_id image; int32 refCount; }; @@ -26,12 +45,23 @@ // AddOn struct DiskSystemAddOnManager::AddOn { + AddOn(AddOnImage* image, BDiskSystemAddOn* addOn) + : image(image), + addOn(addOn) + { + } + AddOnImage* image; BDiskSystemAddOn* addOn; int32 refCount; }; +// StringSet +struct DiskSystemAddOnManager::StringSet : std::set { +}; + + // Default DiskSystemAddOnManager* DiskSystemAddOnManager::Default() @@ -74,15 +104,27 @@ // LoadDiskSystems -void +status_t DiskSystemAddOnManager::LoadDiskSystems() { AutoLocker _(fLock); if (++fLoadCount > 1) - return; + return B_OK; - // TODO: Load the add-ons ... + StringSet alreadyLoaded; + status_t error = _LoadAddOns(alreadyLoaded, B_USER_ADDONS_DIRECTORY); + + if (error == B_OK) + error = _LoadAddOns(alreadyLoaded, B_COMMON_ADDONS_DIRECTORY); + + if (error == B_OK) + error = _LoadAddOns(alreadyLoaded, B_BEOS_ADDONS_DIRECTORY); + + if (error != B_OK) + UnloadDiskSystems(); + + return error; } @@ -92,10 +134,16 @@ { AutoLocker _(fLock); - if (--fLoadCount == 0) + if (fLoadCount == 0 || --fLoadCount > 0) return; - // TODO: Unload the add-ons ... + fAddOnsToBeUnloaded.AddList(&fAddOns); + fAddOns.MakeEmpty(); + + // put all add-ons -- that will cause them to be deleted as soon as they're + // unused + for (int32 i = fAddOnsToBeUnloaded.CountItems() - 1; i >= 0; i--) + _PutAddOn(i); } @@ -147,13 +195,24 @@ for (int32 i = 0; AddOn* addOn = _AddOnAt(i); i++) { if (_addOn == addOn->addOn) { - if (addOn->refCount == 0) - debugger("DiskSystemAddOnManager: unbalanced PutAddOn()"); - else + if (addOn->refCount > 1) { addOn->refCount--; + } else { + debugger("Unbalanced call to " + "DiskSystemAddOnManager::PutAddOn()"); + } return; } + + for (int32 i = 0; + AddOn* addOn = (AddOn*)fAddOnsToBeUnloaded.ItemAt(i); i++) { + if (_addOn == addOn->addOn) + _PutAddOn(i); + return; + } } + + debugger("DiskSystemAddOnManager::PutAddOn(): disk system not found"); } @@ -161,6 +220,7 @@ DiskSystemAddOnManager::DiskSystemAddOnManager() : fLock("disk system add-ons manager"), fAddOns(), + fAddOnsToBeUnloaded(), fLoadCount(0) { } @@ -173,3 +233,114 @@ return (AddOn*)fAddOns.ItemAt(index); } + +// _PutAddOn +void +DiskSystemAddOnManager::_PutAddOn(int32 index) +{ + AddOn* addOn = (AddOn*)fAddOnsToBeUnloaded.ItemAt(index); + if (!addOn) + return; + + if (--addOn->refCount == 0) { + if (--addOn->image->refCount == 0) + delete addOn->image; + + fAddOnsToBeUnloaded.RemoveItem(index); + delete addOn; + } +} + + +// _LoadAddOns +status_t +DiskSystemAddOnManager::_LoadAddOns(StringSet& alreadyLoaded, + directory_which addOnDir) +{ + // get the add-on directory path + BPath path; + status_t error = find_directory(addOnDir, &path, false); + if (error != B_OK) + return error; + + error = path.Append("disk_systems"); + if (error != B_OK) + return error; + + if (!BEntry(path.Path()).Exists()) + return B_OK; + + // open the directory and iterate through its entries + BDirectory directory; + error = directory.SetTo(path.Path()); + if (error != B_OK) + return error; + + entry_ref ref; + while (directory.GetNextRef(&ref) == B_OK) { + // skip, if already loaded + if (alreadyLoaded.find(ref.name) != alreadyLoaded.end()) + continue; + + // get the entry path + BPath entryPath; + error = entryPath.SetTo(&ref); + if (error != B_OK) { + if (error == B_NO_MEMORY) + return error; + continue; + } + + // load the add-on + image_id image = load_add_on(entryPath.Path()); + if (image < 0) + continue; + + AddOnImage* addOnImage = new(nothrow) AddOnImage(image); + if (!addOnImage) { + unload_add_on(image); + return B_NO_MEMORY; + } + ObjectDeleter addOnImageDeleter(addOnImage); + + // get the add-on objects + status_t (*getAddOns)(BList*); + error = get_image_symbol(image, "get_disk_system_add_ons", + B_SYMBOL_TYPE_TEXT, (void**)&getAddOns); + if (error != B_OK) + continue; + + BList addOns; + error = getAddOns(&addOns); + if (error != B_OK || addOns.IsEmpty()) + continue; + + // create and add AddOn objects + int32 count = addOns.CountItems(); + for (int32 i = 0; i < count; i++) { + BDiskSystemAddOn* diskSystemAddOn + = (BDiskSystemAddOn*)addOns.ItemAt(i); + AddOn* addOn = new(nothrow) AddOn(addOnImage, diskSystemAddOn); + if (!addOn) + return B_NO_MEMORY; + + if (fAddOns.AddItem(addOn)) { + addOnImage->refCount++; + addOnImageDeleter.Detach(); + } else { + delete addOn; + return B_NO_MEMORY; + } + } + + // add the add-on name to the set of already loaded add-ons + try { + alreadyLoaded.insert(ref.name); + } catch (std::bad_alloc& exception) { + return B_NO_MEMORY; + } + } + + return B_OK; +} + Modified: haiku/trunk/src/kits/storage/DiskSystemAddOnManager.h =================================================================== --- haiku/trunk/src/kits/storage/DiskSystemAddOnManager.h 2007-10-13 22:13:42 UTC (rev 22543) +++ haiku/trunk/src/kits/storage/DiskSystemAddOnManager.h 2007-10-13 23:17:44 UTC (rev 22544) @@ -5,6 +5,7 @@ #ifndef _DISK_SYSTEM_ADD_ON_MANAGER_H #define _DISK_SYSTEM_ADD_ON_MANAGER_H +#include #include #include @@ -23,7 +24,7 @@ void Unlock(); // load/unload all disk system add-ons - void LoadDiskSystems(); + status_t LoadDiskSystems(); void UnloadDiskSystems(); // manager must be locked @@ -37,14 +38,20 @@ private: struct AddOnImage; struct AddOn; + struct StringSet; DiskSystemAddOnManager(); AddOn* _AddOnAt(int32 index) const; + void _PutAddOn(int32 index); + status_t _LoadAddOns(StringSet& alreadyLoaded, + directory_which directory); + private: mutable BLocker fLock; BList fAddOns; + BList fAddOnsToBeUnloaded; int32 fLoadCount; static DiskSystemAddOnManager* sManager; From sbenedetto at mail.berlios.de Sun Oct 14 01:22:26 2007 From: sbenedetto at mail.berlios.de (sbenedetto at BerliOS) Date: Sun, 14 Oct 2007 01:22:26 +0200 Subject: [Haiku-commits] r22545 - haiku/trunk/src/add-ons/kernel/busses/usb Message-ID: <200710132322.l9DNMQDI005704@sheep.berlios.de> Author: sbenedetto Date: 2007-10-14 01:22:25 +0200 (Sun, 14 Oct 2007) New Revision: 22545 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22545&view=rev Modified: haiku/trunk/src/add-ons/kernel/busses/usb/uhci.cpp haiku/trunk/src/add-ons/kernel/busses/usb/uhci.h haiku/trunk/src/add-ons/kernel/busses/usb/uhci_rh.cpp Log: * Fix some bugs introduced by myself ;) * Removed IOC bit on last TD. To find out whether the TD removed is the last one of a transfer it simply iterate through every transfer submitted. Not the best solution, but should be ok for now. Improvements will be made when there will be some driver to test it with. * Clean up Modified: haiku/trunk/src/add-ons/kernel/busses/usb/uhci.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/usb/uhci.cpp 2007-10-13 23:17:44 UTC (rev 22544) +++ haiku/trunk/src/add-ons/kernel/busses/usb/uhci.cpp 2007-10-13 23:22:25 UTC (rev 22545) @@ -15,10 +15,7 @@ #include #include "uhci.h" -#include "uhci_hardware.h" -#include "usb_p.h" - pci_module_info *UHCI::sPCIModule = NULL; @@ -800,6 +797,7 @@ data->last_to_process = transfer->IsochronousData()->packet_count - 1; data->incoming = directionIn; data->is_active = true; + data->link = NULL; // Put in the isochronous transfer list if (!LockIsochronous()) { @@ -829,6 +827,13 @@ packetSize /= isochronousData->packet_count; uint16 currentFrame; + if (packetSize > pipe->MaxPacketSize()) + { + TRACE_ERROR(("usb_uhci: isochronous packetSize is bigger" + " than pipe MaxPacketSize\n")); + return B_BAD_VALUE; + } + // Ignore the fact that the last descriptor might need less bandwidth. // The overhead is not worthy. uint16 bandwidth = transfer->Bandwidth() / isochronousData->packet_count; @@ -842,11 +847,22 @@ // other in a queue like for every other transfer. uhci_td **isoRequest = new(std::nothrow) uhci_td *[isochronousData->packet_count]; + if (isoRequest == NULL) { + TRACE(("usb_uhci: failed to create isoRequest array!\n")); + return B_NO_MEMORY; + } // Create the list of transfer descriptors for (uint32 i = 0; i < (isochronousData->packet_count - 1); i++) { isoRequest[i] = CreateDescriptor(pipe, directionIn ? TD_TOKEN_IN : TD_TOKEN_OUT, packetSize); + // If we ran out of memory, clean up and return + if (isoRequest[i] == NULL) { + for (uint32 j = 0; j < i; j++) + FreeDescriptor(isoRequest[j]); + delete [] isoRequest; + return B_NO_MEMORY; + } // Make sure data toggle is set to zero isoRequest[i]->token &= ~TD_TOKEN_DATA1; } @@ -854,9 +870,16 @@ // Create the last transfer descriptor which should be of smaller size // and set the IOC bit isoRequest[isochronousData->packet_count - 1] = CreateDescriptor(pipe, - directionIn ? TD_TOKEN_IN : TD_TOKEN_OUT, restSize); + directionIn ? TD_TOKEN_IN : TD_TOKEN_OUT, + (restSize) ? restSize : packetSize); + // If we are that unlucky... + if (!isoRequest[isochronousData->packet_count - 1]) { + for (uint32 i = 0; i < (isochronousData->packet_count - 2); i++) + FreeDescriptor(isoRequest[i]); + delete [] isoRequest; + return B_NO_MEMORY; + } isoRequest[isochronousData->packet_count - 1]->token &= ~TD_TOKEN_DATA1; - isoRequest[isochronousData->packet_count - 1]->status |= TD_CONTROL_IOC; // If direction is out set every descriptor data if (!directionIn) { @@ -904,7 +927,10 @@ if (currentFrame == startSeekingFromFrame) { TRACE_ERROR(("usb_uhci: Not enough bandwidth to queue the" " isochronous request. Try again later!\n")); - return B_ERROR; + for (uint32 i = 0; i < isochronousData->packet_count; i++) + FreeDescriptor(isoRequest[i]); + delete [] isoRequest; + return B_ERROR; } } @@ -916,10 +942,9 @@ directionIn); if (result < B_OK) { TRACE_ERROR(("usb_uhci: failed to add pending isochronous transfer\n")); - for (uint32 i = 0; i < isochronousData->packet_count; i++) { + for (uint32 i = 0; i < isochronousData->packet_count; i++) FreeDescriptor(isoRequest[i]); - delete [] isoRequest; - } + delete [] isoRequest; return result; } @@ -930,7 +955,15 @@ // the starting_frame_number entry // TODO: We don't consider bInterval, and assume it's 1! for (uint32 i = 0; i < isochronousData->packet_count; i++) { - LinkIsochronousDescriptor(isoRequest[i], currentFrame); + result = LinkIsochronousDescriptor(isoRequest[i], currentFrame); + if (result < B_OK) { + TRACE_ERROR(("usb_uhci: failed to add pending isochronous transfer\n")); + for (uint32 i = 0; i < isochronousData->packet_count; i++) + FreeDescriptor(isoRequest[i]); + delete [] isoRequest; + return result; + } + fFrameBandwidth[currentFrame] -= bandwidth; currentFrame = (currentFrame + 1) % NUMBER_OF_FRAMES; } @@ -946,54 +979,73 @@ UHCI::FindIsochronousTransfer(uhci_td *descriptor) { // Simply check every last descriptor of the isochronous transfer list - LockIsochronous(); - isochronous_transfer_data *transfer = fFirstIsochronousTransfer; - while (transfer->descriptors[transfer->last_to_process] != descriptor) { - transfer = transfer->link; - if (!transfer) - break; + if (LockIsochronous()) { + isochronous_transfer_data *transfer = fFirstIsochronousTransfer; + if (transfer) { + while (transfer->descriptors[transfer->last_to_process] + != descriptor) { + transfer = transfer->link; + if (!transfer) + break; + } + } + UnlockIsochronous(); + return transfer; } - - UnlockIsochronous(); - return transfer; + return NULL; } -void +status_t UHCI::LinkIsochronousDescriptor(uhci_td *descriptor, uint16 frame) { // The transfer descriptor is appended to the last // existing isochronous transfer descriptor (if any) // in that frame. - if (fFrameList[frame] & FRAMELIST_NEXT_IS_QH) { - // Insert the transfer descriptor in the first position - descriptor->link_phy = fFrameList[frame]; - // No need to set the link_log as it is already NULL - fFrameList[frame] = descriptor->this_phy & ~FRAMELIST_NEXT_IS_QH; - fFirstIsochronousDescriptor[frame] = descriptor; - fLastIsochronousDescriptor[frame] = descriptor; - } else { - // Append to the last transfer descriptor - descriptor->link_phy = fLastIsochronousDescriptor[frame]->link_phy; - fLastIsochronousDescriptor[frame]->link_log = descriptor; - fLastIsochronousDescriptor[frame]->link_phy - = descriptor->this_phy & ~TD_NEXT_IS_QH; - fLastIsochronousDescriptor[frame] = descriptor; + if (LockIsochronous()) { + if (!fFirstIsochronousDescriptor[frame]) { + // Insert the transfer descriptor in the first position + fFrameList[frame] = descriptor->this_phy & ~FRAMELIST_NEXT_IS_QH; + fFirstIsochronousDescriptor[frame] = descriptor; + fLastIsochronousDescriptor[frame] = descriptor; + } else { + // Append to the last transfer descriptor + fLastIsochronousDescriptor[frame]->link_log = descriptor; + fLastIsochronousDescriptor[frame]->link_phy + = descriptor->this_phy & ~TD_NEXT_IS_QH; + fLastIsochronousDescriptor[frame] = descriptor; + } + + descriptor->link_phy + = fQueues[UHCI_INTERRUPT_QUEUE]->PhysicalAddress() | TD_NEXT_IS_QH; + UnlockIsochronous(); + return B_OK; } + return B_ERROR; } -void -UHCI::UnlinkIsochronousDescriptor(uhci_td *descriptor, uint16 frame) +uhci_td * +UHCI::UnlinkIsochronousDescriptor(uint16 frame) { - // The pointer to the descriptor is in descriptors[frame] and it will be - // freed later. - fFrameList[frame] = descriptor->link_phy; - if (fFrameList[frame] & FRAMELIST_NEXT_IS_QH) { - fFirstIsochronousDescriptor[frame] = NULL; - fLastIsochronousDescriptor[frame] = NULL; - } else - fFirstIsochronousDescriptor[frame] = (uhci_td *)descriptor->link_log; + // We always unlink from the top + if (LockIsochronous()) { + uhci_td *descriptor = fFirstIsochronousDescriptor[frame]; + if (descriptor) { + // The descriptor will be freed later. + fFrameList[frame] = descriptor->link_phy; + if (descriptor->link_log) { + fFirstIsochronousDescriptor[frame] + = (uhci_td *)descriptor->link_log; + } else { + fFirstIsochronousDescriptor[frame] = NULL; + fLastIsochronousDescriptor[frame] = NULL; + } + } + UnlockIsochronous(); + return descriptor; + } + return NULL; } @@ -1233,47 +1285,38 @@ // Process the frame till it has isochronous descriptors in it. while (!(fFrameList[currentFrame] & FRAMELIST_NEXT_IS_QH)) { - uhci_td *current = fFirstIsochronousDescriptor[currentFrame]; - UnlinkIsochronousDescriptor(current, currentFrame); + uhci_td *current = UnlinkIsochronousDescriptor(currentFrame); // Process the transfer if we found the last descriptor - if (current->status & TD_CONTROL_IOC) { - isochronous_transfer_data *transfer - = FindIsochronousTransfer(current); - - // The following should NEVER happen - if (!transfer) { - TRACE_ERROR(("usb_uhci: Isochronous transfer not found" - " in the finisher thread!\n")); - return; - + isochronous_transfer_data *transfer + = FindIsochronousTransfer(current); // Process the descriptors only if it is still active and // belongs to an inbound transfer. If the transfer is not // active, it means the request has been removed, so simply // remove the descriptors. - } else if (transfer->is_active - && (current->status & TD_TOKEN_IN)) { + if (transfer && transfer->is_active) { + if (current->token & TD_TOKEN_IN) { iovec *vector = transfer->transfer->Vector(); transfer->transfer->PrepareKernelAccess(); ReadIsochronousDescriptorChain(transfer, vector); + } - // Remove the transfer - if (LockIsochronous()) { - if (transfer == fFirstIsochronousTransfer) - fFirstIsochronousTransfer = transfer->link; - else { - isochronous_transfer_data *temp - = fFirstIsochronousTransfer; - while (transfer != temp->link) - temp = temp->link; + // Remove the transfer + if (LockIsochronous()) { + if (transfer == fFirstIsochronousTransfer) + fFirstIsochronousTransfer = transfer->link; + else { + isochronous_transfer_data *temp + = fFirstIsochronousTransfer; + while (transfer != temp->link) + temp = temp->link; - if (transfer == fLastIsochronousTransfer) - fLastIsochronousTransfer = temp; - temp->link = temp->link->link; - } - - UnlockIsochronous(); + if (transfer == fLastIsochronousTransfer) + fLastIsochronousTransfer = temp; + temp->link = temp->link->link; } + UnlockIsochronous(); + } transfer->transfer->Finished(B_OK, 0); @@ -1286,7 +1329,6 @@ delete transfer->transfer; delete transfer; transferDone = true; - } } } @@ -1295,7 +1337,6 @@ currentFrame = (currentFrame + 1) % NUMBER_OF_FRAMES; } } - } @@ -1574,7 +1615,8 @@ continue; } - TRACE(("usb_uhci: AddTo(): found at IRQ %u\n", item->u.h0.interrupt_line)); + TRACE(("usb_uhci: AddTo(): found at IRQ %u\n", + item->u.h0.interrupt_line)); UHCI *bus = new(std::nothrow) UHCI(item, stack); if (!bus) { delete item; @@ -1584,7 +1626,8 @@ } if (bus->InitCheck() < B_OK) { - TRACE_ERROR(("usb_uhci: AddTo(): InitCheck() failed 0x%08lx\n", bus->InitCheck())); + TRACE_ERROR(("usb_uhci: AddTo(): InitCheck() failed 0x%08lx\n", + bus->InitCheck())); delete bus; continue; } @@ -1979,9 +2022,9 @@ for (uint32 i = 0; i < isochronousData->packet_count; i++) { uhci_td *current = transfer->descriptors[i]; - size_t bufferSize - = isochronousData->packet_descriptors[i].request_length; - int16 actualLength = (current->status & TD_STATUS_ACTLEN_MASK) + 1; + size_t bufferSize = current->buffer_size; + size_t actualLength = (current->status & TD_STATUS_ACTLEN_MASK) + 1; + if (actualLength == TD_STATUS_ACTLEN_NULL + 1) actualLength = 0; @@ -1989,9 +2032,11 @@ if (actualLength > 0) isochronousData->packet_descriptors[i].status = B_OK; - else + else { isochronousData->packet_descriptors[i].status = B_ERROR; - + vectorOffset += bufferSize; + continue; + } memcpy((uint8 *)vector->iov_base + vectorOffset, (uint8 *)current->buffer_log, bufferSize); Modified: haiku/trunk/src/add-ons/kernel/busses/usb/uhci.h =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/usb/uhci.h 2007-10-13 23:17:44 UTC (rev 22544) +++ haiku/trunk/src/add-ons/kernel/busses/usb/uhci.h 2007-10-13 23:22:25 UTC (rev 22545) @@ -138,12 +138,10 @@ void FinishIsochronousTransfers(); isochronous_transfer_data *FindIsochronousTransfer(uhci_td *descriptor); - void LinkIsochronousDescriptor( + status_t LinkIsochronousDescriptor( uhci_td *descriptor, uint16 frame); - void UnlinkIsochronousDescriptor( - uhci_td *descriptor, - uint16 frame); + uhci_td *UnlinkIsochronousDescriptor(uint16 frame); // Transfer queue functions uhci_qh *CreateTransferQueue(uhci_td *descriptor); Modified: haiku/trunk/src/add-ons/kernel/busses/usb/uhci_rh.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/usb/uhci_rh.cpp 2007-10-13 23:17:44 UTC (rev 22544) +++ haiku/trunk/src/add-ons/kernel/busses/usb/uhci_rh.cpp 2007-10-13 23:22:25 UTC (rev 22545) @@ -138,7 +138,6 @@ return B_ERROR; usb_request_data *request = transfer->RequestData(); - TRACE(("usb_uhci_roothub: request: %d\n", request->Request)); status_t status = B_TIMED_OUT; size_t actualLength = 0; From bonefish at mail.berlios.de Sun Oct 14 02:00:51 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sun, 14 Oct 2007 02:00:51 +0200 Subject: [Haiku-commits] r22546 - haiku/trunk/src/add-ons/disk_systems Message-ID: <200710140000.l9E00pXO008511@sheep.berlios.de> Author: bonefish Date: 2007-10-14 02:00:51 +0200 (Sun, 14 Oct 2007) New Revision: 22546 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22546&view=rev Added: haiku/trunk/src/add-ons/disk_systems/Jamfile Log: Missed to add this one. Added: haiku/trunk/src/add-ons/disk_systems/Jamfile =================================================================== --- haiku/trunk/src/add-ons/disk_systems/Jamfile 2007-10-13 23:22:25 UTC (rev 22545) +++ haiku/trunk/src/add-ons/disk_systems/Jamfile 2007-10-14 00:00:51 UTC (rev 22546) @@ -0,0 +1,3 @@ +SubDir HAIKU_TOP src add-ons disk_systems ; + +SubInclude HAIKU_TOP src add-ons disk_systems intel ; From bonefish at mail.berlios.de Sun Oct 14 02:07:04 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sun, 14 Oct 2007 02:07:04 +0200 Subject: [Haiku-commits] r22547 - in haiku/trunk: headers/private/storage src/kits/storage Message-ID: <200710140007.l9E074Mh008984@sheep.berlios.de> Author: bonefish Date: 2007-10-14 02:07:03 +0200 (Sun, 14 Oct 2007) New Revision: 22547 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22547&view=rev Modified: haiku/trunk/headers/private/storage/MutablePartition.h haiku/trunk/headers/private/storage/Partition.h haiku/trunk/src/kits/storage/MutablePartition.cpp haiku/trunk/src/kits/storage/PartitionDelegate.cpp haiku/trunk/src/kits/storage/PartitionDelegate.h Log: Decided that BPartition::ImmutableDelegate would basically be a big collection of no-op methods, which could as well be implemented in BPartition itself. This makes the Delegate hierarchy unnecessary: MutableDelegate becomes Delegate, and we save a few casts as a side effect. Modified: haiku/trunk/headers/private/storage/MutablePartition.h =================================================================== --- haiku/trunk/headers/private/storage/MutablePartition.h 2007-10-14 00:00:51 UTC (rev 22546) +++ haiku/trunk/headers/private/storage/MutablePartition.h 2007-10-14 00:07:03 UTC (rev 22547) @@ -72,7 +72,7 @@ private: BMutablePartition( - BPartition::MutableDelegate* delegate); + BPartition::Delegate* delegate); ~BMutablePartition(); status_t Init(const user_partition_data* partitionData, @@ -81,11 +81,11 @@ const user_partition_data* PartitionData() const; private: - friend class BPartition::MutableDelegate; + friend class BPartition::Delegate; - BPartition::MutableDelegate* GetDelegate() const; + BPartition::Delegate* GetDelegate() const; - BPartition::MutableDelegate* fDelegate; + BPartition::Delegate* fDelegate; user_partition_data* fData; BMutablePartition* fParent; BList fChildren; Modified: haiku/trunk/headers/private/storage/Partition.h =================================================================== --- haiku/trunk/headers/private/storage/Partition.h 2007-10-14 00:00:51 UTC (rev 22546) +++ haiku/trunk/headers/private/storage/Partition.h 2007-10-14 00:07:03 UTC (rev 22547) @@ -142,8 +142,6 @@ private: class Delegate; - class ImmutableDelegate; - class MutableDelegate; BPartition(); BPartition(const BPartition &); Modified: haiku/trunk/src/kits/storage/MutablePartition.cpp =================================================================== --- haiku/trunk/src/kits/storage/MutablePartition.cpp 2007-10-14 00:00:51 UTC (rev 22546) +++ haiku/trunk/src/kits/storage/MutablePartition.cpp 2007-10-14 00:07:03 UTC (rev 22547) @@ -260,9 +260,9 @@ if (!partition) return B_NO_MEMORY; - // create the MutableDelegate - BPartition::MutableDelegate* delegate - = new(nothrow) BPartition::MutableDelegate(partition); + // create the delegate + BPartition::Delegate* delegate + = new(nothrow) BPartition::Delegate(partition); if (!delegate) { delete partition; return B_NO_MEMORY; @@ -386,7 +386,7 @@ // constructor -BMutablePartition::BMutablePartition(BPartition::MutableDelegate* delegate) +BMutablePartition::BMutablePartition(BPartition::Delegate* delegate) : fDelegate(delegate), fData(NULL), fParent(NULL), @@ -467,7 +467,7 @@ // GetDelegate -BPartition::MutableDelegate* +BPartition::Delegate* BMutablePartition::GetDelegate() const { return fDelegate; Modified: haiku/trunk/src/kits/storage/PartitionDelegate.cpp =================================================================== --- haiku/trunk/src/kits/storage/PartitionDelegate.cpp 2007-10-14 00:00:51 UTC (rev 22546) +++ haiku/trunk/src/kits/storage/PartitionDelegate.cpp 2007-10-14 00:07:03 UTC (rev 22547) @@ -10,28 +10,9 @@ #include "DiskSystemAddOnManager.h" -// #pragma mark - Delegate - - // constructor BPartition::Delegate::Delegate(BPartition* partition) - : fPartition(partition) -{ -} - - -// destructor -BPartition::Delegate::~Delegate() -{ -} - - -// #pragma mark - MutableDelegate - - -// constructor -BPartition::MutableDelegate::MutableDelegate(BPartition* partition) - : Delegate(partition), + : fPartition(partition), fMutablePartition(this), fDiskSystem(NULL), fPartitionHandle(NULL) @@ -40,14 +21,14 @@ // destructor -BPartition::MutableDelegate::~MutableDelegate() +BPartition::Delegate::~Delegate() { } // MutablePartition BMutablePartition* -BPartition::MutableDelegate::MutablePartition() +BPartition::Delegate::MutablePartition() { return &fMutablePartition; } @@ -55,7 +36,7 @@ // MutablePartition const BMutablePartition* -BPartition::MutableDelegate::MutablePartition() const +BPartition::Delegate::MutablePartition() const { return &fMutablePartition; } @@ -63,10 +44,9 @@ // InitHierarchy status_t -BPartition::MutableDelegate::InitHierarchy( - const user_partition_data* partitionData, Delegate* _parent) +BPartition::Delegate::InitHierarchy( + const user_partition_data* partitionData, Delegate* parent) { - MutableDelegate* parent = dynamic_cast(_parent); return fMutablePartition.Init(partitionData, parent ? &parent->fMutablePartition : NULL); } @@ -74,7 +54,7 @@ // InitAfterHierarchy status_t -BPartition::MutableDelegate::InitAfterHierarchy() +BPartition::Delegate::InitAfterHierarchy() { if (!fMutablePartition.ContentType()) return B_OK; @@ -104,7 +84,7 @@ // PartitionData const user_partition_data* -BPartition::MutableDelegate::PartitionData() const +BPartition::Delegate::PartitionData() const { return fMutablePartition.PartitionData(); } @@ -112,7 +92,7 @@ // ChildAt BPartition::Delegate* -BPartition::MutableDelegate::ChildAt(int32 index) const +BPartition::Delegate::ChildAt(int32 index) const { BMutablePartition* child = fMutablePartition.ChildAt(index); return child ? child->GetDelegate() : NULL; @@ -121,7 +101,7 @@ // CountChildren int32 -BPartition::MutableDelegate::CountChildren() const +BPartition::Delegate::CountChildren() const { return fMutablePartition.CountChildren(); } @@ -129,7 +109,7 @@ // SupportedOperations uint32 -BPartition::MutableDelegate::SupportedOperations(uint32 mask) +BPartition::Delegate::SupportedOperations(uint32 mask) { if (!fPartitionHandle) return 0; @@ -140,20 +120,20 @@ // SupportedChildOperations uint32 -BPartition::MutableDelegate::SupportedChildOperations(Delegate* child, +BPartition::Delegate::SupportedChildOperations(Delegate* child, uint32 mask) { if (!fPartitionHandle) return 0; - return fPartitionHandle->SupportedChildOperations( - ((MutableDelegate*)child)->MutablePartition(), mask); + return fPartitionHandle->SupportedChildOperations(child->MutablePartition(), + mask); } // Defragment status_t -BPartition::MutableDelegate::Defragment() +BPartition::Delegate::Defragment() { // TODO: Implement! return B_BAD_VALUE; @@ -162,7 +142,7 @@ // Repair status_t -BPartition::MutableDelegate::Repair(bool checkOnly) +BPartition::Delegate::Repair(bool checkOnly) { // TODO: Implement! return B_BAD_VALUE; @@ -171,7 +151,7 @@ // ValidateResize status_t -BPartition::MutableDelegate::ValidateResize(off_t* size) const +BPartition::Delegate::ValidateResize(off_t* size) const { if (!fPartitionHandle) return B_NO_INIT; @@ -182,11 +162,8 @@ // ValidateResizeChild status_t -BPartition::MutableDelegate::ValidateResizeChild(Delegate* _child, - off_t* size) const +BPartition::Delegate::ValidateResizeChild(Delegate* child, off_t* size) const { - MutableDelegate* child = dynamic_cast(_child); - if (!fPartitionHandle || !child) return B_NO_INIT; @@ -197,7 +174,7 @@ // Resize status_t -BPartition::MutableDelegate::Resize(off_t size) +BPartition::Delegate::Resize(off_t size) { if (!fPartitionHandle) return B_NO_INIT; @@ -208,10 +185,8 @@ // ResizeChild status_t -BPartition::MutableDelegate::ResizeChild(Delegate* _child, off_t size) +BPartition::Delegate::ResizeChild(Delegate* child, off_t size) { - MutableDelegate* child = dynamic_cast(_child); - if (!fPartitionHandle || !child) return B_NO_INIT; @@ -221,7 +196,7 @@ // ValidateMove status_t -BPartition::MutableDelegate::ValidateMove(off_t* offset) const +BPartition::Delegate::ValidateMove(off_t* offset) const { if (!fPartitionHandle) return B_NO_INIT; @@ -232,11 +207,8 @@ // ValidateMoveChild status_t -BPartition::MutableDelegate::ValidateMoveChild(Delegate* _child, - off_t* offset) const +BPartition::Delegate::ValidateMoveChild(Delegate* child, off_t* offset) const { - MutableDelegate* child = dynamic_cast(_child); - if (!fPartitionHandle || !child) return B_NO_INIT; @@ -247,7 +219,7 @@ // Move status_t -BPartition::MutableDelegate::Move(off_t offset) +BPartition::Delegate::Move(off_t offset) { if (!fPartitionHandle) return B_NO_INIT; @@ -258,10 +230,8 @@ // MoveChild status_t -BPartition::MutableDelegate::MoveChild(Delegate* _child, off_t offset) +BPartition::Delegate::MoveChild(Delegate* child, off_t offset) { - MutableDelegate* child = dynamic_cast(_child); - if (!fPartitionHandle || !child) return B_NO_INIT; @@ -271,7 +241,7 @@ // ValidateSetContentName status_t -BPartition::MutableDelegate::ValidateSetContentName(BString* name) const +BPartition::Delegate::ValidateSetContentName(BString* name) const { if (!fPartitionHandle) return B_NO_INIT; @@ -282,11 +252,8 @@ // ValidateSetName status_t -BPartition::MutableDelegate::ValidateSetName(Delegate* _child, - BString* name) const +BPartition::Delegate::ValidateSetName(Delegate* child, BString* name) const { - MutableDelegate* child = dynamic_cast(_child); - if (!fPartitionHandle || !child) return B_NO_INIT; @@ -296,7 +263,7 @@ // SetContentName status_t -BPartition::MutableDelegate::SetContentName(const char* name) +BPartition::Delegate::SetContentName(const char* name) { if (!fPartitionHandle) return B_NO_INIT; @@ -307,10 +274,8 @@ // SetName status_t -BPartition::MutableDelegate::SetName(Delegate* _child, const char* name) +BPartition::Delegate::SetName(Delegate* child, const char* name) { - MutableDelegate* child = dynamic_cast(_child); - if (!fPartitionHandle || !child) return B_NO_INIT; @@ -320,11 +285,8 @@ // ValidateSetType status_t -BPartition::MutableDelegate::ValidateSetType(Delegate* _child, - const char* type) const +BPartition::Delegate::ValidateSetType(Delegate* child, const char* type) const { - MutableDelegate* child = dynamic_cast(_child); - if (!fPartitionHandle || !child) return B_NO_INIT; @@ -334,10 +296,8 @@ // SetType status_t -BPartition::MutableDelegate::SetType(Delegate* _child, const char* type) +BPartition::Delegate::SetType(Delegate* child, const char* type) { - MutableDelegate* child = dynamic_cast(_child); - if (!fPartitionHandle || !child) return B_NO_INIT; @@ -347,7 +307,7 @@ // GetContentParameterEditor status_t -BPartition::MutableDelegate::GetContentParameterEditor( +BPartition::Delegate::GetContentParameterEditor( BDiskDeviceParameterEditor** editor) const { if (!fPartitionHandle) @@ -359,11 +319,9 @@ // GetParameterEditor status_t -BPartition::MutableDelegate::GetParameterEditor(Delegate* _child, +BPartition::Delegate::GetParameterEditor(Delegate* child, BDiskDeviceParameterEditor** editor) const { - MutableDelegate* child = dynamic_cast(_child); - if (!fPartitionHandle || !child) return B_NO_INIT; @@ -374,7 +332,7 @@ // SetContentParameters status_t -BPartition::MutableDelegate::SetContentParameters(const char* parameters) +BPartition::Delegate::SetContentParameters(const char* parameters) { if (!fPartitionHandle) return B_NO_INIT; @@ -385,11 +343,8 @@ // SetParameters status_t -BPartition::MutableDelegate::SetParameters(Delegate* _child, - const char* parameters) +BPartition::Delegate::SetParameters(Delegate* child, const char* parameters) { - MutableDelegate* child = dynamic_cast(_child); - if (!fPartitionHandle || !child) return B_NO_INIT; @@ -400,7 +355,7 @@ // CanInitialize bool -BPartition::MutableDelegate::CanInitialize(const char* diskSystem) const +BPartition::Delegate::CanInitialize(const char* diskSystem) const { // get the disk system add-on DiskSystemAddOnManager* manager = DiskSystemAddOnManager::Default(); @@ -419,7 +374,7 @@ // GetInitializationParameterEditor status_t -BPartition::MutableDelegate::GetInitializationParameterEditor( +BPartition::Delegate::GetInitializationParameterEditor( const char* diskSystem, BDiskDeviceParameterEditor** editor) const { // get the disk system add-on @@ -440,7 +395,7 @@ // ValidateInitialize status_t -BPartition::MutableDelegate::ValidateInitialize(const char* diskSystem, +BPartition::Delegate::ValidateInitialize(const char* diskSystem, BString* name, const char* parameters) { // get the disk system add-on @@ -461,7 +416,7 @@ // Initialize status_t -BPartition::MutableDelegate::Initialize(const char* diskSystem, +BPartition::Delegate::Initialize(const char* diskSystem, const char* name, const char* parameters) { // get the disk system add-on @@ -491,7 +446,7 @@ // Uninitialize status_t -BPartition::MutableDelegate::Uninitialize() +BPartition::Delegate::Uninitialize() { if (fPartitionHandle) { _FreeHandle(); @@ -505,7 +460,7 @@ // GetChildCreationParameterEditor status_t -BPartition::MutableDelegate::GetChildCreationParameterEditor(const char* type, +BPartition::Delegate::GetChildCreationParameterEditor(const char* type, BDiskDeviceParameterEditor** editor) const { if (!fPartitionHandle) @@ -517,7 +472,7 @@ // ValidateCreateChild status_t -BPartition::MutableDelegate::ValidateCreateChild(off_t* start, off_t* size, +BPartition::Delegate::ValidateCreateChild(off_t* start, off_t* size, const char* type, BString* name, const char* parameters) const { if (!fPartitionHandle) @@ -530,9 +485,8 @@ // CreateChild status_t -BPartition::MutableDelegate::CreateChild(off_t start, off_t size, - const char* type, const char* name, const char* parameters, - BPartition** child) +BPartition::Delegate::CreateChild(off_t start, off_t size, const char* type, + const char* name, const char* parameters, BPartition** child) { if (!fPartitionHandle) return B_NO_INIT; @@ -552,10 +506,8 @@ // DeleteChild status_t -BPartition::MutableDelegate::DeleteChild(Delegate* _child) +BPartition::Delegate::DeleteChild(Delegate* child) { - MutableDelegate* child = dynamic_cast(_child); - if (!fPartitionHandle || !child) return B_NO_INIT; @@ -565,7 +517,7 @@ // _FreeHandle void -BPartition::MutableDelegate::_FreeHandle() +BPartition::Delegate::_FreeHandle() { if (fPartitionHandle) { delete fPartitionHandle; Modified: haiku/trunk/src/kits/storage/PartitionDelegate.h =================================================================== --- haiku/trunk/src/kits/storage/PartitionDelegate.h 2007-10-14 00:00:51 UTC (rev 22546) +++ haiku/trunk/src/kits/storage/PartitionDelegate.h 2007-10-14 00:07:03 UTC (rev 22547) @@ -16,184 +16,92 @@ class BPartition::Delegate { public: Delegate(BPartition* partition); - virtual ~Delegate(); + ~Delegate(); - virtual status_t InitHierarchy( - const user_partition_data* partitionData, - Delegate* parent) = 0; - virtual status_t InitAfterHierarchy() = 0; - BPartition* Partition() const { return fPartition; } - virtual const user_partition_data* PartitionData() const = 0; - - virtual Delegate* ChildAt(int32 index) const = 0; - virtual int32 CountChildren() const = 0; - - virtual uint32 SupportedOperations(uint32 mask) = 0; - virtual uint32 SupportedChildOperations(Delegate* child, - uint32 mask) = 0; - - // Self Modification - - virtual status_t Defragment() = 0; - virtual status_t Repair(bool checkOnly) = 0; - - virtual status_t ValidateResize(off_t* size) const = 0; - virtual status_t ValidateResizeChild(Delegate* child, - off_t* size) const = 0; - virtual status_t Resize(off_t size) = 0; - virtual status_t ResizeChild(Delegate* child, off_t size) = 0; - - virtual status_t ValidateMove(off_t* offset) const = 0; - virtual status_t ValidateMoveChild(Delegate* child, - off_t* offset) const = 0; - virtual status_t Move(off_t offset) = 0; - virtual status_t MoveChild(Delegate* child, off_t offset) = 0; - - virtual status_t ValidateSetContentName(BString* name) const = 0; - virtual status_t ValidateSetName(Delegate* child, - BString* name) const = 0; - virtual status_t SetContentName(const char* name) = 0; - virtual status_t SetName(Delegate* child, const char* name) = 0; - - virtual status_t ValidateSetType(Delegate* child, - const char* type) const = 0; - virtual status_t SetType(Delegate* child, const char* type) = 0; - - virtual status_t GetContentParameterEditor( - BDiskDeviceParameterEditor** editor) - const = 0; - virtual status_t GetParameterEditor(Delegate* child, - BDiskDeviceParameterEditor** editor) - const = 0; - virtual status_t SetContentParameters( - const char* parameters) = 0; - virtual status_t SetParameters(Delegate* child, - const char* parameters) = 0; - - virtual bool CanInitialize(const char* diskSystem) const = 0; - virtual status_t GetInitializationParameterEditor( - const char* system, - BDiskDeviceParameterEditor** editor) - const = 0; - virtual status_t ValidateInitialize(const char* diskSystem, - BString* name, const char* parameters) = 0; - virtual status_t Initialize(const char* diskSystem, - const char* name, - const char* parameters) = 0; - virtual status_t Uninitialize() = 0; - - // Modification of child partitions - - virtual status_t GetChildCreationParameterEditor( - const char* system, - BDiskDeviceParameterEditor** editor) - const = 0; - virtual status_t ValidateCreateChild(off_t* start, off_t* size, - const char* type, BString* name, - const char* parameters) const = 0; - virtual status_t CreateChild(off_t start, off_t size, - const char* type, const char* name, - const char* parameters, - BPartition** child) = 0; - - virtual status_t DeleteChild(Delegate* child) = 0; - - -protected: - BPartition* fPartition; -}; - - -class BPartition::MutableDelegate : public BPartition::Delegate { -public: - MutableDelegate(BPartition* partition); - virtual ~MutableDelegate(); - BMutablePartition* MutablePartition(); const BMutablePartition* MutablePartition() const; - virtual status_t InitHierarchy( + status_t InitHierarchy( const user_partition_data* partitionData, Delegate* parent); - virtual status_t InitAfterHierarchy(); + status_t InitAfterHierarchy(); - virtual const user_partition_data* PartitionData() const; + const user_partition_data* PartitionData() const; - virtual Delegate* ChildAt(int32 index) const; - virtual int32 CountChildren() const; + Delegate* ChildAt(int32 index) const; + int32 CountChildren() const; - virtual uint32 SupportedOperations(uint32 mask); - virtual uint32 SupportedChildOperations(Delegate* child, + uint32 SupportedOperations(uint32 mask); + uint32 SupportedChildOperations(Delegate* child, uint32 mask); - // Self Modification + // Self Modification - virtual status_t Defragment(); - virtual status_t Repair(bool checkOnly); + status_t Defragment(); + status_t Repair(bool checkOnly); - virtual status_t ValidateResize(off_t* size) const; - virtual status_t ValidateResizeChild(Delegate* child, + status_t ValidateResize(off_t* size) const; + status_t ValidateResizeChild(Delegate* child, off_t* size) const; - virtual status_t Resize(off_t size); - virtual status_t ResizeChild(Delegate* child, off_t size); + status_t Resize(off_t size); + status_t ResizeChild(Delegate* child, off_t size); - virtual status_t ValidateMove(off_t* offset) const; - virtual status_t ValidateMoveChild(Delegate* child, + status_t ValidateMove(off_t* offset) const; + status_t ValidateMoveChild(Delegate* child, off_t* offset) const; - virtual status_t Move(off_t offset); - virtual status_t MoveChild(Delegate* child, off_t offset); + status_t Move(off_t offset); + status_t MoveChild(Delegate* child, off_t offset); - virtual status_t ValidateSetContentName(BString* name) const; - virtual status_t ValidateSetName(Delegate* child, + status_t ValidateSetContentName(BString* name) const; + status_t ValidateSetName(Delegate* child, BString* name) const; - virtual status_t SetContentName(const char* name); - virtual status_t SetName(Delegate* child, const char* name); + status_t SetContentName(const char* name); + status_t SetName(Delegate* child, const char* name); - virtual status_t ValidateSetType(Delegate* child, + status_t ValidateSetType(Delegate* child, const char* type) const; - virtual status_t SetType(Delegate* child, const char* type); + status_t SetType(Delegate* child, const char* type); - virtual status_t GetContentParameterEditor( + status_t GetContentParameterEditor( BDiskDeviceParameterEditor** editor) const; - virtual status_t GetParameterEditor(Delegate* child, + status_t GetParameterEditor(Delegate* child, BDiskDeviceParameterEditor** editor) const; - virtual status_t SetContentParameters(const char* parameters); - virtual status_t SetParameters(Delegate* child, + status_t SetContentParameters(const char* parameters); + status_t SetParameters(Delegate* child, const char* parameters); - virtual bool CanInitialize(const char* diskSystem) const; - virtual status_t GetInitializationParameterEditor( + bool CanInitialize(const char* diskSystem) const; + status_t GetInitializationParameterEditor( const char* system, BDiskDeviceParameterEditor** editor) const; - virtual status_t ValidateInitialize(const char* diskSystem, + status_t ValidateInitialize(const char* diskSystem, BString* name, const char* parameters); - virtual status_t Initialize(const char* diskSystem, + status_t Initialize(const char* diskSystem, const char* name, const char* parameters); - virtual status_t Uninitialize(); + status_t Uninitialize(); - // Modification of child partitions + // Modification of child partitions - virtual status_t GetChildCreationParameterEditor( + status_t GetChildCreationParameterEditor( const char* system, BDiskDeviceParameterEditor** editor) const; - virtual status_t ValidateCreateChild(off_t* start, off_t* size, + status_t ValidateCreateChild(off_t* start, off_t* size, const char* type, BString* name, const char* parameters) const; - virtual status_t CreateChild(off_t start, off_t size, + status_t CreateChild(off_t start, off_t size, const char* type, const char* name, const char* parameters, BPartition** child); - virtual status_t DeleteChild(Delegate* child); + status_t DeleteChild(Delegate* child); private: void _FreeHandle(); private: -// friend class BMutablePartition; - + BPartition* fPartition; BMutablePartition fMutablePartition; BDiskSystemAddOn* fDiskSystem; BPartitionHandle* fPartitionHandle; From bonefish at mail.berlios.de Sun Oct 14 02:14:32 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sun, 14 Oct 2007 02:14:32 +0200 Subject: [Haiku-commits] r22548 - haiku/trunk/src/kits/storage Message-ID: <200710140014.l9E0EWjs010319@sheep.berlios.de> Author: bonefish Date: 2007-10-14 02:14:31 +0200 (Sun, 14 Oct 2007) New Revision: 22548 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22548&view=rev Modified: haiku/trunk/src/kits/storage/DiskSystemAddOnManager.cpp Log: gcc 4 fix. Modified: haiku/trunk/src/kits/storage/DiskSystemAddOnManager.cpp =================================================================== --- haiku/trunk/src/kits/storage/DiskSystemAddOnManager.cpp 2007-10-14 00:07:03 UTC (rev 22547) +++ haiku/trunk/src/kits/storage/DiskSystemAddOnManager.cpp 2007-10-14 00:14:31 UTC (rev 22548) @@ -6,6 +6,7 @@ #include "DiskSystemAddOnManager.h" #include +#include #include #include @@ -21,6 +22,9 @@ #include +using std::nothrow; + + // sManager DiskSystemAddOnManager* DiskSystemAddOnManager::sManager = NULL; From axeld at pinc-software.de Sun Oct 14 11:50:17 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Sun, 14 Oct 2007 11:50:17 +0200 CEST Subject: [Haiku-commits] =?iso-8859-15?q?r22533_-_in_haiku/trunk/src/syste?= =?iso-8859-15?q?m/libroot=3A_=2E_posix/glibc_posix/glibc/iconv_posix/glib?= =?iso-8859-15?q?c/include_posix/glibc/include/arch/ppc/bits_posix/glibc/i?= =?iso-8859-15?q?nclude/arch/x86/bits_posix/glibc/include/bits_posix/glibc?= =?iso-8859-15?q?/include/sys_posix/glibc/libio_posix/glibc/locale_posix/g?= =?iso-8859-15?q?libc/misc__posix/glibc/wcsmbs?= In-Reply-To: <200710131534.l9DFYKCQ005636@sheep.berlios.de> Message-ID: <2181769426-BeMail@zon> korli at BerliOS wrote: > Log: > added some tsearch and iconv functions, Our libtextencoding.so already contains libiconv. One of them should be removed IMO. Bye, Axel. From axeld at mail.berlios.de Sun Oct 14 13:03:58 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sun, 14 Oct 2007 13:03:58 +0200 Subject: [Haiku-commits] r22549 - haiku/trunk/src/servers/app Message-ID: <200710141103.l9EB3wJ0003401@sheep.berlios.de> Author: axeld Date: 2007-10-14 13:03:57 +0200 (Sun, 14 Oct 2007) New Revision: 22549 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22549&view=rev Modified: haiku/trunk/src/servers/app/WindowLayer.cpp haiku/trunk/src/servers/app/WorkspacesLayer.cpp Log: * WindowLayer::InWorkspace() was actually nowhere used the way it was implemented; it now only returns wether or not the window is part of the list specified by the index. This fixes bug #195 and #1553. * HasInSubset() would report "true" for app-floating windows vs. modal app windows which was wrong. * Removed SameSubset() as it isn't needed at all. * SubsetWorkspaces() now take the front window into account for floating windows. * Minor cleanup. Modified: haiku/trunk/src/servers/app/WindowLayer.cpp =================================================================== --- haiku/trunk/src/servers/app/WindowLayer.cpp 2007-10-14 00:14:31 UTC (rev 22548) +++ haiku/trunk/src/servers/app/WindowLayer.cpp 2007-10-14 11:03:57 UTC (rev 22549) @@ -68,10 +68,8 @@ WindowLayer::WindowLayer(const BRect& frame, const char *name, - window_look look, window_feel feel, - uint32 flags, uint32 workspaces, - ::ServerWindow* window, - DrawingEngine* drawingEngine) + window_look look, window_feel feel, uint32 flags, uint32 workspaces, + ::ServerWindow* window, DrawingEngine* drawingEngine) : fTitle(name), fFrame(frame), @@ -1358,47 +1356,13 @@ } -/*! - \brief Returns wether or not the window is visible on the specified - workspace. - - A modal or floating window may be visible on a workscreen if one - of its subset windows is visible there. +/*! Returns wether or not a window is in the workspace list with the + specified \a index. */ bool WindowLayer::InWorkspace(int32 index) const { - if (IsNormal()) - return (fWorkspaces & (1UL << index)) != 0; - - if (fFeel == B_MODAL_ALL_WINDOW_FEEL - || fFeel == B_FLOATING_ALL_WINDOW_FEEL) - return true; - - if (fFeel == B_FLOATING_APP_WINDOW_FEEL) - return ServerWindow()->App()->InWorkspace(index); - - if (fFeel == B_MODAL_APP_WINDOW_FEEL) { - uint32 workspaces = ServerWindow()->App()->Workspaces(); - if (workspaces == 0) { - // The application doesn't seem to have any other windows - // open or visible - but we'd like to see modal windows - // anyway, at least when they are first opened. - return index == fDesktop->CurrentWorkspace(); - } - return (workspaces & (1UL << index)) != 0; - } - - if (fFeel == B_MODAL_SUBSET_WINDOW_FEEL - || fFeel == B_FLOATING_SUBSET_WINDOW_FEEL) { - for (int32 i = 0; i < fSubsets.CountItems(); i++) { - WindowLayer* window = fSubsets.ItemAt(i); - if (!window->IsHidden() && window->InWorkspace(index)) - return true; - } - } - - return false; + return (fWorkspaces & (1UL << index)) != 0; } @@ -1451,8 +1415,7 @@ } -/*! - \brief Returns the windows that's in behind of the backmost position +/*! \brief Returns the windows that's in behind of the backmost position this window can get. Returns NULL is this window can be the backmost window. */ @@ -1481,8 +1444,7 @@ } -/*! - \brief Returns the windows that's in front of the frontmost position +/*! \brief Returns the windows that's in front of the frontmost position this window can get. Returns NULL if this window can be the frontmost window. */ @@ -1552,6 +1514,7 @@ } if (fFeel == B_FLOATING_APP_WINDOW_FEEL + && window->Feel() != B_MODAL_APP_WINDOW_FEEL || fFeel == B_MODAL_APP_WINDOW_FEEL) return window->ServerWindow()->App() == ServerWindow()->App(); @@ -1559,34 +1522,12 @@ } -bool -WindowLayer::SameSubset(WindowLayer* window) -{ - // TODO: this is probably not needed at all, but it doesn't hurt to have it in svn - if (fFeel == B_MODAL_ALL_WINDOW_FEEL || window->Feel() == B_MODAL_ALL_WINDOW_FEEL) - return fFeel == window->Feel(); +/*! \brief Returns on which workspaces the window should be visible. - if (fFeel == B_MODAL_APP_WINDOW_FEEL || window->Feel() == B_MODAL_APP_WINDOW_FEEL) - return ServerWindow()->App() == window->ServerWindow()->App(); - - if (fFeel == B_MODAL_SUBSET_WINDOW_FEEL) { - // we basically need to check if the subsets have anything in common - for (int32 i = fSubsets.CountItems(); i-- > 0;) { - if (window->HasInSubset(fSubsets.ItemAt(i))) - return true; - } - } - if (window->Feel() == B_MODAL_SUBSET_WINDOW_FEEL) { - for (int32 i = window->fSubsets.CountItems(); i-- > 0;) { - if (HasInSubset(window->fSubsets.ItemAt(i))) - return true; - } - } - - return false; -} - - + A modal or floating window may be visible on a workscreen if one + of its subset windows is visible there. Floating windows also need + to have a subset as front window to be visible. +*/ uint32 WindowLayer::SubsetWorkspaces() const { @@ -1594,9 +1535,15 @@ || fFeel == B_FLOATING_ALL_WINDOW_FEEL) return B_ALL_WORKSPACES; - if (fFeel == B_FLOATING_APP_WINDOW_FEEL) - return ServerWindow()->App()->Workspaces(); + if (fFeel == B_FLOATING_APP_WINDOW_FEEL) { + WindowLayer* front = fDesktop->FrontWindow(); + if (front != NULL && front->IsNormal() + && front->ServerWindow()->App() == ServerWindow()->App()) + return ServerWindow()->App()->Workspaces(); + return 0; + } + if (fFeel == B_MODAL_APP_WINDOW_FEEL) { uint32 workspaces = ServerWindow()->App()->Workspaces(); if (workspaces == 0) { @@ -1611,13 +1558,19 @@ if (fFeel == B_MODAL_SUBSET_WINDOW_FEEL || fFeel == B_FLOATING_SUBSET_WINDOW_FEEL) { uint32 workspaces = 0; + bool hasNormalFront = false; for (int32 i = 0; i < fSubsets.CountItems(); i++) { WindowLayer* window = fSubsets.ItemAt(i); if (!window->IsHidden()) workspaces |= window->Workspaces(); + if (window == fDesktop->FrontWindow() && window->IsNormal()) + hasNormalFront = true; } + if (fFeel == B_FLOATING_SUBSET_WINDOW_FEEL && !hasNormalFront) + return 0; + return workspaces; } @@ -1717,7 +1670,7 @@ // _ShiftPartOfRegion void WindowLayer::_ShiftPartOfRegion(BRegion* region, BRegion* regionToShift, - int32 xOffset, int32 yOffset) + int32 xOffset, int32 yOffset) { BRegion* common = fRegionPool.GetRegion(*regionToShift); if (!common) @@ -1871,6 +1824,7 @@ fEffectiveDrawingRegionValid = false; } + void WindowLayer::BeginUpdate(BPrivate::PortLink& link) { @@ -2059,9 +2013,10 @@ ResizeBy(xDiff, yDiff, NULL); } + // #pragma mark - UpdateSession -// constructor + WindowLayer::UpdateSession::UpdateSession() : fDirtyRegion(), fInUse(false), @@ -2069,12 +2024,12 @@ { } -// destructor + WindowLayer::UpdateSession::~UpdateSession() { } -// Include + void WindowLayer::UpdateSession::Include(BRegion* additionalDirty) { @@ -2123,5 +2078,3 @@ return *this; } - - Modified: haiku/trunk/src/servers/app/WorkspacesLayer.cpp =================================================================== --- haiku/trunk/src/servers/app/WorkspacesLayer.cpp 2007-10-14 00:14:31 UTC (rev 22548) +++ haiku/trunk/src/servers/app/WorkspacesLayer.cpp 2007-10-14 11:03:57 UTC (rev 22549) @@ -476,7 +476,7 @@ workspaceFrame.InsetBy(1, 1); if (index != fSelectedWorkspace) { - if (!fSelectedWindow->InWorkspace(index) && fSelectedWindow->IsNormal()) { + if (fSelectedWindow->IsNormal() && !fSelectedWindow->InWorkspace(index)) { // move window to this new workspace uint32 newWorkspaces = fSelectedWindow->Workspaces() & ~(1UL << fSelectedWorkspace) | (1UL << index); From axeld at mail.berlios.de Sun Oct 14 13:23:41 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sun, 14 Oct 2007 13:23:41 +0200 Subject: [Haiku-commits] r22550 - haiku/trunk/src/kits/interface Message-ID: <200710141123.l9EBNfwL006183@sheep.berlios.de> Author: axeld Date: 2007-10-14 13:23:40 +0200 (Sun, 14 Oct 2007) New Revision: 22550 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22550&view=rev Modified: haiku/trunk/src/kits/interface/ListView.cpp Log: MakeEmpty() now also calls _FixupScrollBar() - this fixes bug #1558. Modified: haiku/trunk/src/kits/interface/ListView.cpp =================================================================== --- haiku/trunk/src/kits/interface/ListView.cpp 2007-10-14 11:03:57 UTC (rev 22549) +++ haiku/trunk/src/kits/interface/ListView.cpp 2007-10-14 11:23:40 UTC (rev 22550) @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2006, Haiku, Inc. + * Copyright (c) 2001-2007, Haiku, Inc. * Distributed under the terms of the MIT license. * * Authors: @@ -737,10 +737,16 @@ void BListView::MakeEmpty() { + if (fList.IsEmpty()) + return; + _DeselectAll(-1, -1); fList.MakeEmpty(); - Invalidate(); + if (Window()) { + _FixupScrollBar(); + Invalidate(); + } } // IsEmpty From axeld at mail.berlios.de Sun Oct 14 14:31:52 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sun, 14 Oct 2007 14:31:52 +0200 Subject: [Haiku-commits] r22551 - in haiku/trunk: headers/private/graphics/common src/add-ons/accelerants/intel_extreme Message-ID: <200710141231.l9ECVqgf013055@sheep.berlios.de> Author: axeld Date: 2007-10-14 14:31:51 +0200 (Sun, 14 Oct 2007) New Revision: 22551 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22551&view=rev Modified: haiku/trunk/headers/private/graphics/common/create_display_modes.h haiku/trunk/src/add-ons/accelerants/intel_extreme/accelerant.h haiku/trunk/src/add-ons/accelerants/intel_extreme/accelerant_protos.h haiku/trunk/src/add-ons/accelerants/intel_extreme/hooks.cpp haiku/trunk/src/add-ons/accelerants/intel_extreme/mode.cpp Log: * Now uses the new create_display_modes() function. * Now supports the new B_GET_EDID_INFO hook under Haiku. * Fixed build under BeOS. Modified: haiku/trunk/headers/private/graphics/common/create_display_modes.h =================================================================== --- haiku/trunk/headers/private/graphics/common/create_display_modes.h 2007-10-14 11:23:40 UTC (rev 22550) +++ haiku/trunk/headers/private/graphics/common/create_display_modes.h 2007-10-14 12:31:51 UTC (rev 22551) @@ -9,6 +9,7 @@ #include #include +#include typedef bool (*check_display_mode_hook)(display_mode *mode); Modified: haiku/trunk/src/add-ons/accelerants/intel_extreme/accelerant.h =================================================================== --- haiku/trunk/src/add-ons/accelerants/intel_extreme/accelerant.h 2007-10-14 11:23:40 UTC (rev 22550) +++ haiku/trunk/src/add-ons/accelerants/intel_extreme/accelerant.h 2007-10-14 12:31:51 UTC (rev 22551) @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku, Inc. All Rights Reserved. + * Copyright 2006-2007, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -11,6 +11,7 @@ #include "intel_extreme.h" +#include #include @@ -50,6 +51,9 @@ hardware_status *status; uint8 *cursor_memory; + edid1_info edid_info; + bool has_edid; + int device; uint8 head_mode; bool is_clone; Modified: haiku/trunk/src/add-ons/accelerants/intel_extreme/accelerant_protos.h =================================================================== --- haiku/trunk/src/add-ons/accelerants/intel_extreme/accelerant_protos.h 2007-10-14 11:23:40 UTC (rev 22550) +++ haiku/trunk/src/add-ons/accelerants/intel_extreme/accelerant_protos.h 2007-10-14 12:31:51 UTC (rev 22551) @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku, Inc. All Rights Reserved. + * Copyright 2006-2007, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -35,6 +35,7 @@ const display_mode *high); status_t intel_set_display_mode(display_mode *mode); status_t intel_get_display_mode(display_mode *currentMode); +status_t intel_get_edid_info(void* info, size_t size, uint32* _version); status_t intel_get_frame_buffer_config(frame_buffer_config *config); status_t intel_get_pixel_clock_limits(display_mode *mode, uint32 *low, uint32 *high); status_t intel_move_display(uint16 hDisplayStart, uint16 vDisplayStart); Modified: haiku/trunk/src/add-ons/accelerants/intel_extreme/hooks.cpp =================================================================== --- haiku/trunk/src/add-ons/accelerants/intel_extreme/hooks.cpp 2007-10-14 11:23:40 UTC (rev 22550) +++ haiku/trunk/src/add-ons/accelerants/intel_extreme/hooks.cpp 2007-10-14 12:31:51 UTC (rev 22551) @@ -42,6 +42,10 @@ return (void*)intel_set_display_mode; case B_GET_DISPLAY_MODE: return (void*)intel_get_display_mode; +#ifdef __HAIKU__ + case B_GET_EDID_INFO: + return (void*)intel_get_edid_info; +#endif case B_GET_FRAME_BUFFER_CONFIG: return (void*)intel_get_frame_buffer_config; case B_GET_PIXEL_CLOCK_LIMITS: Modified: haiku/trunk/src/add-ons/accelerants/intel_extreme/mode.cpp =================================================================== --- haiku/trunk/src/add-ons/accelerants/intel_extreme/mode.cpp 2007-10-14 11:23:40 UTC (rev 22550) +++ haiku/trunk/src/add-ons/accelerants/intel_extreme/mode.cpp 2007-10-14 12:31:51 UTC (rev 22551) @@ -3,7 +3,7 @@ * Distributed under the terms of the MIT License. * * Support for i915 chipset and up based on the X driver, - * Copyright 2006 Intel Corporation. + * Copyright 2006-2007 Intel Corporation. * * Authors: * Axel D?rfler, axeld at pinc-software.de @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -31,12 +32,6 @@ #endif -#define POSITIVE_SYNC \ - (B_POSITIVE_HSYNC | B_POSITIVE_VSYNC) -#define MODE_FLAGS \ - (B_8_BIT_DAC | B_HARDWARE_CURSOR | B_PARALLEL_ACCESS | B_DPMS | B_SUPPORTS_OVERLAYS) - - struct display_registers { uint32 pll; uint32 divisors; @@ -73,46 +68,7 @@ uint32 max_vco; }; -static const display_mode kBaseModeList[] = { - {{25175, 640, 656, 752, 800, 350, 387, 389, 449, B_POSITIVE_HSYNC}, B_CMAP8, 640, 350, 0, 0, MODE_FLAGS}, /* 640x350 - www.epanorama.net/documents/pc/vga_timing.html) */ - {{25175, 640, 656, 752, 800, 400, 412, 414, 449, B_POSITIVE_VSYNC}, B_CMAP8, 640, 400, 0, 0, MODE_FLAGS}, /* 640x400 - www.epanorama.net/documents/pc/vga_timing.html) */ - {{25175, 640, 656, 752, 800, 480, 490, 492, 525, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 60Hz_(640X480X8.Z1) */ - {{27500, 640, 672, 768, 864, 480, 488, 494, 530, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* 640X480X60Hz */ - {{30500, 640, 672, 768, 864, 480, 517, 523, 588, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* SVGA_640X480X60HzNI */ - {{31500, 640, 664, 704, 832, 480, 489, 492, 520, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 70-72Hz_(640X480X8.Z1) */ - {{31500, 640, 656, 720, 840, 480, 481, 484, 500, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 75Hz_(640X480X8.Z1) */ - {{36000, 640, 696, 752, 832, 480, 481, 484, 509, 0}, B_CMAP8, 640, 480, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 85Hz_(640X480X8.Z1) */ - {{38100, 800, 832, 960, 1088, 600, 602, 606, 620, 0}, B_CMAP8, 800, 600, 0, 0, MODE_FLAGS}, /* SVGA_800X600X56HzNI */ - {{40000, 800, 840, 968, 1056, 600, 601, 605, 628, POSITIVE_SYNC}, B_CMAP8, 800, 600, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 60Hz_(800X600X8.Z1) */ - {{49500, 800, 816, 896, 1056, 600, 601, 604, 625, POSITIVE_SYNC}, B_CMAP8, 800, 600, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 75Hz_(800X600X8.Z1) */ - {{50000, 800, 856, 976, 1040, 600, 637, 643, 666, POSITIVE_SYNC}, B_CMAP8, 800, 600, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 70-72Hz_(800X600X8.Z1) */ - {{56250, 800, 832, 896, 1048, 600, 601, 604, 631, POSITIVE_SYNC}, B_CMAP8, 800, 600, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 85Hz_(800X600X8.Z1) */ - {{65000, 1024, 1048, 1184, 1344, 768, 771, 777, 806, 0}, B_CMAP8, 1024, 768, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 60Hz_(1024X768X8.Z1) */ - {{75000, 1024, 1048, 1184, 1328, 768, 771, 777, 806, 0}, B_CMAP8, 1024, 768, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 70-72Hz_(1024X768X8.Z1) */ - {{78750, 1024, 1040, 1136, 1312, 768, 769, 772, 800, POSITIVE_SYNC}, B_CMAP8, 1024, 768, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 75Hz_(1024X768X8.Z1) */ - {{94500, 1024, 1072, 1168, 1376, 768, 769, 772, 808, POSITIVE_SYNC}, B_CMAP8, 1024, 768, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 85Hz_(1024X768X8.Z1) */ - {{94200, 1152, 1184, 1280, 1472, 864, 865, 868, 914, POSITIVE_SYNC}, B_CMAP8, 1152, 864, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 70Hz_(1152X864X8.Z1) */ - {{108000, 1152, 1216, 1344, 1600, 864, 865, 868, 900, POSITIVE_SYNC}, B_CMAP8, 1152, 864, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 75Hz_(1152X864X8.Z1) */ - {{121500, 1152, 1216, 1344, 1568, 864, 865, 868, 911, POSITIVE_SYNC}, B_CMAP8, 1152, 864, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 85Hz_(1152X864X8.Z1) */ - {{108000, 1280, 1328, 1440, 1688, 1024, 1025, 1028, 1066, POSITIVE_SYNC}, B_CMAP8, 1280, 1024, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 60Hz_(1280X1024X8.Z1) */ - {{135000, 1280, 1296, 1440, 1688, 1024, 1025, 1028, 1066, POSITIVE_SYNC}, B_CMAP8, 1280, 1024, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 75Hz_(1280X1024X8.Z1) */ - {{157500, 1280, 1344, 1504, 1728, 1024, 1025, 1028, 1072, POSITIVE_SYNC}, B_CMAP8, 1280, 1024, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 85Hz_(1280X1024X8.Z1) */ - {{106500, 1440, 1520, 1672, 1904, 900, 901, 904, 932, POSITIVE_SYNC}, B_CMAP8, 1440, 900, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 60Hz_(1440X900) */ - - {{162000, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 60Hz_(1600X1200X8.Z1) */ - {{175500, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 65Hz_(1600X1200X8.Z1) */ - {{189000, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 70Hz_(1600X1200X8.Z1) */ - {{202500, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 75Hz_(1600X1200X8.Z1) */ - {{216000, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 80Hz_(1600X1200X8.Z1) */ - {{229500, 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, POSITIVE_SYNC}, B_CMAP8, 1600, 1200, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 85Hz_(1600X1200X8.Z1) */ - - {{147100, 1680, 1784, 1968, 2256, 1050, 1051, 1054, 1087, POSITIVE_SYNC}, B_CMAP8, 1680, 1050, 0, 0, MODE_FLAGS}, /* Vesa_Monitor_ at 60Hz_(1680X1050) */ -}; -static const uint32 kNumBaseModes = sizeof(kBaseModeList) / sizeof(display_mode); -static const uint32 kMaxNumModes = kNumBaseModes * 4; - - static status_t get_i2c_signals(void* cookie, int* _clock, int* _data) { @@ -189,55 +145,37 @@ } -/*! - Creates the initial mode list of the primary accelerant. +/*! Creates the initial mode list of the primary accelerant. It's called from intel_init_accelerant(). */ status_t create_mode_list(void) { - color_space spaces[4] = {B_RGB32_LITTLE, B_RGB16_LITTLE, B_RGB15_LITTLE, B_CMAP8}; - size_t size = ROUND_TO_PAGE_SIZE(kMaxNumModes * sizeof(display_mode)); - display_mode *list; - - gInfo->mode_list_area = create_area("intel extreme modes", (void **)&list, B_ANY_ADDRESS, - size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); - if (gInfo->mode_list_area < B_OK) - return gInfo->mode_list_area; - - // for now, just copy all of the modes with different color spaces - - const display_mode *source = kBaseModeList; - uint32 count = 0; - - for (uint32 i = 0; i < kNumBaseModes; i++) { - for (uint32 j = 0; j < (sizeof(spaces) / sizeof(color_space)); j++) { - list[count] = *source; - list[count].space = spaces[j]; - - count++; - } - - source++; - } - - gInfo->mode_list = list; - gInfo->shared_info->mode_list_area = gInfo->mode_list_area; - gInfo->shared_info->mode_count = count; - - edid1_info edid; i2c_bus bus; bus.cookie = (void*)INTEL_I2C_IO_A; bus.set_signals = &set_i2c_signals; bus.get_signals = &get_i2c_signals; ddc2_init_timing(&bus); - if (ddc2_read_edid1(&bus, &edid, NULL, NULL) == B_OK) { - edid_dump(&edid); + if (ddc2_read_edid1(&bus, &gInfo->edid_info, NULL, NULL) == B_OK) { + edid_dump(&gInfo->edid_info); + gInfo->has_edid = true; } else { TRACE(("intel_extreme: getting EDID failed!\n")); } + display_mode *list; + uint32 count = 0; + gInfo->mode_list_area = create_display_modes("intel extreme modes", + gInfo->has_edid ? &gInfo->edid_info : NULL, NULL, 0, NULL, 0, NULL, + &list, &count); + if (gInfo->mode_list_area < B_OK) + return gInfo->mode_list_area; + + gInfo->mode_list = list; + gInfo->shared_info->mode_list_area = gInfo->mode_list_area; + gInfo->shared_info->mode_count = count; + return B_OK; } @@ -454,7 +392,6 @@ uint32 colorMode, bytesPerRow, bitsPerPixel; get_color_space_format(target, colorMode, bytesPerRow, bitsPerPixel); -debug_printf("new resolution: %ux%ux%lu\n", target.timing.h_display, target.timing.v_display, bitsPerPixel); #if 0 static bool first = true; if (first) { @@ -472,7 +409,6 @@ first = false; } #endif - //return B_ERROR; intel_shared_info &sharedInfo = *gInfo->shared_info; Autolock locker(sharedInfo.accelerant_lock); @@ -541,7 +477,6 @@ pll |= DISPLAY_PLL_POST1_DIVIDE_2; } - debug_printf("PLL is %#lx, write: %#lx\n", read32(INTEL_DISPLAY_A_PLL), pll); write32(INTEL_DISPLAY_A_PLL, pll); read32(INTEL_DISPLAY_A_PLL); spin(150); @@ -710,8 +645,24 @@ return B_OK; } +#ifdef __HAIKU__ status_t +intel_get_edid_info(void* info, size_t size, uint32* _version) +{ + if (!gInfo->has_edid) + return B_ERROR; + if (size < sizeof(struct edid1_info)) + return B_BUFFER_OVERFLOW; + + memcpy(info, &gInfo->edid_info, sizeof(struct edid1_info)); + *_version = EDID_VERSION_1; + return B_OK; +} + +#endif // __HAIKU__ + +status_t intel_get_frame_buffer_config(frame_buffer_config *config) { TRACE(("intel_get_frame_buffer_config()\n")); From korli at mail.berlios.de Sun Oct 14 15:10:37 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Sun, 14 Oct 2007 15:10:37 +0200 Subject: [Haiku-commits] r22552 - haiku/trunk/build/jam Message-ID: <200710141310.l9EDAbF8015724@sheep.berlios.de> Author: korli Date: 2007-10-14 15:10:37 +0200 (Sun, 14 Oct 2007) New Revision: 22552 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22552&view=rev Modified: haiku/trunk/build/jam/HaikuImage Log: removed pcmcia-cs tools Modified: haiku/trunk/build/jam/HaikuImage =================================================================== --- haiku/trunk/build/jam/HaikuImage 2007-10-14 12:31:51 UTC (rev 22551) +++ haiku/trunk/build/jam/HaikuImage 2007-10-14 13:10:37 UTC (rev 22552) @@ -22,18 +22,18 @@ GPL_ONLY = "" ; } -BEOS_BIN = "[" addattr alert arp base64 basename bc beep bison bzip2 cat cardctl catattr +BEOS_BIN = "[" addattr alert arp base64 basename bc beep bison bzip2 cat catattr chgrp chmod chop chown cksum clear clockconfig cmp comm compress cp copyattr $(X86_ONLY)CortexAddOnHost csplit ctags cut date dc dd desklink df diff diff3 dircolors dirname - driveinfo dstcheck du dump_cis dump_cisreg echo eject env error expand expr + driveinfo dstcheck du echo eject env error expand expr expr factor false fdinfo ffm find finddir fmt fold fortune frcode ftp funzip fwcontrol gawk $(X86_ONLY)gdb grep groups gzip gzexe hd head hey hostname id ident ideinfo idestatus ifconfig install installsound iroster isvolume join keymap kill less lessecho lesskey link listarea listattr listdev listimage listport listres listsem ln locate logger login logname ls lsindex m4 make makebootable md5sum merge mimeset mkdos mkdir mkindex modifiers mount - mount_nfs mountvolume mv nc netstat nl nohup od open pack_cis paste patch pathchk pc + mount_nfs mountvolume mv nc netstat nl nohup od open paste patch pathchk pc ping play playfile playsound playwav pr prio printenv printf ps ptx pwd query quit readlink release renice rescan rlog rm rmattr rmindex rmdir roster route safemode screen_blanker sed setdecor settype setversion setvolume seq sh sha1sum shar From axeld at mail.berlios.de Sun Oct 14 15:52:43 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sun, 14 Oct 2007 15:52:43 +0200 Subject: [Haiku-commits] r22553 - in haiku/trunk: build/jam data/etc Message-ID: <200710141352.l9EDqgjH018395@sheep.berlios.de> Author: axeld Date: 2007-10-14 15:52:42 +0200 (Sun, 14 Oct 2007) New Revision: 22553 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22553&view=rev Added: haiku/trunk/data/etc/inputrc Modified: haiku/trunk/build/jam/HaikuImage Log: * Added PackageInstaller to the image. * Added an inputrc to the image that should have the same effect as the recent bash readline default changes for other apps that use readline. Modified: haiku/trunk/build/jam/HaikuImage =================================================================== --- haiku/trunk/build/jam/HaikuImage 2007-10-14 13:10:37 UTC (rev 22552) +++ haiku/trunk/build/jam/HaikuImage 2007-10-14 13:52:42 UTC (rev 22553) @@ -48,8 +48,8 @@ BEOS_APPS = AboutSystem CodyCam DeskCalc DiskProbe CDPlayer Expander Icon-O-Matic Installer LaunchBox Magnify Mail MediaPlayer MidiPlayer - NetworkStatus People PowerStatus ProcessController ShowImage SoundRecorder - StyledEdit Terminal TV Workspaces + NetworkStatus PackageInstaller People PowerStatus ProcessController + ShowImage SoundRecorder StyledEdit Terminal TV Workspaces ; BEOS_PREFERENCES = Appearance Backgrounds DataTranslations E-mail FileTypes Fonts Keyboard Keymap Media Menu Mouse Network Printers Screen ScreenSaver @@ -278,7 +278,7 @@ AddFilesToHaikuImage beos etc artwork : $(svgFiles) ; # TODO: Use data/etc/termcap or src/libs/termcap.src? -local etcFiles = profile termcap teapot.data ; +local etcFiles = inputrc profile termcap teapot.data ; etcFiles = $(etcFiles:G=etc) ; SEARCH on $(etcFiles) = [ FDirName $(HAIKU_TOP) data etc ] ; AddFilesToHaikuImage beos etc : $(etcFiles) ; Added: haiku/trunk/data/etc/inputrc =================================================================== --- haiku/trunk/data/etc/inputrc 2007-10-14 13:10:37 UTC (rev 22552) +++ haiku/trunk/data/etc/inputrc 2007-10-14 13:52:42 UTC (rev 22553) @@ -0,0 +1,7 @@ +# readline input configuration + +"\e[5~": history-search-backward +"\e[6~": history-search-forward +"\e[@": beginning-of-line +"\e[[": end-of-line +DEL: delete-char From julun at mail.berlios.de Sun Oct 14 15:53:54 2007 From: julun at mail.berlios.de (julun at BerliOS) Date: Sun, 14 Oct 2007 15:53:54 +0200 Subject: [Haiku-commits] r22554 - haiku/trunk/src/preferences/time Message-ID: <200710141353.l9EDrsjm018426@sheep.berlios.de> Author: julun Date: 2007-10-14 15:53:53 +0200 (Sun, 14 Oct 2007) New Revision: 22554 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22554&view=rev Added: haiku/trunk/src/preferences/time/DateTime.cpp haiku/trunk/src/preferences/time/DateTime.h Removed: haiku/trunk/src/preferences/time/DateUtils.cpp haiku/trunk/src/preferences/time/DateUtils.h Modified: haiku/trunk/src/preferences/time/AnalogClock.cpp haiku/trunk/src/preferences/time/AnalogClock.h haiku/trunk/src/preferences/time/BaseView.cpp haiku/trunk/src/preferences/time/BaseView.h haiku/trunk/src/preferences/time/Bitmaps.cpp haiku/trunk/src/preferences/time/Bitmaps.h haiku/trunk/src/preferences/time/CalendarView.cpp haiku/trunk/src/preferences/time/CalendarView.h haiku/trunk/src/preferences/time/DateTimeEdit.cpp haiku/trunk/src/preferences/time/DateTimeEdit.h haiku/trunk/src/preferences/time/Jamfile haiku/trunk/src/preferences/time/SectionEdit.cpp haiku/trunk/src/preferences/time/SectionEdit.h haiku/trunk/src/preferences/time/SettingsView.cpp haiku/trunk/src/preferences/time/SettingsView.h haiku/trunk/src/preferences/time/TZDisplay.cpp haiku/trunk/src/preferences/time/TZDisplay.h haiku/trunk/src/preferences/time/Time.cpp haiku/trunk/src/preferences/time/Time.h haiku/trunk/src/preferences/time/TimeMessages.h haiku/trunk/src/preferences/time/TimeSettings.cpp haiku/trunk/src/preferences/time/TimeSettings.h haiku/trunk/src/preferences/time/TimeWindow.cpp haiku/trunk/src/preferences/time/TimeWindow.h haiku/trunk/src/preferences/time/ZoneView.cpp haiku/trunk/src/preferences/time/ZoneView.h Log: * implemented Time, Date, DateTime classes to be used in CalendarView * implemented new Calendarview, capable to show/hide week numbers and day names weekstart sunday/monday and getting the current selected date etc... * updated mail addresses * make use of the new calendar view in time prefs * changed required classes to use the new date, time classes * gmt/ local time change implementation is missing atm, will come next Modified: haiku/trunk/src/preferences/time/AnalogClock.cpp =================================================================== --- haiku/trunk/src/preferences/time/AnalogClock.cpp 2007-10-14 13:52:42 UTC (rev 22553) +++ haiku/trunk/src/preferences/time/AnalogClock.cpp 2007-10-14 13:53:53 UTC (rev 22554) @@ -3,7 +3,7 @@ * Distributed under the terms of the MIT License. * * Authors: - * Mike Berg (inseculous) + * Mike Berg * Julun * Stephan A?mus */ Modified: haiku/trunk/src/preferences/time/AnalogClock.h =================================================================== --- haiku/trunk/src/preferences/time/AnalogClock.h 2007-10-14 13:52:42 UTC (rev 22553) +++ haiku/trunk/src/preferences/time/AnalogClock.h 2007-10-14 13:53:53 UTC (rev 22554) @@ -3,7 +3,7 @@ * Distributed under the terms of the MIT License. * * Authors: - * Mike Berg (inseculous) + * Mike Berg * Julun */ #ifndef ANALOG_CLOCK_H Modified: haiku/trunk/src/preferences/time/BaseView.cpp =================================================================== --- haiku/trunk/src/preferences/time/BaseView.cpp 2007-10-14 13:52:42 UTC (rev 22553) +++ haiku/trunk/src/preferences/time/BaseView.cpp 2007-10-14 13:53:53 UTC (rev 22554) @@ -3,21 +3,20 @@ * Distributed under the terms of the MIT License. * * Authors: - * Mike Berg (inseculous) + * Mike Berg * Julun */ #include "BaseView.h" +#include "DateTime.h" #include "TimeMessages.h" -#include #include TTimeBaseView::TTimeBaseView(BRect frame, const char *name) : BView(frame, name, B_FOLLOW_ALL_SIDES, B_PULSE_NEEDED), - fIsGMT(false), fMessage(H_TIME_UPDATE) { } @@ -32,7 +31,7 @@ TTimeBaseView::Pulse() { if (IsWatched()) - DispatchMessage(); + _SendNotices(); } @@ -44,78 +43,69 @@ void -TTimeBaseView::SetGMTime(bool gmt) -{ - fIsGMT = gmt; -} - - -void TTimeBaseView::ChangeTime(BMessage *message) { bool isTime; if (message->FindBool("time", &isTime) != B_OK) return; - time_t tmp = time(NULL); - struct tm *tm_struct = localtime(&tmp); - + BDateTime dateTime = BDateTime::CurrentDateTime(B_LOCAL_TIME); + if (isTime) { - int32 hour = 0; - if (message->FindInt32("hour", &hour) == B_OK) - tm_struct->tm_hour = hour; + BTime time = dateTime.Time(); + int32 hour; + if (message->FindInt32("hour", &hour) != B_OK) + hour = time.Hour(); - int32 minute = 0; - if (message->FindInt32("minute", &minute) == B_OK) - tm_struct->tm_min = minute; + int32 minute; + if (message->FindInt32("minute", &minute) != B_OK) + minute = time.Minute(); - int32 second = 0; - if (message->FindInt32("second", &second) == B_OK) - tm_struct->tm_sec = second; + int32 second; + if (message->FindInt32("second", &second) != B_OK) + second = time.Second(); - bool isAM = false; - if (message->FindBool("isam", &isAM) == B_OK) { - if (!isAM) - tm_struct->tm_hour += 12; - } + time.SetTime(hour, minute, second); + dateTime.SetTime(time); } else { - int32 month = 0; - if (message->FindInt32("month", &month) == B_OK) - tm_struct->tm_mon = month; + BDate date = dateTime.Date(); + int32 day; + if (message->FindInt32("day", &day) != B_OK) + day = date.Day(); - int32 day = 0; - if (message->FindInt32("day", &day) == B_OK) - tm_struct->tm_mday = day; + int32 year; + if (message->FindInt32("year", &year) != B_OK) + year = date.Year(); - int32 year = 0; - if (message->FindInt32("year", &year) == B_OK) - tm_struct->tm_year = year; + int32 month; + if (message->FindInt32("month", &month) != B_OK) + month = date.Month(); + + if (year >= 1970 && year <= 2037) { + date.SetDate(year, month, day); + dateTime.SetDate(date); + } } - - tmp = mktime(tm_struct); - set_real_time_clock(tmp); + + set_real_time_clock(dateTime.Time_t()); } void -TTimeBaseView::DispatchMessage() +TTimeBaseView::_SendNotices() { - time_t tmp = time(NULL); - struct tm *tm_struct = localtime(&tmp); - - if (fIsGMT) - tm_struct = gmtime(&tmp); - fMessage.MakeEmpty(); + + BDate date = BDate::CurrentDate(B_LOCAL_TIME); + fMessage.AddInt32("day", date.Day()); + fMessage.AddInt32("year", date.Year()); + fMessage.AddInt32("month", date.Month()); - fMessage.AddInt32("month", tm_struct->tm_mon); - fMessage.AddInt32("day", tm_struct->tm_mday); - fMessage.AddInt32("year", tm_struct->tm_year); + BTime time = BTime::CurrentTime(B_LOCAL_TIME); + fMessage.AddInt32("hour", time.Hour()); + fMessage.AddInt32("minute", time.Minute()); + fMessage.AddInt32("second", time.Second()); - fMessage.AddInt32("hour", tm_struct->tm_hour); - fMessage.AddInt32("minute", tm_struct->tm_min); - fMessage.AddInt32("second", tm_struct->tm_sec); - SendNotices(H_TM_CHANGED, &fMessage); } Modified: haiku/trunk/src/preferences/time/BaseView.h =================================================================== --- haiku/trunk/src/preferences/time/BaseView.h 2007-10-14 13:52:42 UTC (rev 22553) +++ haiku/trunk/src/preferences/time/BaseView.h 2007-10-14 13:53:53 UTC (rev 22554) @@ -3,15 +3,15 @@ * Distributed under the terms of the MIT License. * * Authors: - * Mike Berg (inseculous) + * Mike Berg * Julun */ #ifndef TIMEBASE_H #define TIMEBASE_H -#include #include +#include class TTimeBaseView: public BView { @@ -22,14 +22,12 @@ virtual void Pulse(); virtual void AttachedToWindow(); - void SetGMTime(bool gmtTime); void ChangeTime(BMessage *message); - protected: - virtual void DispatchMessage(); + private: + void _SendNotices(); private: - bool fIsGMT; BMessage fMessage; }; Modified: haiku/trunk/src/preferences/time/Bitmaps.cpp =================================================================== --- haiku/trunk/src/preferences/time/Bitmaps.cpp 2007-10-14 13:52:42 UTC (rev 22553) +++ haiku/trunk/src/preferences/time/Bitmaps.cpp 2007-10-14 13:53:53 UTC (rev 22554) @@ -3,9 +3,10 @@ * Distributed under the terms of the MIT License. * * Authors: - * probably Mike Berg - * and/or Andrew McCall + * Andrew McCall + * Mike Berg * Julun + * */ #include "Bitmaps.h" Modified: haiku/trunk/src/preferences/time/Bitmaps.h =================================================================== --- haiku/trunk/src/preferences/time/Bitmaps.h 2007-10-14 13:52:42 UTC (rev 22553) +++ haiku/trunk/src/preferences/time/Bitmaps.h 2007-10-14 13:53:53 UTC (rev 22554) @@ -3,9 +3,10 @@ * Distributed under the terms of the MIT License. * * Authors: - * probably Mike Berg - * and/or Andrew McCall + * Andrew McCall + * Mike Berg * Julun + * */ #ifndef ANALOG_CLOCK_H #define ANALOG_CLOCK_H Modified: haiku/trunk/src/preferences/time/CalendarView.cpp =================================================================== --- haiku/trunk/src/preferences/time/CalendarView.cpp 2007-10-14 13:52:42 UTC (rev 22553) +++ haiku/trunk/src/preferences/time/CalendarView.cpp 2007-10-14 13:53:53 UTC (rev 22554) @@ -1,466 +1,1234 @@ /* - * Copyright 2004-2007, Haiku. + * Copyright 2007, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: - * Michael Berg + * Julun */ -#include +#include "CalendarView.h" + + #include -#include "CalendarView.h" -#include "DateUtils.h" -#include "TimeMessages.h" -#include +#include -#define SEGMENT_CHANGE 'ostd' +namespace { + float + FontHeight(const BView *view) + { + if (!view) + return 0.0; + BFont font; + view->GetFont(&font); + font_height fheight; + font.GetHeight(&fheight); + return ceilf(fheight.ascent + fheight.descent + fheight.leading); + } +} -// ToDo: read these out of the locale -static const char kDays[7] = { 'S', 'M', 'T', 'W', 'T', 'F', 'S' }; +BCalendarView::BCalendarView(BRect frame, const char *name, + uint32 resizeMask, uint32 flags) + : BView(frame, name, resizeMask, flags), + BInvoker(), + fSelectionMessage(NULL), + fDay(0), + fYear(0), + fMonth(0), + fFocusChanged(false), + fSelectionChanged(false), + fWeekStart(B_WEEK_START_SUNDAY), + fDayNameHeaderVisible(true), + fWeekNumberHeaderVisible(true) +{ + _InitObject(); +} -static float -FontHeight(BView* target, bool full) + +BCalendarView::BCalendarView(BRect frame, const char *name, week_start start, + uint32 resizeMask, uint32 flags) + : BView(frame, name, resizeMask, flags), + BInvoker(), + fSelectionMessage(NULL), + fDay(0), + fYear(0), + fMonth(0), + fFocusChanged(false), + fSelectionChanged(false), + fWeekStart(start), + fDayNameHeaderVisible(true), + fWeekNumberHeaderVisible(true) { - font_height finfo; - target->GetFontHeight(&finfo); - float h = ceil(finfo.ascent) + ceil(finfo.descent); + _InitObject(); +} - if (full) - h += ceil(finfo.leading); - - return h; + +BCalendarView::~BCalendarView() +{ + SetSelectionMessage(NULL); } -// #pragma mark - +BCalendarView::BCalendarView(BMessage *archive) + : BView(archive), + BInvoker(), + fSelectionMessage(NULL), + fDay(0), + fYear(0), + fMonth(0), + fFocusChanged(false), + fSelectionChanged(false), + fWeekStart(B_WEEK_START_SUNDAY), + fDayNameHeaderVisible(true), + fWeekNumberHeaderVisible(true) +{ + if (archive->HasMessage("_invokeMsg")) { + BMessage *invokationMessage = new BMessage; + archive->FindMessage("_invokeMsg", invokationMessage); + SetInvocationMessage(invokationMessage); + } + if (archive->HasMessage("_selectMsg")) { + BMessage *selectionMessage = new BMessage; + archive->FindMessage("selectMsg", selectionMessage); + SetSelectionMessage(selectionMessage); + } -TDay::TDay(BRect frame, int day) - : BControl(frame, B_EMPTY_STRING, NULL, NULL, B_FOLLOW_NONE, B_WILL_DRAW) - , f_day(day) + if (archive->FindInt32("_day", &fDay) != B_OK + || archive->FindInt32("_month", &fMonth) != B_OK + || archive->FindInt32("_year", &fYear) != B_OK) { + BDate date = BDate::CurrentDate(B_LOCAL_TIME); + fDay = date.Day(); + fMonth = date.Month(); + fYear = date.Year(); + } + + int32 start; + if (archive->FindInt32("_weekStart", &start) == B_OK) + fWeekStart = week_start(start); + + if (archive->FindBool("_dayHeader", &fDayNameHeaderVisible) != B_OK) + fDayNameHeaderVisible = true; + + if (archive->FindBool("_weekHeader", &fWeekNumberHeaderVisible) != B_OK) + fWeekNumberHeaderVisible = true; + + _SetupDayNames(); + _SetupDayNumbers(); + _SetupWeekNumbers(); +} + + +BArchivable* +BCalendarView::Instantiate(BMessage *archive) { + if (validate_instantiation(archive, "BCalendarView")) + return new BCalendarView(archive); + + return NULL; } -TDay::~TDay() +status_t +BCalendarView::Archive(BMessage *archive, bool deep) const { + status_t status = BView::Archive(archive, deep); + + if (status == B_OK && InvocationMessage()) + status = archive->AddMessage("_invokeMsg", InvocationMessage()); + + if (status == B_OK && SelectionMessage()) + status = archive->AddMessage("_selectMsg", SelectionMessage()); + + if (status == B_OK) + status = archive->AddInt32("_day", fDay); + + if (status == B_OK) + status = archive->AddInt32("_month", fMonth); + + if (status == B_OK) + status = archive->AddInt32("_year", fYear); + + if (status == B_OK) + status = archive->AddInt32("_weekStart", int32(fWeekStart)); + + if (status == B_OK) + status = archive->AddBool("_dayHeader", fDayNameHeaderVisible); + + if (status == B_OK) + status = archive->AddBool("_weekHeader", fWeekNumberHeaderVisible); + + return status; } void -TDay::AttachedToWindow() +BCalendarView::AttachedToWindow() { - if (Parent()) - SetViewColor(Parent()->ViewColor()); + BView::AttachedToWindow(); + + if (!Messenger().IsValid()) + SetTarget(Window(), NULL); } void -TDay::MouseDown(BPoint where) +BCalendarView::DetachedFromWindow() { - if (f_day> 0) { - // only allow if not currently selected - if (Value() == B_CONTROL_ON) + BView::DetachedFromWindow(); +} + + +void +BCalendarView::AllAttached() +{ + BView::AllAttached(); +} + + +void +BCalendarView::AllDetached() +{ + BView::AllDetached(); +} + + +void +BCalendarView::FrameMoved(BPoint newPosition) +{ + BView::FrameMoved(newPosition); +} + + +void +BCalendarView::FrameResized(float width, float height) +{ + Invalidate(Bounds()); +} + + +void +BCalendarView::Draw(BRect updateRect) +{ + if (LockLooper()) { + if (fFocusChanged) { + _DrawFocusRect(); + UnlockLooper(); return; - - SetValue(B_CONTROL_ON); - Invoke(); + } - //update display - Draw(Bounds()); + if (fSelectionChanged) { + _UpdateSelection(); + UnlockLooper(); + return; + + } + + _DrawDays(); + _DrawDayHeader(); + _DrawWeekHeader(); + + rgb_color background = ui_color(B_PANEL_BACKGROUND_COLOR); + SetHighColor(tint_color(background, B_DARKEN_3_TINT)); + StrokeRect(Bounds()); + + UnlockLooper(); } } void -TDay::KeyDown(const char *bytes, int32 numbytes) +BCalendarView::DrawDay(BView *owner, BRect frame, const char *text, + bool isSelected, bool isEnabled, bool focus) { - BControl::KeyDown(bytes, numbytes); - Parent()->KeyDown(bytes, numbytes); + _DrawItem(owner, frame, text, isSelected, isEnabled, focus); } void -TDay::MakeFocus(bool focused) +BCalendarView::DrawDayName(BView *owner, BRect frame, const char *text) { - if (focused != IsFocus()) { - BView::MakeFocus(focused); - Draw(Bounds()); - Flush(); - } + // we get the full rect, fake this as the internal function + // shrinks the frame to work properly when drawing a day item + _DrawItem(owner, frame.InsetByCopy(-1.0, -1.0), text, true); } void -TDay::Stroke3dFrame(BRect frame, rgb_color light, rgb_color dark, bool inset) +BCalendarView::DrawWeekNumber(BView *owner, BRect frame, const char *text) { - rgb_color color1; - rgb_color color2; + // we get the full rect, fake this as the internal function + // shrinks the frame to work properly when drawing a day item + _DrawItem(owner, frame.InsetByCopy(-1.0, -1.0), text, true); +} + + +void +BCalendarView::MessageReceived(BMessage *message) +{ + BView::MessageReceived(message); +} + + +uint32 +BCalendarView::SelectionCommand() const +{ + if (SelectionMessage()) + return SelectionMessage()->what; + + return 0; +} + + +BMessage* +BCalendarView::SelectionMessage() const +{ + return fSelectionMessage; +} + + +void +BCalendarView::SetSelectionMessage(BMessage *message) +{ + delete fSelectionMessage; + fSelectionMessage = message; +} + + +uint32 +BCalendarView::InvocationCommand() const +{ + return BInvoker::Command(); +} + + +BMessage* +BCalendarView::InvocationMessage() const +{ + return BInvoker::Message(); +} + + +void +BCalendarView::SetInvocationMessage(BMessage *message) +{ + BInvoker::SetMessage(message); +} + + +void +BCalendarView::WindowActivated(bool state) +{ + BView::WindowActivated(state); +} + + +void +BCalendarView::MakeFocus(bool state) +{ + if (IsFocus() == state) + return; + + BView::MakeFocus(state); - if (inset) { - color1 = dark; - color2 = light; - } else { - color1 = light; - color2 = dark; - } - - BeginLineArray(4); - AddLine(frame.LeftTop(), frame.RightTop(), color1); - AddLine(frame.LeftTop(), frame.LeftBottom(), color1); - AddLine(frame.LeftBottom(), frame.RightBottom(), color2); - AddLine(frame.RightBottom(), frame.RightTop(), color2); - EndLineArray(); + fFocusChanged = true; + Draw(_RectOfDay(fFocusedDay)); + fFocusChanged = false; } +status_t +BCalendarView::Invoke(BMessage *message) +{ + bool notify = false; + uint32 kind = InvokeKind(¬ify); + + BMessage clone(kind); + status_t status = B_BAD_VALUE; + + if (!message && !notify) + message = Message(); + + if (!message) { + if (!IsWatched()) + return status; + } else + clone = *message; + + clone.AddPointer("source", this); + clone.AddInt64("when", (int64)system_time()); + clone.AddMessenger("be:sender", BMessenger(this)); + + int32 year; + int32 month; + _GetYearMonth(&year, &month); + + clone.AddInt32("year", year); + clone.AddInt32("month", month); + clone.AddInt32("day", fDay); + + if (message) + status = BInvoker::Invoke(&clone); + + SendNotices(kind, &clone); + + return status; +} + + void -TDay::Draw(BRect updaterect) +BCalendarView::MouseUp(BPoint point) { - BRect bounds(Bounds()); - - SetHighColor(ViewColor()); - FillRect(Bounds(), B_SOLID_HIGH); - - rgb_color bgcolor; - rgb_color dark; - rgb_color light; - - BString text; - - if (Value() == 1) { - bgcolor = tint_color(ViewColor(), B_DARKEN_2_TINT); - } else { - bgcolor = tint_color(ViewColor(), B_DARKEN_1_TINT); + BView::MouseUp(point); +} + + +void +BCalendarView::MouseDown(BPoint where) +{ + if (!IsFocus()) { + MakeFocus(); + Sync(); + Window()->UpdateIfNeeded(); } - text << f_day; - dark = tint_color(bgcolor, B_DARKEN_1_TINT); - light = tint_color(bgcolor, B_LIGHTEN_MAX_TINT); + BRect frame = Bounds(); + if (fDayNameHeaderVisible) + frame.top += frame.Height() / 7 - 1.0; + + if (fWeekNumberHeaderVisible) + frame.left += frame.Width() / 8 - 1.0; + + if (!frame.Contains(where)) + return; + + // try to set to new day + frame = _SetNewSelectedDay(where); - SetHighColor(bgcolor); - FillRect(bounds); + // on success + if (fSelectedDay != fNewSelectedDay) { + // update focus + fFocusChanged = true; + fNewFocusedDay = fNewSelectedDay; + Draw(_RectOfDay(fFocusedDay)); + fFocusChanged = false; - if (f_day > 0) { - if (!(Value() == 1)) - SetHighColor(0, 0, 0, 255); - else - SetHighColor(255, 255, 255, 255); - - SetLowColor(bgcolor); - - // calc font size; - float width = be_plain_font->StringWidth(text.String()); - font_height finfo; - be_plain_font->GetHeight(&finfo); - float height = finfo.descent +finfo.ascent +finfo.leading; + // update selection + fSelectionChanged = true; + Draw(frame); + Draw(_RectOfDay(fSelectedDay)); + fSelectionChanged = false; - BPoint drawpt((bounds.Width()/2.0) -(width/2.0) +1, (bounds.Height()/2.0) +(height/2.0) -2); - DrawString(text.String(), drawpt); + // notify that selection changed + InvokeNotify(SelectionMessage(), B_CONTROL_MODIFIED); } - - if (IsFocus()) { - rgb_color nav_color = keyboard_navigation_color(); - SetHighColor(nav_color); - StrokeRect(bounds); - - } else { - SetHighColor(bgcolor); - StrokeRect(bounds); - if (Value() == 1) - Stroke3dFrame(bounds, light, dark, true); - } + + int32 clicks; + // on double click invoke + BMessage *message = Looper()->CurrentMessage(); + if (message->FindInt32("clicks", &clicks) == B_OK && clicks > 1) + Invoke(); } void -TDay::SetValue(int32 value) +BCalendarView::MouseMoved(BPoint point, uint32 code, const BMessage *dragMessage) { - BControl::SetValue(value); - - if (Value() == 1) { - SetFlags(Flags() & ~B_NAVIGABLE); - } else { - SetFlags(Flags()|B_NAVIGABLE); + BView::MouseMoved(point, code, dragMessage); +} + + +void +BCalendarView::KeyDown(const char *bytes, int32 numBytes) +{ + const int32 kRows = 6; + const int32 kColumns = 7; + + int32 row = fFocusedDay.row; + int32 column = fFocusedDay.column; + + switch (bytes[0]) { + case B_LEFT_ARROW: + { + column -= 1; + if (column < 0) { + column = kColumns -1; + row -= 1; + if (row >= 0) + fFocusChanged = true; + } else + fFocusChanged = true; + } break; + + case B_RIGHT_ARROW: + { + column += 1; + if (column == kColumns) { + column = 0; + row += 1; + if (row < kRows) + fFocusChanged = true; + } else + fFocusChanged = true; + } break; + + case B_UP_ARROW: + { + row -= 1; + if (row >= 0) + fFocusChanged = true; + } break; + + case B_DOWN_ARROW: + { + row += 1; + if (row < kRows) + fFocusChanged = true; + } break; + + case B_RETURN: + case B_SPACE: { + fSelectionChanged = true; + BPoint pt = _RectOfDay(fFocusedDay).LeftTop(); + Draw(_SetNewSelectedDay(pt + BPoint(4.0, 4.0))); + Draw(_RectOfDay(fSelectedDay)); + fSelectionChanged = false; + + Invoke(); + } break; + + default: + BView::KeyDown(bytes, numBytes); + break; } - Draw(Bounds()); + + if (fFocusChanged) { + fNewFocusedDay.SetTo(row, column); + Draw(_RectOfDay(fFocusedDay)); + Draw(_RectOfDay(fNewFocusedDay)); + fFocusChanged = false; + } } -void -TDay::SetTo(BRect frame, int day) +BHandler* +BCalendarView::ResolveSpecifier(BMessage *message, int32 index, + BMessage *specifier, int32 form, const char *property) { - MoveTo(frame.LeftTop()); - f_day = day; - Draw(Bounds()); + return BView::ResolveSpecifier(message, index, specifier, form, property); } +status_t +BCalendarView::GetSupportedSuites(BMessage *data) +{ + return BView::GetSupportedSuites(data); +} + + +status_t +BCalendarView::Perform(perform_code code, void *arg) +{ + return BView::Perform(code, arg); +} + + void -TDay::SetTo(int day, bool selected) +BCalendarView::ResizeToPreferred() { - f_day = day; - SetValue(selected); - if (Value() == 1) { - SetFlags(Flags() | B_NAVIGABLE); + float width; + float height; + + GetPreferredSize(&width, &height); + BView::ResizeTo(width, height); +} + + +void +BCalendarView::GetPreferredSize(float *width, float *height) +{ + _GetPreferredSize(width, height); +} + + +int32 +BCalendarView::Day() const +{ + return fDay; +} + + +int32 +BCalendarView::Year() const +{ + int32 year; + int32 month; + _GetYearMonth(&year, &month); + + return year; +} + + +int32 +BCalendarView::Month() const +{ + int32 year; + int32 month; + _GetYearMonth(&year, &month); + + return month; +} + + +BDate +BCalendarView::Date() const +{ + int32 year; + int32 month; + _GetYearMonth(&year, &month); + return BDate(year, month, fDay); +} + + +bool +BCalendarView::SetDate(const BDate &date) +{ + return SetDate(date.Year(), date.Month(), date.Day()); +} + + +bool +BCalendarView::SetDate(int32 year, int32 month, int32 day) [... truncated: 3227 lines follow ...] From sbenedetto at mail.berlios.de Sun Oct 14 17:05:15 2007 From: sbenedetto at mail.berlios.de (sbenedetto at BerliOS) Date: Sun, 14 Oct 2007 17:05:15 +0200 Subject: [Haiku-commits] r22555 - haiku/trunk/src/add-ons/kernel/busses/usb Message-ID: <200710141505.l9EF5F0N024570@sheep.berlios.de> Author: sbenedetto Date: 2007-10-14 17:05:14 +0200 (Sun, 14 Oct 2007) New Revision: 22555 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22555&view=rev Modified: haiku/trunk/src/add-ons/kernel/busses/usb/ohci.cpp haiku/trunk/src/add-ons/kernel/busses/usb/ohci.h haiku/trunk/src/add-ons/kernel/busses/usb/ohci_hardware.h haiku/trunk/src/add-ons/kernel/busses/usb/ohci_rh.cpp Log: * License changed: I've successfully contacted Jan-Rixt Van Hoye, and he gave me his bless :) * Usual clean up Modified: haiku/trunk/src/add-ons/kernel/busses/usb/ohci.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/usb/ohci.cpp 2007-10-14 13:53:53 UTC (rev 22554) +++ haiku/trunk/src/add-ons/kernel/busses/usb/ohci.cpp 2007-10-14 15:05:14 UTC (rev 22555) @@ -1,27 +1,11 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2005, Jan-Rixt Van Hoye -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// ------------------------------------------------------------------------ -// Authors: -// Salvatore Benedetto +/* + * Copyright 2005-2008, Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Jan-Rixt Van Hoye + * Salvatore Benedetto + */ #include #include @@ -32,128 +16,27 @@ #include "ohci.h" pci_module_info *OHCI::sPCIModule = NULL; + -//------------------------------------------------------ -// OHCI:: Reverse the bits in a value between 0 and 31 -// (Section 3.3.2) -//------------------------------------------------------ -static uint8 revbits[OHCI_NUMBER_OF_INTERRUPTS] = - { 0x00, 0x10, 0x08, 0x18, 0x04, 0x14, 0x0c, 0x1c, - 0x02, 0x12, 0x0a, 0x1a, 0x06, 0x16, 0x0e, 0x1e, - 0x01, 0x11, 0x09, 0x19, 0x05, 0x15, 0x0d, 0x1d, - 0x03, 0x13, 0x0b, 0x1b, 0x07, 0x17, 0x0f, 0x1f }; - - static int32 ohci_std_ops( int32 op , ... ) { - switch (op) - { + switch (op) { case B_MODULE_INIT: TRACE(("usb_ohci_module: init module\n")); return B_OK; case B_MODULE_UNINIT: TRACE(("usb_ohci_module: uninit module\n")); - break; - default: - return EINVAL; + return B_OK; } - return B_OK; -} - -//------------------------------------------------------------------------ -// OHCI:: Give an reference of a stack instance to the OHCI module -// -// parameters: -// - &stack: reference to a stack instance form stack.cpp -//------------------------------------------------------------------------ - -status_t -OHCI::AddTo(Stack *stack) -{ -#ifdef TRACE_USB - set_dprintf_enabled(true); - load_driver_symbols("ohci"); -#endif - - if (!sPCIModule) { - status_t status = get_module(B_PCI_MODULE_NAME, (module_info **)&sPCIModule); - if (status < B_OK) { - TRACE_ERROR(("usb_ohci: AddTo(): getting pci module failed! 0x%08lx\n", - status)); - return status; - } - } - - TRACE(("usb_ohci: AddTo(): setting up hardware\n")); - - bool found = false; - pci_info *item = new(std::nothrow) pci_info; - if (!item) { - sPCIModule = NULL; - put_module(B_PCI_MODULE_NAME); - return B_NO_MEMORY; - } - - for (uint32 i = 0 ; sPCIModule->get_nth_pci_info(i, item) >= B_OK; i++) { - - if (item->class_base == PCI_serial_bus && item->class_sub == PCI_usb - && item->class_api == PCI_usb_ohci) { - if (item->u.h0.interrupt_line == 0 - || item->u.h0.interrupt_line == 0xFF) { - TRACE_ERROR(("usb_ohci: AddTo(): found with invalid IRQ -" - " check IRQ assignement\n")); - continue; - } - - TRACE(("usb_ohci: AddTo(): found at IRQ %u\n", - item->u.h0.interrupt_line)); - OHCI *bus = new(std::nothrow) OHCI(item, stack); - if (!bus) { - delete item; - sPCIModule = NULL; - put_module(B_PCI_MODULE_NAME); - return B_NO_MEMORY; - } - - if (bus->InitCheck() < B_OK) { - TRACE_ERROR(("usb_ohci: AddTo(): InitCheck() failed 0x%08lx\n", - bus->InitCheck())); - delete bus; - continue; - } - - // the bus took it away - item = new(std::nothrow) pci_info; - - bus->Start(); - stack->AddBusManager(bus); - found = true; - } - } - - if (!found) { - TRACE_ERROR(("usb_ohci: no devices found\n")); - delete item; - put_module(B_PCI_MODULE_NAME); - return ENODEV; - } - - delete item; - return B_OK; + return EINVAL; } -//------------------------------------------------------------------------ -// OHCI:: Host controller information -// -// parameters: none -//------------------------------------------------------------------------ - host_controller_info ohci_module = { { - "busses/usb/ohci", + "busses/usb/ohci", 0, ohci_std_ops }, @@ -161,27 +44,28 @@ OHCI::AddTo }; -//------------------------------------------------------------------------ -// OHCI:: Module information -// -// parameters: none -//------------------------------------------------------------------------ -module_info *modules[] = { +module_info *modules[] = { (module_info *) &ohci_module, - NULL + NULL }; -//------------------------------------------------------------------------ -// OHCI:: Constructor/Initialisation -// -// parameters: -// - info: pointer to a pci information structure -// - stack: pointer to a stack instance -//------------------------------------------------------------------------ +//------------------------------------------------------ +// OHCI:: Reverse the bits in a value between 0 and 31 +// (Section 3.3.2) +//------------------------------------------------------ +static uint8 revbits[OHCI_NUMBER_OF_INTERRUPTS] = + { 0x00, 0x10, 0x08, 0x18, 0x04, 0x14, 0x0c, 0x1c, + 0x02, 0x12, 0x0a, 0x1a, 0x06, 0x16, 0x0e, 0x1e, + 0x01, 0x11, 0x09, 0x19, 0x05, 0x15, 0x0d, 0x1d, + 0x03, 0x13, 0x0b, 0x1b, 0x07, 0x17, 0x0f, 0x1f }; + + OHCI::OHCI(pci_info *info, Stack *stack) : BusManager(stack), + fPCIInfo(info), + fStack(stack), fRegisterArea(-1), fHccaArea(-1), fDummyControl(0), @@ -191,14 +75,13 @@ fRootHubAddress(0), fNumPorts(0) { - fPCIInfo = info; - fStack = stack; int i; TRACE(("usb_ohci: constructing new BusManager\n")); fInitOK = false; - for(i = 0; i < OHCI_NO_EDS; i++) //Clear the interrupt list + fInterruptEndpoints = new(std::nothrow) uint32[OHCI_NUMBER_OF_INTERRUPTS]; + for(i = 0; i < OHCI_NUMBER_OF_INTERRUPTS; i++) //Clear the interrupt list fInterruptEndpoints[i] = 0; // enable busmaster and memory mapped access @@ -338,6 +221,7 @@ fInitOK = true; } + OHCI::~OHCI() { if (fHccaArea > 0) @@ -357,6 +241,7 @@ FreeEndpoint(fInterruptEndpoints[i]); } + status_t OHCI::Start() { @@ -388,7 +273,9 @@ return B_OK; } -status_t OHCI::SubmitTransfer( Transfer *t ) + +status_t +OHCI::SubmitTransfer(Transfer *t) { TRACE(("usb OHCI::SubmitTransfer: called for device %d\n", t->TransferPipe()->DeviceAddress())); @@ -398,6 +285,7 @@ return B_ERROR; } + status_t OHCI::NotifyPipeChange(Pipe *pipe, usb_change change) { @@ -418,11 +306,88 @@ return B_ERROR; //We should never go here } + status_t +OHCI::AddTo(Stack *stack) +{ +#ifdef TRACE_USB + set_dprintf_enabled(true); + load_driver_symbols("ohci"); +#endif + + if (!sPCIModule) { + status_t status = get_module(B_PCI_MODULE_NAME, (module_info **)&sPCIModule); + if (status < B_OK) { + TRACE_ERROR(("usb_ohci: AddTo(): getting pci module failed! 0x%08lx\n", + status)); + return status; + } + } + + TRACE(("usb_ohci: AddTo(): setting up hardware\n")); + + bool found = false; + pci_info *item = new(std::nothrow) pci_info; + if (!item) { + sPCIModule = NULL; + put_module(B_PCI_MODULE_NAME); + return B_NO_MEMORY; + } + + for (uint32 i = 0 ; sPCIModule->get_nth_pci_info(i, item) >= B_OK; i++) { + + if (item->class_base == PCI_serial_bus && item->class_sub == PCI_usb + && item->class_api == PCI_usb_ohci) { + if (item->u.h0.interrupt_line == 0 + || item->u.h0.interrupt_line == 0xFF) { + TRACE_ERROR(("usb_ohci: AddTo(): found with invalid IRQ -" + " check IRQ assignement\n")); + continue; + } + + TRACE(("usb_ohci: AddTo(): found at IRQ %u\n", + item->u.h0.interrupt_line)); + OHCI *bus = new(std::nothrow) OHCI(item, stack); + if (!bus) { + delete item; + sPCIModule = NULL; + put_module(B_PCI_MODULE_NAME); + return B_NO_MEMORY; + } + + if (bus->InitCheck() < B_OK) { + TRACE_ERROR(("usb_ohci: AddTo(): InitCheck() failed 0x%08lx\n", + bus->InitCheck())); + delete bus; + continue; + } + + // the bus took it away + item = new(std::nothrow) pci_info; + + bus->Start(); + stack->AddBusManager(bus); + found = true; + } + } + + if (!found) { + TRACE_ERROR(("usb_ohci: no devices found\n")); + delete item; + put_module(B_PCI_MODULE_NAME); + return ENODEV; + } + + delete item; + return B_OK; +} + + +status_t OHCI::GetPortStatus(uint8 index, usb_port_status *status) { TRACE(("OHCI::%s(%ud, )\n", __FUNCTION__, index)); - if (index > fNumPorts) + if (index >= fNumPorts) return B_BAD_INDEX; status->status = status->change = 0; @@ -462,6 +427,7 @@ return B_OK; } + status_t OHCI::SetPortFeature(uint8 index, uint16 feature) { @@ -482,6 +448,7 @@ return B_BAD_VALUE; } + status_t OHCI::ClearPortFeature(uint8 index, uint16 feature) { @@ -502,6 +469,7 @@ return B_BAD_VALUE; } + Endpoint * OHCI::AllocateEndpoint() { @@ -527,6 +495,7 @@ return endpoint; } + void OHCI::FreeEndpoint(Endpoint *end) { @@ -535,6 +504,7 @@ delete end; } + TransferDescriptor * OHCI::AllocateTransfer() { @@ -549,7 +519,8 @@ memset((void *)transfer->td, 0, sizeof(ohci_general_transfer_descriptor)); return transfer; } - + + void OHCI::FreeTransfer(TransferDescriptor *trans) { @@ -558,6 +529,7 @@ delete trans; } + status_t OHCI::InsertEndpointForPipe(Pipe *p) { @@ -650,7 +622,6 @@ return B_OK; } -pci_module_info *sPCIModule = 0; void OHCI::WriteReg(uint32 reg, uint32 value) @@ -659,6 +630,7 @@ *(volatile uint32 *)(fRegisterBase + reg) = value; } + uint32 OHCI::ReadReg(uint32 reg) { @@ -666,9 +638,9 @@ return *(volatile uint32 *)(fRegisterBase + reg); } + status_t OHCI::CancelQueuedTransfers(Pipe *pipe) { return B_ERROR; } - Modified: haiku/trunk/src/add-ons/kernel/busses/usb/ohci.h =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/usb/ohci.h 2007-10-14 13:53:53 UTC (rev 22554) +++ haiku/trunk/src/add-ons/kernel/busses/usb/ohci.h 2007-10-14 15:05:14 UTC (rev 22555) @@ -1,28 +1,12 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2005, Jan-Rixt Van Hoye -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -//------------------------------------------------------------------------------- -// Authors: -// Salvatore Benedetto +/* + * Copyright 2005-2008, Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Jan-Rixt Van Hoye + * Salvatore Benedetto + */ - #ifndef OHCI_H #define OHCI_H @@ -63,14 +47,40 @@ #define OHCI_NO_EDS (2 * OHCI_NUMBER_OF_INTERRUPTS - 1) -// -------------------------------- -// OHCI: The OHCI class derived -// from the BusManager -// -------------------------------- +// +// Endpoint: wrapper around the hardware endpoints +// +struct Endpoint +{ + addr_t physicaladdress;//Point to the physical address + ohci_endpoint_descriptor *ed; //Logical 'endpoint' + Endpoint *next; //Pointer to the 'next' endpoint + TransferDescriptor *head, *tail; //Pointers to the 'head' and 'tail' transfer descriptors + + //Utility functions + void SetNext(Endpoint *end) { + next = end; + if (end == 0) + ed->next_endpoint = 0; + else + ed->next_endpoint = end->physicaladdress; + }; + + //Constructor (or better: initialiser) + Endpoint() : physicaladdress(0), ed(0), next(0), head(0), tail(0) {}; +}; + + +struct TransferDescriptor +{ + addr_t physicaladdress; + ohci_general_transfer_descriptor *td; +}; + + class OHCI : public BusManager { - friend class OHCIRootHub; public: OHCI(pci_info *info, Stack *stack); @@ -97,7 +107,7 @@ inline void WriteReg(uint32 reg, uint32 value); inline uint32 ReadReg(uint32 reg); - // Global + // Global static pci_module_info *sPCIModule; uint32 *fRegisterBase; @@ -106,21 +116,21 @@ area_id fRegisterArea; - // HCCA - area_id fHccaArea; - struct ohci_hcca *fHcca; // The HCCA structure for the interupt communication - Endpoint *fInterruptEndpoints[OHCI_NO_EDS]; // The interrupt endpoint list - // Dummy endpoints - Endpoint *fDummyControl; - Endpoint *fDummyBulk; - Endpoint *fDummyIsochronous; - // functions - Endpoint *AllocateEndpoint(); // allocate memory for an endpoint - void FreeEndpoint(Endpoint *end); // Free endpoint - TransferDescriptor *AllocateTransfer(); // create a NULL transfer - void FreeTransfer(TransferDescriptor *trans); // Free transfer + // HCCA + area_id fHccaArea; + struct ohci_hcca *fHcca; + Endpoint *fInterruptEndpoints[OHCI_NO_EDS]; + // Dummy endpoints + Endpoint *fDummyControl; + Endpoint *fDummyBulk; + Endpoint *fDummyIsochronous; + // functions + Endpoint *AllocateEndpoint(); + void FreeEndpoint(Endpoint *end); + TransferDescriptor *AllocateTransfer(); + void FreeTransfer(TransferDescriptor *trans); - status_t InsertEndpointForPipe(Pipe *p); + status_t InsertEndpointForPipe(Pipe *p); // Root Hub OHCIRootHub *fRootHub; @@ -128,47 +138,15 @@ uint8 fNumPorts; }; -// -------------------------------- -// OHCI: The root hub of the OHCI -// controller derived from -// the Hub class -// -------------------------------- -class OHCIRootHub : public Hub -{ - public: - OHCIRootHub(OHCI *ohci, int8 deviceAddress); - status_t ProcessTransfer(Transfer *t, OHCI *ohci); -}; +class OHCIRootHub : public Hub { +public: + OHCIRootHub(Object *rootObject, + int8 deviceAddress); -// -// Endpoint: wrapper around the hardware endpoints -// - -struct Endpoint -{ - addr_t physicaladdress;//Point to the physical address - ohci_endpoint_descriptor *ed; //Logical 'endpoint' - Endpoint *next; //Pointer to the 'next' endpoint - TransferDescriptor *head, *tail; //Pointers to the 'head' and 'tail' transfer descriptors - - //Utility functions - void SetNext(Endpoint *end) { - next = end; - if (end == 0) - ed->next_endpoint = 0; - else - ed->next_endpoint = end->physicaladdress; - }; - - //Constructor (or better: initialiser) - Endpoint() : physicaladdress(0), ed(0), next(0), head(0), tail(0) {}; +static status_t ProcessTransfer(OHCI *ohci, + Transfer *transfer); }; -struct TransferDescriptor -{ - addr_t physicaladdress; - ohci_general_transfer_descriptor *td; -}; #endif // OHCI_H Modified: haiku/trunk/src/add-ons/kernel/busses/usb/ohci_hardware.h =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/usb/ohci_hardware.h 2007-10-14 13:53:53 UTC (rev 22554) +++ haiku/trunk/src/add-ons/kernel/busses/usb/ohci_hardware.h 2007-10-14 15:05:14 UTC (rev 22555) @@ -1,29 +1,12 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2005, Jan-Rixt Van Hoye -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// ---------------------------------------------------------------------------- -// Authors: -// Salvatore Benedetto +/* + * Copyright 2005-2008, Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Jan-Rixt Van Hoye + * Salvatore Benedetto + */ - #ifndef OHCI_HARD_H #define OHCI_HARD_H Modified: haiku/trunk/src/add-ons/kernel/busses/usb/ohci_rh.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/usb/ohci_rh.cpp 2007-10-14 13:53:53 UTC (rev 22554) +++ haiku/trunk/src/add-ons/kernel/busses/usb/ohci_rh.cpp 2007-10-14 15:05:14 UTC (rev 22555) @@ -1,26 +1,12 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2005, Jan-Rixt Van Hoye -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -//------------------------------------------------------------------------------ +/* + * Copyright 2005-2008, Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Jan-Rixt Van Hoye + * Salvatore Benedetto + */ - #include "ohci.h" static usb_device_descriptor sOHCIRootHubDevice = From axeld at mail.berlios.de Sun Oct 14 19:27:44 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sun, 14 Oct 2007 19:27:44 +0200 Subject: [Haiku-commits] r22557 - in haiku/trunk: headers/private/kernel src/system/kernel src/system/kernel/arch/x86 Message-ID: <200710141727.l9EHRivJ015426@sheep.berlios.de> Author: axeld Date: 2007-10-14 19:27:44 +0200 (Sun, 14 Oct 2007) New Revision: 22557 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22557&view=rev Modified: haiku/trunk/headers/private/kernel/real_time_clock.h haiku/trunk/src/system/kernel/arch/x86/arch_real_time_clock.c haiku/trunk/src/system/kernel/real_time_clock.c Log: Applied patch by Julun: time computations based on an algorithm by Fliegel, and van Flandern (1968), instead of those inefficient loops we had before. Thanks! Modified: haiku/trunk/headers/private/kernel/real_time_clock.h =================================================================== --- haiku/trunk/headers/private/kernel/real_time_clock.h 2007-10-14 16:55:32 UTC (rev 22556) +++ haiku/trunk/headers/private/kernel/real_time_clock.h 2007-10-14 17:27:44 UTC (rev 22557) @@ -1,5 +1,5 @@ /* - * Copyright 2006, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Copyright 2006-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. * Copyright 2003, Jeff Ward, jeff at r2d2.stcloudstate.edu. All rights reserved. * * Distributed under the terms of the MIT License. @@ -13,7 +13,7 @@ #include -#define RTC_EPOCHE_BASE_YEAR 1970 +#define RTC_EPOCH_BASE_YEAR 1970 typedef struct rtc_info { uint32 time; Modified: haiku/trunk/src/system/kernel/arch/x86/arch_real_time_clock.c =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/arch_real_time_clock.c 2007-10-14 16:55:32 UTC (rev 22556) +++ haiku/trunk/src/system/kernel/arch/x86/arch_real_time_clock.c 2007-10-14 17:27:44 UTC (rev 22557) @@ -1,5 +1,5 @@ /* - * Copyright 2005, Axel D?rfler, axeld at pinc-software.de + * Copyright 2005-2007, Axel D?rfler, axeld at pinc-software.de * Copyright 2003, Jeff Ward, jeff at r2d2.stcloudstate.edu. All rights reserved. * * Distributed under the terms of the MIT License. @@ -141,7 +141,7 @@ { struct tm t; t.tm_year = bcd_to_int(cmos->century) * 100 + bcd_to_int(cmos->year) - - RTC_EPOCHE_BASE_YEAR; + - RTC_EPOCH_BASE_YEAR; t.tm_mon = bcd_to_int(cmos->month) - 1; t.tm_mday = bcd_to_int(cmos->day); t.tm_hour = bcd_to_int(cmos->hour); @@ -160,7 +160,7 @@ struct tm t; rtc_secs_to_tm(seconds, &t); - wholeYear = t.tm_year + RTC_EPOCHE_BASE_YEAR; + wholeYear = t.tm_year + RTC_EPOCH_BASE_YEAR; cmos->century = int_to_bcd(wholeYear / 100); cmos->year = int_to_bcd(wholeYear % 100); Modified: haiku/trunk/src/system/kernel/real_time_clock.c =================================================================== --- haiku/trunk/src/system/kernel/real_time_clock.c 2007-10-14 16:55:32 UTC (rev 22556) +++ haiku/trunk/src/system/kernel/real_time_clock.c 2007-10-14 17:27:44 UTC (rev 22557) @@ -23,6 +23,10 @@ #endif +#define RTC_SECONDS_DAY 86400 +#define RTC_EPOCH_JULIAN_DAY 2440588 + // January 1st, 1970 + static struct real_time_data *sRealTimeData; static bool sIsGMT = false; static char sTimezoneFilename[B_PATH_NAME_LENGTH] = ""; @@ -161,130 +165,58 @@ // #pragma mark - -#define SECONDS_31 2678400 -#define SECONDS_30 2592000 -#define SECONDS_28 2419200 -#define SECONDS_DAY 86400 - -static uint32 sSecsPerMonth[12] = {SECONDS_31, SECONDS_28, SECONDS_31, SECONDS_30, - SECONDS_31, SECONDS_30, SECONDS_31, SECONDS_31, SECONDS_30, SECONDS_31, SECONDS_30, - SECONDS_31}; - - -static bool -leap_year(uint32 year) -{ - if (year % 400 == 0) - return true; - - if (year % 100 == 0) - return false; - - if (year % 4 == 0) - return true; - - return false; -} - - -static inline uint32 -secs_this_year(uint32 year) -{ - if (leap_year(year)) - return 31622400; - - return 31536000; -} - - +/*! Converts the \a tm data to seconds. Note that the base year is not + 1900 as in POSIX, but 1970. +*/ uint32 -rtc_tm_to_secs(const struct tm *t) +rtc_tm_to_secs(const struct tm *tm) { - uint32 wholeYear; - uint32 time = 0; - uint32 i; + uint32 days; + int year, month; - wholeYear = RTC_EPOCHE_BASE_YEAR + t->tm_year; + month = tm->tm_mon + 1; + year = tm->tm_year + RTC_EPOCH_BASE_YEAR; - // ToDo: get rid of these loops and compute the correct value - // i.e. days = (long)(year > 0) + year*365 + --year/4 - year/100 + year/400; - // let sSecsPerMonth[] have the values already added up + // Reference: Fliegel, H. F. and van Flandern, T. C. (1968). + // Communications of the ACM, Vol. 11, No. 10 (October, 1968). + days = tm->tm_mday - 32075 - RTC_EPOCH_JULIAN_DAY + + 1461 * (year + 4800 + (month - 14) / 12) / 4 + + 367 * (month - 2 - 12 * ((month - 14) / 12)) / 12 + - 3 * ((year + 4900 + (month - 14) / 12) / 100) / 4; - // Add up the seconds from all years since 1970 that have elapsed. - for (i = RTC_EPOCHE_BASE_YEAR; i < wholeYear; ++i) { - time += secs_this_year(i); - } - - // Add up the seconds from all months passed this year. - for (i = 0; i < t->tm_mon && i < 12; ++i) - time += sSecsPerMonth[i]; - - // Add up the seconds from all days passed this month. - if (leap_year(wholeYear) && t->tm_mon >= 2) - time += SECONDS_DAY; - - time += (t->tm_mday - 1) * SECONDS_DAY; - time += t->tm_hour * 3600; - time += t->tm_min * 60; - time += t->tm_sec; - - return time; + return days * RTC_SECONDS_DAY + tm->tm_hour * 3600 + tm->tm_min * 60 + + tm->tm_sec; } void rtc_secs_to_tm(uint32 seconds, struct tm *t) { - uint32 wholeYear = RTC_EPOCHE_BASE_YEAR; - uint32 secsThisYear; - bool keepLooping; - bool isLeapYear; - int temp; - int month; + uint32 year, month, day, l, n; - keepLooping = 1; + // Reference: Fliegel, H. F. and van Flandern, T. C. (1968). + // Communications of the ACM, Vol. 11, No. 10 (October, 1968). + l = seconds / 86400 + 68569 + RTC_EPOCH_JULIAN_DAY; + n = 4 * l / 146097; + l = l - (146097 * n + 3) / 4; + year = 4000 * (l + 1) / 1461001; + l = l - 1461 * year / 4 + 31; + month = 80 * l / 2447; + day = l - 2447 * month / 80; + l = month / 11; + month = month + 2 - 12 * l; + year = 100 * (n - 49) + year + l; - // Determine the current year by starting at 1970 and incrementing whole_year as long as - // we can keep subtracting secs_this_year from seconds. - while (keepLooping) { - secsThisYear = secs_this_year(wholeYear); + t->tm_mday = day; + t->tm_mon = month - 1; + t->tm_year = year - RTC_EPOCH_BASE_YEAR; - if (seconds >= secsThisYear) { - seconds -= secsThisYear; - ++wholeYear; - } else - keepLooping = false; - } - - t->tm_year = wholeYear - RTC_EPOCHE_BASE_YEAR; - - // Determine the current month - month = 0; - isLeapYear = leap_year(wholeYear); - do { - temp = seconds - sSecsPerMonth[month]; - - if (isLeapYear && month == 1) - temp -= SECONDS_DAY; - - if (temp >= 0) { - seconds = temp; - ++month; - } - } while (temp >= 0 && month < 12); - - t->tm_mon = month; - - t->tm_mday = seconds / SECONDS_DAY + 1; - seconds = seconds % SECONDS_DAY; - + seconds = seconds % RTC_SECONDS_DAY; t->tm_hour = seconds / 3600; + seconds = seconds % 3600; - t->tm_min = seconds / 60; - seconds = seconds % 60; - - t->tm_sec = seconds; + t->tm_sec = seconds % 60; } From axeld at mail.berlios.de Sun Oct 14 18:55:33 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sun, 14 Oct 2007 18:55:33 +0200 Subject: [Haiku-commits] r22556 - haiku/trunk/src/system/kernel Message-ID: <200710141655.l9EGtXYR003940@sheep.berlios.de> Author: axeld Date: 2007-10-14 18:55:32 +0200 (Sun, 14 Oct 2007) New Revision: 22556 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22556&view=rev Modified: haiku/trunk/src/system/kernel/real_time_clock.c Log: Fixed various style issues. Modified: haiku/trunk/src/system/kernel/real_time_clock.c =================================================================== --- haiku/trunk/src/system/kernel/real_time_clock.c 2007-10-14 15:05:14 UTC (rev 22555) +++ haiku/trunk/src/system/kernel/real_time_clock.c 2007-10-14 16:55:32 UTC (rev 22556) @@ -1,5 +1,5 @@ /* - * Copyright 2004-2006, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Copyright 2004-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. * Copyright 2003, Jeff Ward, jeff at r2d2.stcloudstate.edu. All rights reserved. * * Distributed under the terms of the MIT License. @@ -30,22 +30,20 @@ static bool sDaylightSavingTime = false; -/** Write the system time to CMOS. */ - +/*! Write the system time to CMOS. */ static void rtc_system_to_hw(void) { uint32 seconds; - seconds = (arch_rtc_get_system_time_offset(sRealTimeData) + system_time() + seconds = (arch_rtc_get_system_time_offset(sRealTimeData) + system_time() + (sIsGMT ? 0 : sTimezoneOffset)) / 1000000; - + arch_rtc_set_hw_time(seconds); } -/** Read the CMOS clock and update the system time accordingly. */ - +/*! Read the CMOS clock and update the system time accordingly. */ static void rtc_hw_to_system(void) { @@ -71,7 +69,7 @@ uint32 currentTime; bigtime_t systemTimeOffset = arch_rtc_get_system_time_offset(sRealTimeData); - + currentTime = (systemTimeOffset + system_time()) / 1000000; dprintf("system_time: %Ld\n", system_time()); dprintf("system_time_offset: %Ld\n", systemTimeOffset); @@ -90,22 +88,22 @@ { void *clonedRealTimeData; - area_id area = create_area("real time data", (void **)&sRealTimeData, B_ANY_KERNEL_ADDRESS, - PAGE_ALIGN(sizeof(struct real_time_data)), B_FULL_LOCK, - B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); + area_id area = create_area("real time data", (void **)&sRealTimeData, + B_ANY_KERNEL_ADDRESS, PAGE_ALIGN(sizeof(struct real_time_data)), + B_FULL_LOCK, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); if (area < B_OK) { panic("rtc_init: error creating real time data area\n"); return area; } - // On some systems like x86, a page cannot be read-only in userland and writable - // in the kernel. Therefore, we clone the real time data area here for user - // access; it doesn't hurt on other platforms, too. + // On some systems like x86, a page cannot be read-only in userland and + // writable in the kernel. Therefore, we clone the real time data area + // here for user access; it doesn't hurt on other platforms, too. // The area is used to share time critical information, such as the system // time conversion factor which can change at any time. - if (clone_area("real time data userland", &clonedRealTimeData, B_ANY_KERNEL_ADDRESS, - B_READ_AREA, area) < B_OK) { + if (clone_area("real time data userland", &clonedRealTimeData, + B_ANY_KERNEL_ADDRESS, B_READ_AREA, area) < B_OK) { dprintf("rtc_init: error creating real time data userland area\n"); // we don't panic because it's not kernel critical } @@ -150,6 +148,7 @@ { if (info == NULL) return B_BAD_VALUE; + info->time = real_time_clock(); info->is_gmt = sIsGMT; info->tz_minuteswest = sTimezoneOffset / 1000000LL; @@ -193,7 +192,7 @@ { if (leap_year(year)) return 31622400; - + return 31536000; } @@ -292,10 +291,9 @@ // #pragma mark - -/** This is called from the gettimeofday() implementation that's part of the - * kernel. - */ - +/*! This is called from the gettimeofday() implementation that's part of the + kernel. +*/ status_t _kern_get_timezone(time_t *_timezoneOffset, bool *_daylightSavingTime) { @@ -336,15 +334,16 @@ return B_NOT_ALLOWED; TRACE(("old system_time_offset %Ld old %Ld new %Ld gmt %d\n", - arch_rtc_get_system_time_offset(sRealTimeData), sTimezoneOffset, offset, - sIsGMT)); + arch_rtc_get_system_time_offset(sRealTimeData), sTimezoneOffset, + offset, sIsGMT)); // We only need to update our time offset if the hardware clock // does not run in the local timezone. // Since this is shared data, we need to update it atomically. if (!sIsGMT) { arch_rtc_set_system_time_offset(sRealTimeData, - arch_rtc_get_system_time_offset(sRealTimeData) + sTimezoneOffset - offset); + arch_rtc_get_system_time_offset(sRealTimeData) + sTimezoneOffset + - offset); } sTimezoneOffset = offset; @@ -362,9 +361,11 @@ { time_t offset = (time_t)(sTimezoneOffset / 1000000LL); - if (!IS_USER_ADDRESS(_timezoneOffset) || !IS_USER_ADDRESS(_daylightSavingTime) + if (!IS_USER_ADDRESS(_timezoneOffset) + || !IS_USER_ADDRESS(_daylightSavingTime) || user_memcpy(_timezoneOffset, &offset, sizeof(time_t)) < B_OK - || user_memcpy(_daylightSavingTime, &sDaylightSavingTime, sizeof(bool)) < B_OK) + || user_memcpy(_daylightSavingTime, &sDaylightSavingTime, + sizeof(bool)) < B_OK) return B_BAD_ADDRESS; return B_OK; @@ -379,7 +380,8 @@ if (!IS_USER_ADDRESS(filename) || filename == NULL - || user_strlcpy(sTimezoneFilename, filename, B_PATH_NAME_LENGTH) < B_OK) + || user_strlcpy(sTimezoneFilename, filename, + B_PATH_NAME_LENGTH) < B_OK) return B_BAD_ADDRESS; // ToDo: Shouldn't this update the system_time_offset as well? From korli at users.berlios.de Sun Oct 14 20:01:56 2007 From: korli at users.berlios.de (=?ISO-8859-1?Q?J=E9r=F4me_Duval?=) Date: Sun, 14 Oct 2007 20:01:56 +0200 Subject: [Haiku-commits] r22533 - in haiku/trunk/src/system/libroot: . posix/glibc posix/glibc/iconv posix/glibc/include posix/glibc/include/arch/ppc/bits posix/glibc/include/arch/x86/bits posix/glibc/include/bits posix/glibc/include/sys posix/glibc/libio Message-ID: 2007/10/14, Axel D?rfler : > korli at BerliOS wrote: > > Log: > > added some tsearch and iconv functions, > > Our libtextencoding.so already contains libiconv. One of them should be > removed IMO. > Actually no libiconv functions were added. wchar functions (like btowc) required some gconv functions to not crash like in bug 1549, and they are located in the iconv directory. I agree it's a bit hard to keep things working with a beast like glibc. Not sure if libiconv should be in libroot either. Maybe later. Bye, J?r?me From julun at mail.berlios.de Sun Oct 14 20:18:52 2007 From: julun at mail.berlios.de (julun at BerliOS) Date: Sun, 14 Oct 2007 20:18:52 +0200 Subject: [Haiku-commits] r22558 - haiku/trunk/src/preferences/time Message-ID: <200710141818.l9EIIqiN018569@sheep.berlios.de> Author: julun Date: 2007-10-14 20:18:52 +0200 (Sun, 14 Oct 2007) New Revision: 22558 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22558&view=rev Modified: haiku/trunk/src/preferences/time/Jamfile haiku/trunk/src/preferences/time/SettingsView.cpp haiku/trunk/src/preferences/time/SettingsView.h haiku/trunk/src/preferences/time/Time.cpp haiku/trunk/src/preferences/time/TimeMessages.h Log: * implemented gmt/ local time switch, not working atm but will investigate note: i think it should be enough to only call _kern_set_tzfilename(..) as the timezone offset and dst would have been set by clockconfig on boot or from the time prefs panel while switching the timezone. so the comment in _user_set_tzfilename should not be count and no update would be needed. it should only take the sIsGmt boolean take into account when getting the time. Modified: haiku/trunk/src/preferences/time/Jamfile =================================================================== --- haiku/trunk/src/preferences/time/Jamfile 2007-10-14 17:27:44 UTC (rev 22557) +++ haiku/trunk/src/preferences/time/Jamfile 2007-10-14 18:18:52 UTC (rev 22558) @@ -3,6 +3,9 @@ SetSubDirSupportedPlatformsBeOSCompatible ; AddSubDirSupportedPlatforms libbe_test ; +UsePrivateHeaders kernel ; +UseArchHeaders $(TARGET_ARCH) ; + Preference Time : AnalogClock.cpp BaseView.cpp Modified: haiku/trunk/src/preferences/time/SettingsView.cpp =================================================================== --- haiku/trunk/src/preferences/time/SettingsView.cpp 2007-10-14 17:27:44 UTC (rev 22557) +++ haiku/trunk/src/preferences/time/SettingsView.cpp 2007-10-14 18:18:52 UTC (rev 22558) @@ -27,6 +27,17 @@ #include +#include + + +#ifdef HAIKU_TARGET_PLATFORM_HAIKU +#include +#else +void _kset_tzfilename_(const char *name, size_t length, bool isGMT); +#define _kern_set_tzfilename _kset_tzfilename_ +#endif + + TSettingsView::TSettingsView(BRect frame) : BView(frame,"Settings", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP), @@ -106,6 +117,10 @@ Window()->PostMessage(&msg); } break; + case kRTCUpdate: + _UpdateGmtSettings(); + break; + default: BView::MessageReceived(message); break; @@ -186,16 +201,18 @@ frameRight.top = text->Frame().bottom + 5.0; fLocalTime = new BRadioButton(frameRight, "local", "Local time", - new BMessage(H_RTC_CHANGE)); + new BMessage(kRTCUpdate)); AddChild(fLocalTime); fLocalTime->ResizeToPreferred(); + fLocalTime->SetTarget(this); frameRight.left = fLocalTime->Frame().right +10.0f; - fGmtTime = new BRadioButton(frameRight, "gmt", "GMT", new BMessage(H_RTC_CHANGE)); + fGmtTime = new BRadioButton(frameRight, "gmt", "GMT", new BMessage(kRTCUpdate)); AddChild(fGmtTime); fGmtTime->ResizeToPreferred(); - + fGmtTime->SetTarget(this); + if (fIsLocalTime) fLocalTime->SetValue(B_CONTROL_ON); else @@ -254,6 +271,29 @@ void +TSettingsView::_UpdateGmtSettings() +{ + _WriteRTCSettings(); + + BPath path; + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) + return; + + path.Append("timezone"); + BEntry entry(path.Path(), true); + + if (!entry.Exists()) + return; + + entry.GetPath(&path); + + // take the existing timezone and set it's gmt use + _kern_set_tzfilename(path.Path(), B_PATH_NAME_LENGTH + , fGmtTime->Value() == B_CONTROL_ON); +} + + +void TSettingsView::_UpdateDateTime(BMessage *message) { int32 day; Modified: haiku/trunk/src/preferences/time/SettingsView.h =================================================================== --- haiku/trunk/src/preferences/time/SettingsView.h 2007-10-14 17:27:44 UTC (rev 22557) +++ haiku/trunk/src/preferences/time/SettingsView.h 2007-10-14 18:18:52 UTC (rev 22558) @@ -35,6 +35,7 @@ void _InitView(); void _ReadRTCSettings(); void _WriteRTCSettings(); + void _UpdateGmtSettings(); void _UpdateDateTime(BMessage *message); private: Modified: haiku/trunk/src/preferences/time/Time.cpp =================================================================== --- haiku/trunk/src/preferences/time/Time.cpp 2007-10-14 17:27:44 UTC (rev 22557) +++ haiku/trunk/src/preferences/time/Time.cpp 2007-10-14 18:18:52 UTC (rev 22558) @@ -18,6 +18,9 @@ #include +#include + + TimeApplication::TimeApplication() : BApplication(HAIKU_APP_SIGNATURE), fWindow(NULL) @@ -72,6 +75,7 @@ main(int argc, char** argv) { TimeApplication app; + setuid(0); app.Run(); return 0; Modified: haiku/trunk/src/preferences/time/TimeMessages.h =================================================================== --- haiku/trunk/src/preferences/time/TimeMessages.h 2007-10-14 17:27:44 UTC (rev 22557) +++ haiku/trunk/src/preferences/time/TimeMessages.h 2007-10-14 18:18:52 UTC (rev 22558) @@ -36,7 +36,7 @@ const uint32 H_USER_CHANGE = 'obUC'; // local/ gmt radiobuttons -const uint32 H_RTC_CHANGE = 'obRC'; +const uint32 kRTCUpdate = '_rtc'; // sunday/ monday radio button const uint32 kWeekStart = '_kws'; From korli at mail.berlios.de Sun Oct 14 23:44:10 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Sun, 14 Oct 2007 23:44:10 +0200 Subject: [Haiku-commits] r22559 - haiku/trunk/src/kits/interface Message-ID: <200710142144.l9ELiAQ1029698@sheep.berlios.de> Author: korli Date: 2007-10-14 23:44:10 +0200 (Sun, 14 Oct 2007) New Revision: 22559 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22559&view=rev Modified: haiku/trunk/src/kits/interface/MenuBar.cpp Log: stop tracking if we don't have a owner anymore, should help with bug #573 Modified: haiku/trunk/src/kits/interface/MenuBar.cpp =================================================================== --- haiku/trunk/src/kits/interface/MenuBar.cpp 2007-10-14 18:18:52 UTC (rev 22558) +++ haiku/trunk/src/kits/interface/MenuBar.cpp 2007-10-14 21:44:10 UTC (rev 22559) @@ -476,7 +476,7 @@ while (true) { bigtime_t snoozeAmount = 40000; - bool locked = window->Lock();//WithTimeout(200000) + bool locked = (Window() != NULL && window->Lock());//WithTimeout(200000) if (!locked) break; From julun at mail.berlios.de Mon Oct 15 01:10:54 2007 From: julun at mail.berlios.de (julun at BerliOS) Date: Mon, 15 Oct 2007 01:10:54 +0200 Subject: [Haiku-commits] r22560 - haiku/trunk/src/apps/clock Message-ID: <200710142310.l9ENAsBr026280@sheep.berlios.de> Author: julun Date: 2007-10-15 01:10:53 +0200 (Mon, 15 Oct 2007) New Revision: 22560 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22560&view=rev Modified: haiku/trunk/src/apps/clock/cl_view.cpp haiku/trunk/src/apps/clock/cl_view.h haiku/trunk/src/apps/clock/cl_wind.cpp haiku/trunk/src/apps/clock/cl_wind.h haiku/trunk/src/apps/clock/clock.cpp haiku/trunk/src/apps/clock/clock.h Log: * fixed bug #1554, it seems my patch didn't make it in completely even after several trials Modified: haiku/trunk/src/apps/clock/cl_view.cpp =================================================================== --- haiku/trunk/src/apps/clock/cl_view.cpp 2007-10-14 21:44:10 UTC (rev 22559) +++ haiku/trunk/src/apps/clock/cl_view.cpp 2007-10-14 23:10:53 UTC (rev 22560) @@ -369,3 +369,4 @@ BView::MessageReceived(msg); } } + Modified: haiku/trunk/src/apps/clock/cl_view.h =================================================================== --- haiku/trunk/src/apps/clock/cl_view.h 2007-10-14 21:44:10 UTC (rev 22559) +++ haiku/trunk/src/apps/clock/cl_view.h 2007-10-14 23:10:53 UTC (rev 22560) @@ -73,3 +73,4 @@ }; #endif + Modified: haiku/trunk/src/apps/clock/cl_wind.cpp =================================================================== --- haiku/trunk/src/apps/clock/cl_wind.cpp 2007-10-14 21:44:10 UTC (rev 22559) +++ haiku/trunk/src/apps/clock/cl_wind.cpp 2007-10-14 23:10:53 UTC (rev 22560) @@ -4,26 +4,24 @@ */ #include "cl_wind.h" +#include "cl_view.h" #include #include #include -#include +#include + + #include -#include #include -#include -#include "cl_view.h" - - TClockWindow::TClockWindow(BRect frame, const char* title) : BWindow(frame, title, B_TITLED_WINDOW, - B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AVOID_FRONT, B_ALL_WORKSPACES) + B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AVOID_FRONT, B_ALL_WORKSPACES), + fOnScreenView(NULL) { - SetPulseRate(500000); - // half second pulse rate + _InitWindow(); } @@ -42,9 +40,9 @@ if (ref >= 0) { BPoint lefttop = Frame().LeftTop(); write(ref, (char *)&lefttop, sizeof(BPoint)); - short face = theOnscreenView->ReturnFace(); + short face = fOnScreenView->ReturnFace(); write(ref, (char *)&face, sizeof(short)); - bool seconds = theOnscreenView->ReturnSeconds(); + bool seconds = fOnScreenView->ReturnSeconds(); write(ref, (char *)&seconds, sizeof(bool)); close(ref); } @@ -52,3 +50,45 @@ be_app->PostMessage(B_QUIT_REQUESTED); return true; } + + +void +TClockWindow::_InitWindow() +{ + // half second pulse rate + SetPulseRate(500000); + + fOnScreenView = new TOnscreenView(BRect(0, 0, 82, 82), "Clock", 22, 15, 41); + AddChild(fOnScreenView); + + int ref; + BPath path; + if (find_directory (B_USER_SETTINGS_DIRECTORY, &path) == B_OK) { + path.Append("Clock_settings"); + ref = open(path.Path(), O_RDONLY); + if (ref >= 0) { + BPoint leftTop; + read(ref, (char*)&leftTop, sizeof(leftTop)); + + short face; + read(ref, (char *)&face, sizeof(short)); + fOnScreenView->UseFace(face); + + bool secs; + read(ref, (char *)&secs, sizeof(bool)); + fOnScreenView->ShowSecs(secs); + + close(ref); + + MoveTo(leftTop); + + BRect frame = Frame(); + frame.InsetBy(-4, -4); + // it's not visible so reposition. I'm not going to get + // fancy here, just place in the default location + if (!frame.Intersects(BScreen(this).Frame())) + MoveTo(100, 100); + } + } +} + Modified: haiku/trunk/src/apps/clock/cl_wind.h =================================================================== --- haiku/trunk/src/apps/clock/cl_wind.h 2007-10-14 21:44:10 UTC (rev 22559) +++ haiku/trunk/src/apps/clock/cl_wind.h 2007-10-14 23:10:53 UTC (rev 22560) @@ -24,7 +24,8 @@ void _InitWindow(); private: - TOnscreenView *theOnscreenView; + TOnscreenView *fOnScreenView; }; #endif // _CLOCK_WINDOW_H + Modified: haiku/trunk/src/apps/clock/clock.cpp =================================================================== --- haiku/trunk/src/apps/clock/clock.cpp 2007-10-14 21:44:10 UTC (rev 22559) +++ haiku/trunk/src/apps/clock/clock.cpp 2007-10-14 23:10:53 UTC (rev 22560) @@ -43,3 +43,4 @@ return 0; } + Modified: haiku/trunk/src/apps/clock/clock.h =================================================================== --- haiku/trunk/src/apps/clock/clock.h 2007-10-14 21:44:10 UTC (rev 22559) +++ haiku/trunk/src/apps/clock/clock.h 2007-10-14 23:10:53 UTC (rev 22560) @@ -29,3 +29,4 @@ #endif // _CLOCK_APPLICATION_H + From HOST.HAIKU at gmx.de Mon Oct 15 01:17:44 2007 From: HOST.HAIKU at gmx.de (Julun) Date: Mon, 15 Oct 2007 01:17:44 +0200 Subject: [Haiku-commits] r22560 - haiku/trunk/src/apps/clock In-Reply-To: <200710142310.l9ENAsBr026280@sheep.berlios.de> References: <200710142310.l9ENAsBr026280@sheep.berlios.de> Message-ID: <1192403864.6355.1.camel@ubuntu> Hi, How does one close a ticket, or is it required to be the owner of the ticket? Regards, Julun From bonefish at cs.tu-berlin.de Mon Oct 15 01:41:33 2007 From: bonefish at cs.tu-berlin.de (Ingo Weinhold) Date: Mon, 15 Oct 2007 01:41:33 +0200 Subject: [Haiku-commits] r22560 - haiku/trunk/src/apps/clock In-Reply-To: <1192403864.6355.1.camel@ubuntu> References: <200710142310.l9ENAsBr026280@sheep.berlios.de> <1192403864.6355.1.camel@ubuntu> Message-ID: <20071015014133.1503.1@cs.tu-berlin.de> On 2007-10-15 at 01:17:44 [+0200], Julun wrote: > > How does one close a ticket, or is it required to be the owner of the > ticket? Looks like you weren't in Trac's "developers" group yet. I've added you -- I hope user name "julun" is correct -- so now you should have the required permission. CU, Ingo From bonefish at mail.berlios.de Mon Oct 15 02:41:19 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Mon, 15 Oct 2007 02:41:19 +0200 Subject: [Haiku-commits] r22561 - in haiku/trunk: headers/private/storage src/kits/storage Message-ID: <200710150041.l9F0fJK9027316@sheep.berlios.de> Author: bonefish Date: 2007-10-15 02:41:18 +0200 (Mon, 15 Oct 2007) New Revision: 22561 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22561&view=rev Modified: haiku/trunk/headers/private/storage/Partition.h haiku/trunk/src/kits/storage/Partition.cpp haiku/trunk/src/kits/storage/PartitionDelegate.cpp haiku/trunk/src/kits/storage/PartitionDelegate.h Log: Beginning of the integration with the new userland disk system add-on based code. Small API changes. Modified: haiku/trunk/headers/private/storage/Partition.h =================================================================== --- haiku/trunk/headers/private/storage/Partition.h 2007-10-14 23:10:53 UTC (rev 22560) +++ haiku/trunk/headers/private/storage/Partition.h 2007-10-15 00:41:18 UTC (rev 22561) @@ -25,7 +25,7 @@ class BPartition { public: // Partition Info - + off_t Offset() const; // 0 for devices off_t Size() const; off_t ContentSize() const; // 0 if uninitialized @@ -95,12 +95,12 @@ status_t Move(off_t newOffset); bool CanSetName() const; - status_t ValidateSetName(char *name) const; + status_t ValidateSetName(BString* name) const; // adjusts name to be suitable status_t SetName(const char *name); bool CanSetContentName(bool *whileMounted = NULL) const; - status_t ValidateSetContentName(char *name) const; + status_t ValidateSetContentName(BString* name) const; // adjusts name to be suitable status_t SetContentName(const char *name); @@ -121,7 +121,7 @@ bool CanInitialize(const char *diskSystem) const; status_t GetInitializationParameterEditor(const char *system, BDiskDeviceParameterEditor **editor) const; - status_t ValidateInitialize(const char *diskSystem, char *name, + status_t ValidateInitialize(const char *diskSystem, BString* name, const char *parameters); status_t Initialize(const char *diskSystem, const char *name, const char *parameters); @@ -130,12 +130,12 @@ // Modification of child partitions bool CanCreateChild() const; - status_t GetChildCreationParameterEditor(const char *system, + status_t GetChildCreationParameterEditor(const char *type, BDiskDeviceParameterEditor **editor) const; - status_t ValidateCreateChild(off_t *start, off_t *size, - const char *type, const char *parameters) const; - status_t CreateChild(off_t start, off_t size, const char *type, - const char *parameters, BPartition **child = NULL); + status_t ValidateCreateChild(off_t* start, off_t* size, + const char* type, BString* name, const char* parameters) const; + status_t CreateChild(off_t start, off_t size, const char* type, + const char* name, const char* parameters, BPartition** child = NULL); bool CanDeleteChild(int32 index) const; status_t DeleteChild(int32 index); @@ -167,6 +167,13 @@ BPartition *_VisitEachDescendant(BDiskDeviceVisitor *visitor, int32 level = -1); + const user_partition_data* _PartitionData() const; + + bool _HasContent() const; + bool _SupportsOperation(uint32 flag, uint32 whileMountedFlag, + bool* whileMounted) const; + bool _SupportsChildOperation(const BPartition* child, uint32 flag) const; + friend class BDiskDevice; friend class BDiskSystem; friend class BMutablePartition; Modified: haiku/trunk/src/kits/storage/Partition.cpp =================================================================== --- haiku/trunk/src/kits/storage/Partition.cpp 2007-10-14 23:10:53 UTC (rev 22560) +++ haiku/trunk/src/kits/storage/Partition.cpp 2007-10-15 00:41:18 UTC (rev 22561) @@ -29,9 +29,12 @@ #include #include +#include "PartitionDelegate.h" + using std::nothrow; + /*! \class BPartition \brief A BPartition object represent a partition and provides a lot of methods to retrieve information about it and some to manipulate it. @@ -77,6 +80,7 @@ { } + // destructor /*! \brief Frees all resources associated with this object. */ @@ -85,6 +89,7 @@ _Unset(); } + // Offset /*! \brief Returns the partition's offset relative to the beginning of the device it resides on. @@ -94,9 +99,10 @@ off_t BPartition::Offset() const { - return (fPartitionData ? fPartitionData->offset : 0); + return _PartitionData()->offset; } + // Size /*! \brief Returns the size of the partition. \return The size of the partition in bytes. @@ -104,14 +110,15 @@ off_t BPartition::Size() const { - return (fPartitionData ? fPartitionData->size : 0); + return _PartitionData()->size; } + // ContentSize off_t BPartition::ContentSize() const { - return (fPartitionData ? fPartitionData->content_size : 0); + return _PartitionData()->content_size; } // BlockSize @@ -121,9 +128,10 @@ uint32 BPartition::BlockSize() const { - return (fPartitionData ? fPartitionData->block_size : 0); + return _PartitionData()->block_size; } + // Index /*! \brief Returns the index of the partition in its session's list of partitions. @@ -132,48 +140,50 @@ int32 BPartition::Index() const { - return (fPartitionData ? fPartitionData->index : -1); + return _PartitionData()->index; } + // Status uint32 BPartition::Status() const { - return (fPartitionData ? fPartitionData->status : 0); + return _PartitionData()->status; } + // ContainsFileSystem bool BPartition::ContainsFileSystem() const { - return (fPartitionData - && (fPartitionData->flags & B_PARTITION_FILE_SYSTEM)); + return _PartitionData()->flags & B_PARTITION_FILE_SYSTEM; } + // ContainsPartitioningSystem bool BPartition::ContainsPartitioningSystem() const { - return (fPartitionData - && (fPartitionData->flags & B_PARTITION_PARTITIONING_SYSTEM)); + return _PartitionData()->flags & B_PARTITION_PARTITIONING_SYSTEM; } + // IsDevice bool BPartition::IsDevice() const { - return (fPartitionData - && (fPartitionData->flags & B_PARTITION_IS_DEVICE)); + return _PartitionData()->flags & B_PARTITION_IS_DEVICE; } + // IsReadOnly bool BPartition::IsReadOnly() const { - return (fPartitionData - && (fPartitionData->flags & B_PARTITION_READ_ONLY)); + return _PartitionData()->flags & B_PARTITION_READ_ONLY; } + // IsMounted /*! \brief Returns whether the volume is mounted. \return \c true, if the volume is mounted, \c false otherwise. @@ -181,21 +191,21 @@ bool BPartition::IsMounted() const { - return (fPartitionData - && (fPartitionData->flags & B_PARTITION_MOUNTED)); + return _PartitionData()->flags & B_PARTITION_MOUNTED; // alternatively: - // return (fPartitionData && fPartitionData->volume >= 0); + // return _PartitionData()->volume >= 0; } + // IsBusy bool BPartition::IsBusy() const { - return (fPartitionData - && (fPartitionData->flags - & (B_PARTITION_BUSY | B_PARTITION_DESCENDANT_BUSY))); + return _PartitionData()->flags + & (B_PARTITION_BUSY | B_PARTITION_DESCENDANT_BUSY); } + // Flags /*! \brief Returns the flags for this partitions. @@ -213,9 +223,10 @@ uint32 BPartition::Flags() const { - return (fPartitionData ? fPartitionData->flags : 0); + return _PartitionData()->flags; } + // Name /*! \brief Returns the name of the partition. @@ -228,16 +239,18 @@ const char * BPartition::Name() const { - return (fPartitionData ? fPartitionData->name : NULL); + return _PartitionData()->name; } + // ContentName const char * BPartition::ContentName() const { - return (fPartitionData ? fPartitionData->content_name : NULL); + return _PartitionData()->content_name; } + // Type /*! \brief Returns a human readable string for the type of the partition. \return A human readable string for the type of the partition. @@ -245,16 +258,18 @@ const char * BPartition::Type() const { - return (fPartitionData ? fPartitionData->type : NULL); + return _PartitionData()->type; } + // ContentType const char * BPartition::ContentType() const { - return (fPartitionData ? fPartitionData->content_type : NULL); + return _PartitionData()->content_type; } + // ID /*! \brief Returns a unique identifier for this partition. @@ -268,7 +283,7 @@ int32 BPartition::ID() const { - return (fPartitionData ? fPartitionData->id : -1); + return _PartitionData()->id; } @@ -276,7 +291,7 @@ const char* BPartition::Parameters() const { - return fPartitionData ? fPartitionData->parameters : NULL; + return _PartitionData()->parameters; } @@ -284,7 +299,7 @@ const char* BPartition::ContentParameters() const { - return fPartitionData ? fPartitionData->content_parameters : NULL; + return _PartitionData()->content_parameters; } @@ -292,13 +307,17 @@ status_t BPartition::GetDiskSystem(BDiskSystem *diskSystem) const { - if (!fPartitionData || !diskSystem) + const user_partition_data* data = _PartitionData(); + if (!data || !diskSystem) return B_BAD_VALUE; - if (fPartitionData->disk_system < 0) + + if (data->disk_system < 0) return B_ENTRY_NOT_FOUND; - return diskSystem->_SetTo(fPartitionData->disk_system); + + return diskSystem->_SetTo(data->disk_system); } + // GetPath status_t BPartition::GetPath(BPath *path) const @@ -333,6 +352,7 @@ return error; } + // GetVolume /*! \brief Returns a BVolume for the partition. @@ -346,12 +366,13 @@ status_t BPartition::GetVolume(BVolume *volume) const { - status_t error = (fPartitionData && volume ? B_OK : B_BAD_VALUE); - if (error == B_OK) - error = volume->SetTo(fPartitionData->volume); - return error; + if (volume) + return B_BAD_VALUE; + + return volume->SetTo(_PartitionData()->volume); } + // GetIcon /*! \brief Returns an icon for this partition. @@ -393,6 +414,7 @@ return B_ERROR; } + // GetMountPoint /*! \brief Returns the mount point for the partition. @@ -479,7 +501,7 @@ BPartition::Mount(const char *mountPoint, uint32 mountFlags, const char *parameters) { - if (!fPartitionData || IsMounted() || !ContainsFileSystem()) + if (IsMounted() || !ContainsFileSystem()) return B_BAD_VALUE; // get the partition path @@ -521,6 +543,7 @@ return device; } + // Unmount /*! \brief Unmounts the volume. @@ -535,7 +558,7 @@ status_t BPartition::Unmount(uint32 unmountFlags) { - if (fPartitionData == NULL || !IsMounted()) + if (!IsMounted()) return B_BAD_VALUE; // get the partition path @@ -554,6 +577,7 @@ return status; } + // Device /*! \brief Returns the device this partition resides on. \return The device this partition resides on. @@ -564,6 +588,7 @@ return fDevice; } + // Parent BPartition * BPartition::Parent() const @@ -571,22 +596,33 @@ return fParent; } + // ChildAt BPartition * BPartition::ChildAt(int32 index) const { - if (!fPartitionData || index < 0 || index >= fPartitionData->child_count) + if (fDelegate) { + Delegate* child = fDelegate->ChildAt(index); + return child ? child->Partition() : NULL; + } + + if (index < 0 || index >= fPartitionData->child_count) return NULL; return (BPartition*)fPartitionData->children[index]->user_data; } + // CountChildren int32 BPartition::CountChildren() const { - return (fPartitionData ? fPartitionData->child_count : 0); + if (fDelegate) + return fDelegate->CountChildren(); + + return fPartitionData->child_count; } + // FindDescendant BPartition * BPartition::FindDescendant(partition_id id) const @@ -595,15 +631,18 @@ return const_cast(this)->VisitEachDescendant(&visitor); } + // GetPartitioningInfo status_t BPartition::GetPartitioningInfo(BPartitioningInfo *info) const { - if (!info || !fPartitionData || !_IsShadow()) + if (!fDelegate || !info) return B_BAD_VALUE; - return info->_SetTo(_ShadowID(), _ChangeCounter()); + + return fDelegate->GetPartitioningInfo(info); } + // VisitEachChild BPartition * BPartition::VisitEachChild(BDiskDeviceVisitor *visitor) @@ -618,6 +657,7 @@ return NULL; } + // VisitEachDescendant BPartition * BPartition::VisitEachDescendant(BDiskDeviceVisitor *visitor) @@ -627,468 +667,524 @@ return NULL; } + // CanDefragment bool BPartition::CanDefragment(bool *whileMounted) const { - return (fPartitionData && _IsShadow() - && _kern_supports_defragmenting_partition(_ShadowID(), - _ChangeCounter(), - whileMounted)); + return _SupportsOperation(B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING, + B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING_WHILE_MOUNTED, whileMounted); } + // Defragment status_t BPartition::Defragment() const { - if (!fPartitionData || !_IsShadow()) + if (!fDelegate) return B_BAD_VALUE; - status_t error = _kern_defragment_partition(_ShadowID(), _ChangeCounter()); - if (error == B_OK) - error = Device()->Update(); - return error; + + return fDelegate->Defragment(); } + // CanRepair bool BPartition::CanRepair(bool checkOnly, bool *whileMounted) const { - return (fPartitionData && _IsShadow() - && _kern_supports_repairing_partition(_ShadowID(), _ChangeCounter(), - checkOnly, whileMounted)); + uint32 flag; + uint32 whileMountedFlag; + if (checkOnly) { + flag = B_DISK_SYSTEM_SUPPORTS_CHECKING; + whileMountedFlag = B_DISK_SYSTEM_SUPPORTS_CHECKING_WHILE_MOUNTED; + } else { + flag = B_DISK_SYSTEM_SUPPORTS_REPAIRING; + whileMountedFlag = B_DISK_SYSTEM_SUPPORTS_REPAIRING_WHILE_MOUNTED; + } + + return _SupportsOperation(flag, whileMountedFlag, whileMounted); } + // Repair status_t BPartition::Repair(bool checkOnly) const { - if (!fPartitionData || !_IsShadow()) + if (!fDelegate) return B_BAD_VALUE; - status_t error = _kern_repair_partition(_ShadowID(), _ChangeCounter(), - checkOnly); - if (error == B_OK) - error = Device()->Update(); - return error; + + return fDelegate->Repair(checkOnly); } + // CanResize bool BPartition::CanResize(bool *canResizeContents, bool *whileMounted) const { - return (fPartitionData && !IsDevice() && Parent() && _IsShadow() - && _kern_supports_resizing_partition(_ShadowID(), _ChangeCounter(), - canResizeContents, whileMounted)); + BPartition* parent = Parent(); + if (!parent) + return false; + + if (!parent->_SupportsChildOperation(this, + B_DISK_SYSTEM_SUPPORTS_RESIZING_CHILD)) { + return false; + } + + if (!_HasContent()) + return true; + + return _SupportsOperation(B_DISK_SYSTEM_SUPPORTS_RESIZING, + B_DISK_SYSTEM_SUPPORTS_RESIZING_WHILE_MOUNTED, whileMounted); } + // ValidateResize status_t BPartition::ValidateResize(off_t *size) const { - if (!fPartitionData || IsDevice() || !Parent() || !_IsShadow() || !size) + BPartition* parent = Parent(); + if (!parent || !fDelegate) return B_BAD_VALUE; - return _kern_validate_resize_partition(_ShadowID(), _ChangeCounter(), - size); + + status_t error = parent->fDelegate->ValidateResizeChild(fDelegate, size); + if (error != B_OK) + return error; + + if (_HasContent()) { +// TODO: We would actually need the parameter for the content size. + off_t contentSize = *size; + error = fDelegate->ValidateResize(&contentSize); + if (error != B_OK) + return error; + + if (contentSize > *size) + return B_BAD_VALUE; + } + + return B_OK; } + // Resize status_t BPartition::Resize(off_t size) { - if (!fPartitionData || IsDevice() || !Parent() || !_IsShadow()) + BPartition* parent = Parent(); + if (!parent || !fDelegate) return B_BAD_VALUE; - status_t error = _kern_resize_partition(_ShadowID(), _ChangeCounter(), - size); - if (error == B_OK) - error = Device()->Update(); - return error; + + status_t error; + off_t contentSize = size; + if (_HasContent()) { + error = fDelegate->ValidateResize(&contentSize); + if (error != B_OK) + return error; + + if (contentSize > size) + return B_BAD_VALUE; + } + + // If shrinking the partition, resize content first, otherwise last. + bool shrink = (Size() > size); + + if (shrink && ContentType() != NULL) { + error = fDelegate->Resize(contentSize); + if (error != B_OK) + return error; + } + + error = parent->fDelegate->ResizeChild(fDelegate, size); + if (error != B_OK) + return error; + + if (!shrink && ContentType() != NULL) { + error = fDelegate->Resize(contentSize); + if (error != B_OK) + return error; + } + + return B_OK; } + // CanMove bool BPartition::CanMove(BObjectList *unmovableDescendants, BObjectList *movableOnlyIfUnmounted) const { - // check parameters - if (!fPartitionData || IsDevice() || !Parent() || !_IsShadow()) + BPartition* parent = Parent(); + if (!parent || !fDelegate) return false; - // count descendants and allocate partition_id arrays large enough - int32 descendantCount = _CountDescendants(); - partition_id *unmovableIDs = NULL; - partition_id *needUnmountingIDs = NULL; - ArrayDeleter deleter1; - ArrayDeleter deleter2; - if (descendantCount > 0) { - // allocate arrays - unmovableIDs = new(nothrow) partition_id[descendantCount]; - needUnmountingIDs = new(nothrow) partition_id[descendantCount]; - deleter1.SetTo(unmovableIDs); - deleter2.SetTo(needUnmountingIDs); - if (!unmovableIDs || !needUnmountingIDs) - return false; - // init arrays - for (int32 i = 0; i < descendantCount; i++) { - unmovableIDs[i] = -1; - needUnmountingIDs[i] = -1; - } + + if (!parent->_SupportsChildOperation(this, + B_DISK_SYSTEM_SUPPORTS_MOVING_CHILD)) { + return false; } - // get the info - bool result = _kern_supports_moving_partition(_ShadowID(), - _ChangeCounter(), unmovableIDs, needUnmountingIDs, - descendantCount); - if (result) { - // get unmovable BPartition objects for returned IDs - if (unmovableDescendants) { - for (int32 i = 0; i < descendantCount && unmovableIDs[i] != -1; - i++) { - BPartition *descendant = FindDescendant(unmovableIDs[i]); - if (!descendant || !unmovableDescendants->AddItem(descendant)) - return false; - } - } - // get BPartition objects needing to be unmounted for returned IDs - if (movableOnlyIfUnmounted) { - for (int32 i = 0; - i < descendantCount && needUnmountingIDs[i] != -1; - i++) { - BPartition *descendant = FindDescendant(needUnmountingIDs[i]); - if (!descendant || !movableOnlyIfUnmounted->AddItem(descendant)) - return false; - } - } - } - return result; + + bool whileMounted; + bool movable = _SupportsOperation(B_DISK_SYSTEM_SUPPORTS_MOVING, + B_DISK_SYSTEM_SUPPORTS_MOVING_WHILE_MOUNTED, &whileMounted); + if (!movable) + return false; + + if (!whileMounted) + movableOnlyIfUnmounted->AddItem(const_cast(this)); + + // collect descendent partitions + // TODO: ... +// TODO: Currently there's no interface for asking descendents. They'll still +// have the same offset (relative to their parent) after moving. The only thing +// we really have to ask is whether they need to be unmounted. + + return true; } + // ValidateMove status_t -BPartition::ValidateMove(off_t *newOffset) const +BPartition::ValidateMove(off_t *offset) const { - if (!fPartitionData || IsDevice() || !Parent() || !_IsShadow() - || !newOffset) { + BPartition* parent = Parent(); + if (!parent || !fDelegate) return B_BAD_VALUE; + + status_t error = parent->fDelegate->ValidateMoveChild(fDelegate, offset); + if (error != B_OK) + return error; + + if (_HasContent()) { + off_t contentOffset = *offset; + error = fDelegate->ValidateMove(&contentOffset); + if (error != B_OK) + return error; + + if (contentOffset != *offset) + return B_BAD_VALUE; } - return _kern_validate_move_partition(_ShadowID(), _ChangeCounter(), - newOffset); + + return B_OK; } + // Move status_t -BPartition::Move(off_t newOffset) +BPartition::Move(off_t offset) { - if (!fPartitionData || IsDevice() || !Parent() || !_IsShadow()) + BPartition* parent = Parent(); + if (!parent || !fDelegate) return B_BAD_VALUE; - status_t error = _kern_resize_partition(_ShadowID(), _ChangeCounter(), - newOffset); - if (error == B_OK) - error = Device()->Update(); - return error; + + status_t error = parent->fDelegate->MoveChild(fDelegate, offset); + if (error != B_OK) + return error; + + if (_HasContent()) { + error = fDelegate->Move(offset); + if (error != B_OK) + return error; + } + + return B_OK; } + // CanSetName bool BPartition::CanSetName() const { - return (fPartitionData && Parent() && _IsShadow() - && _kern_supports_setting_partition_name(_ShadowID(), - _ChangeCounter())); + BPartition* parent = Parent(); + if (!parent || !fDelegate) + return false; + + return parent->_SupportsChildOperation(this, + B_DISK_SYSTEM_SUPPORTS_SETTING_NAME); } + // ValidateSetName status_t -BPartition::ValidateSetName(char *name) const +BPartition::ValidateSetName(BString* name) const { - if (!fPartitionData || IsDevice() || !Parent() || !_IsShadow() || !name) + BPartition* parent = Parent(); + if (!parent || !fDelegate) return B_BAD_VALUE; - return _kern_validate_set_partition_name(_ShadowID(), _ChangeCounter(), - name); + + return parent->fDelegate->ValidateSetName(fDelegate, name); } + // SetName status_t BPartition::SetName(const char *name) { - if (!fPartitionData || IsDevice() || !Parent() || !_IsShadow() || !name) + BPartition* parent = Parent(); + if (!parent || !fDelegate) return B_BAD_VALUE; - status_t error = _kern_set_partition_name(_ShadowID(), _ChangeCounter(), - name); - if (error == B_OK) - error = Device()->Update(); - return error; + + return parent->fDelegate->SetName(fDelegate, name); } + // CanSetContentName bool BPartition::CanSetContentName(bool *whileMounted) const { - return (fPartitionData && _IsShadow() - && _kern_supports_setting_partition_content_name(_ShadowID(), - _ChangeCounter(), - whileMounted)); + return _SupportsOperation(B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME, + B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME_WHILE_MOUNTED, + whileMounted); } + // ValidateSetContentName status_t -BPartition::ValidateSetContentName(char *name) const +BPartition::ValidateSetContentName(BString* name) const { - if (!fPartitionData || !_IsShadow() || !name) + if (!fDelegate) return B_BAD_VALUE; - return _kern_validate_set_partition_content_name(_ShadowID(), - _ChangeCounter(), name); + + return fDelegate->ValidateSetContentName(name); } + // SetContentName status_t BPartition::SetContentName(const char *name) { - if (!fPartitionData || !_IsShadow() || !name) + if (!fDelegate) return B_BAD_VALUE; - status_t error = _kern_set_partition_content_name(_ShadowID(), - _ChangeCounter(), name); - if (error == B_OK) - error = Device()->Update(); - return error; + + return fDelegate->SetContentName(name); } + // CanSetType bool BPartition::CanSetType() const { - return (fPartitionData && Parent() && _IsShadow() - && _kern_supports_setting_partition_type(_ShadowID(), - _ChangeCounter())); + BPartition* parent = Parent(); + if (!parent) + return false; + + return parent->_SupportsChildOperation(this, + B_DISK_SYSTEM_SUPPORTS_SETTING_TYPE); } + // ValidateSetType status_t BPartition::ValidateSetType(const char *type) const { - if (!fPartitionData || IsDevice() || !Parent() || !_IsShadow() || !type) + BPartition* parent = Parent(); + if (!parent || !fDelegate) return B_BAD_VALUE; - return _kern_validate_set_partition_type(_ShadowID(), _ChangeCounter(), - type); + + return parent->fDelegate->ValidateSetType(fDelegate, type); } + // SetType status_t BPartition::SetType(const char *type) { - if (!fPartitionData || IsDevice() || !Parent() || !_IsShadow() || !type) + BPartition* parent = Parent(); + if (!parent || !fDelegate) return B_BAD_VALUE; - status_t error = _kern_set_partition_type(_ShadowID(), _ChangeCounter(), - type); - if (error == B_OK) - error = Device()->Update(); - return error; + + return parent->fDelegate->SetType(fDelegate, type); } + // CanEditParameters bool BPartition::CanEditParameters() const { - return (fPartitionData && Parent() && _IsShadow() - && _kern_supports_setting_partition_parameters(_ShadowID(), - _ChangeCounter())); + BPartition* parent = Parent(); + if (!parent) + return false; + + return parent->_SupportsChildOperation(this, + B_DISK_SYSTEM_SUPPORTS_SETTING_PARAMETERS); } + // GetParameterEditor status_t BPartition::GetParameterEditor(BDiskDeviceParameterEditor **editor) { - // not implemented - return B_ERROR; + BPartition* parent = Parent(); + if (!parent || !fDelegate) + return B_BAD_VALUE; + + return parent->fDelegate->GetParameterEditor(fDelegate, editor); } + // SetParameters status_t BPartition::SetParameters(const char *parameters) { - if (!fPartitionData || IsDevice() || !Parent() || !_IsShadow()) + BPartition* parent = Parent(); + if (!parent || !fDelegate) return B_BAD_VALUE; - status_t error = _kern_set_partition_parameters(_ShadowID(), - _ChangeCounter(), - parameters, - (parameters - ? strlen(parameters)+1 - : 0)); - if (error == B_OK) - error = Device()->Update(); - return error; + + return parent->fDelegate->SetParameters(fDelegate, parameters); } + // CanEditContentParameters bool BPartition::CanEditContentParameters(bool *whileMounted) const { - return (fPartitionData && _IsShadow() - && _kern_supports_setting_partition_content_parameters( - _ShadowID(), _ChangeCounter(), whileMounted)); + return _SupportsOperation(B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS, + B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS_WHILE_MOUNTED, + whileMounted); } [... truncated: 433 lines follow ...] From bonefish at mail.berlios.de Mon Oct 15 02:42:58 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Mon, 15 Oct 2007 02:42:58 +0200 Subject: [Haiku-commits] r22562 - haiku/trunk/src/tests/apps/partitioner Message-ID: <200710150042.l9F0gwF2027377@sheep.berlios.de> Author: bonefish Date: 2007-10-15 02:42:57 +0200 (Mon, 15 Oct 2007) New Revision: 22562 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22562&view=rev Modified: haiku/trunk/src/tests/apps/partitioner/Partitioner.cpp Log: Adjusted due to API changes. It compiles again, but won't work for a while. Modified: haiku/trunk/src/tests/apps/partitioner/Partitioner.cpp =================================================================== --- haiku/trunk/src/tests/apps/partitioner/Partitioner.cpp 2007-10-15 00:41:18 UTC (rev 22561) +++ haiku/trunk/src/tests/apps/partitioner/Partitioner.cpp 2007-10-15 00:42:57 UTC (rev 22562) @@ -384,10 +384,9 @@ } // validate parameters - char validatedName[B_OS_NAME_LENGTH]; - strlcpy(validatedName, name.String(), sizeof(validatedName)); + BString validatedName(name); if (partition->ValidateInitialize(diskSystem->Name(), - supportsName ? validatedName : NULL, parameters.String()) + supportsName ? &validatedName : NULL, parameters.String()) != B_OK) { printf("Validation of the given values failed. Sorry, can't " "continue.\n"); @@ -399,7 +398,7 @@ printf("Everything looks dandy.\n"); } else { printf("The disk system adjusted the file name to \"%s\".\n", - validatedName); + validatedName.String()); name = validatedName; } @@ -588,7 +587,8 @@ // validate parameters off_t validatedStart = start; off_t validatedSize = size; - if (partition->ValidateCreateChild(&start, &size, type, +// TODO: Support the name parameter! + if (partition->ValidateCreateChild(&start, &size, type, NULL, parameters.String()) != B_OK) { printf("Validation of the given values failed. Sorry, can't " "continue.\n"); @@ -633,7 +633,7 @@ } // create child - error = partition->CreateChild(start, size, type, + error = partition->CreateChild(start, size, type, NULL, parameters.String()); if (error != B_OK) printf("Creating the partiiton failed: %s\n", strerror(error)); From axeld at mail.berlios.de Mon Oct 15 13:41:50 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 15 Oct 2007 13:41:50 +0200 Subject: [Haiku-commits] r22563 - in haiku/trunk: headers/os/add-ons/graphics headers/os/interface headers/private/app src/kits/interface src/servers/app src/servers/app/drawing Message-ID: <200710151141.l9FBfoaB028494@sheep.berlios.de> Author: axeld Date: 2007-10-15 13:41:47 +0200 (Mon, 15 Oct 2007) New Revision: 22563 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22563&view=rev Modified: haiku/trunk/headers/os/add-ons/graphics/Accelerant.h haiku/trunk/headers/os/interface/Bitmap.h haiku/trunk/headers/os/interface/Screen.h haiku/trunk/headers/private/app/ServerProtocol.h haiku/trunk/src/kits/interface/PrivateScreen.cpp haiku/trunk/src/kits/interface/PrivateScreen.h haiku/trunk/src/kits/interface/Screen.cpp haiku/trunk/src/servers/app/ServerApp.cpp haiku/trunk/src/servers/app/drawing/AccelerantHWInterface.cpp haiku/trunk/src/servers/app/drawing/AccelerantHWInterface.h haiku/trunk/src/servers/app/drawing/HWInterface.cpp haiku/trunk/src/servers/app/drawing/HWInterface.h Log: * Introduced a monitor_info structure and means to let it be filled by the accelerant (or the app_server via EDID info). It's still experimental API, and opinions are welcome. * Moved BPrivateScreen into the BPrivate namespace. * Rewrote Screen.h. * Introduced a BScreen::GetMonitorInfo() method, and implemented it in the app server as well (ie. AS_GET_MONITOR_INFO). Modified: haiku/trunk/headers/os/add-ons/graphics/Accelerant.h =================================================================== --- haiku/trunk/headers/os/add-ons/graphics/Accelerant.h 2007-10-15 00:42:57 UTC (rev 22562) +++ haiku/trunk/headers/os/add-ons/graphics/Accelerant.h 2007-10-15 11:41:47 UTC (rev 22563) @@ -1,4 +1,4 @@ -#if !defined(_ACCELERANT_H_) +#ifndef _ACCELERANT_H_ #define _ACCELERANT_H_ #include @@ -15,7 +15,7 @@ typedef void * (*GetAccelerantHook)(uint32, void *); -_EXPORT void * get_accelerant_hook(uint32 feature, void *data); +void *get_accelerant_hook(uint32 feature, void *data); enum { /* initialization */ @@ -42,6 +42,7 @@ B_DPMS_MODE, /* required if driver supports DPMS */ B_SET_DPMS_MODE, /* required if driver supports DPMS */ B_GET_PREFERRED_DISPLAY_MODE, /* optional */ + B_GET_MONITOR_INFO, /* optional */ B_GET_EDID_INFO, /* optional */ /* cursor managment */ @@ -121,6 +122,26 @@ uint16 v_blank_max; } display_timing_constraints; +// TODO: experimental API +typedef struct { + uint32 version; + char vendor[128]; + char name[128]; + char serial_number[128]; + uint32 product_id; + struct { + uint16 week; + uint16 year; + } produced; + float width; + float height; + uint32 min_horizontal_frequency; // in kHz + uint32 max_horizontal_frequency; + uint32 min_vertical_frequency; // in Hz + uint32 max_vertical_frequency; + uint32 max_pixel_clock; // in kHz +} monitor_info; + enum { /* mode flags */ B_SCROLL = 1 << 0, B_8_BIT_DAC = 1 << 1, @@ -216,6 +237,7 @@ typedef uint32 (*dpms_mode)(void); typedef status_t (*set_dpms_mode)(uint32 dpms_flags); typedef status_t (*get_preferred_display_mode)(display_mode *preferredMode); +typedef status_t (*get_monitor_info)(monitor_info *info); typedef status_t (*get_edid_info)(void *info, uint32 size, uint32 *_version); typedef sem_id (*accelerant_retrace_semaphore)(void); Modified: haiku/trunk/headers/os/interface/Bitmap.h =================================================================== --- haiku/trunk/headers/os/interface/Bitmap.h 2007-10-15 00:42:57 UTC (rev 22562) +++ haiku/trunk/headers/os/interface/Bitmap.h 2007-10-15 11:41:47 UTC (rev 22563) @@ -1,5 +1,5 @@ /* - * Copyright 2001-2006, Haiku. + * Copyright 2001-2007, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -13,8 +13,11 @@ #include #include -class BPrivateScreen; +class BView; class BWindow; +namespace BPrivate { + class BPrivateScreen; +} enum { B_BITMAP_CLEAR_TO_WHITE = 0x00000001, @@ -91,15 +94,12 @@ BBitmap& operator=(const BBitmap& source); - //----- Private or reserved -----------------------------------------// - - virtual status_t Perform(perform_code d, void *arg); - private: friend class BView; friend class BApplication; - friend class BPrivateScreen; + friend class BPrivate::BPrivateScreen; + virtual status_t Perform(perform_code d, void *arg); virtual void _ReservedBitmap1(); virtual void _ReservedBitmap2(); virtual void _ReservedBitmap3(); Modified: haiku/trunk/headers/os/interface/Screen.h =================================================================== --- haiku/trunk/headers/os/interface/Screen.h 2007-10-15 00:42:57 UTC (rev 22562) +++ haiku/trunk/headers/os/interface/Screen.h 2007-10-15 11:41:47 UTC (rev 22563) @@ -1,101 +1,95 @@ -/******************************************************************************* -/ -/ File: Screen.h -/ -/ Description: BScreen provides information about a screen's current -/ display settings. It also lets you set the Desktop color. -/ -/ Copyright 1993-98, Be Incorporated, All Rights Reserved -/ -*******************************************************************************/ - +/* + * Copyright 2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + */ #ifndef _SCREEN_H #define _SCREEN_H -#include + #include #include #include #include -/*----------------------------------------------------------------*/ -/*----- BScreen structures and declarations ----------------------*/ class BWindow; -class BPrivateScreen; -/*----------------------------------------------------------------*/ -/*----- BScreen class --------------------------------------------*/ +namespace BPrivate { + class BPrivateScreen; +} class BScreen { -public: - BScreen( screen_id id=B_MAIN_SCREEN_ID ); - BScreen( BWindow *win ); - ~BScreen(); + public: + BScreen(screen_id id = B_MAIN_SCREEN_ID); + BScreen(BWindow* window); + ~BScreen(); - bool IsValid(); - status_t SetToNext(); - - color_space ColorSpace(); - BRect Frame(); - screen_id ID(); + bool IsValid(); + status_t SetToNext(); - status_t WaitForRetrace(); - status_t WaitForRetrace(bigtime_t timeout); - - uint8 IndexForColor( rgb_color rgb ); - uint8 IndexForColor( uint8 r, uint8 g, uint8 b, uint8 a=255 ); - rgb_color ColorForIndex( const uint8 index ); - uint8 InvertIndex( uint8 index ); + color_space ColorSpace(); + BRect Frame(); + screen_id ID(); -const color_map* ColorMap(); + status_t WaitForRetrace(); + status_t WaitForRetrace(bigtime_t timeout); - status_t GetBitmap( BBitmap **screen_shot, - bool draw_cursor = true, - BRect *bound = NULL); - status_t ReadBitmap( BBitmap *buffer, - bool draw_cursor = true, - BRect *bound = NULL); - - rgb_color DesktopColor(); - rgb_color DesktopColor(uint32 index); - void SetDesktopColor( rgb_color rgb, bool stick=true ); - void SetDesktopColor( rgb_color rgb, uint32 index, bool stick=true ); + uint8 IndexForColor(rgb_color color); + uint8 IndexForColor(uint8 red, uint8 green, uint8 blue, + uint8 alpha = 255); + rgb_color ColorForIndex(uint8 index); + uint8 InvertIndex(uint8 index); - status_t ProposeMode(display_mode *target, const display_mode *low, const display_mode *high); - status_t GetModeList(display_mode **mode_list, uint32 *count); - status_t GetMode(display_mode *mode); - status_t GetMode(uint32 workspace, display_mode *mode); - status_t SetMode(display_mode *mode, bool makeDefault = false); - status_t SetMode(uint32 workspace, display_mode *mode, bool makeDefault = false); - status_t GetDeviceInfo(accelerant_device_info *adi); - status_t GetPixelClockLimits(display_mode *mode, uint32 *low, uint32 *high); - status_t GetTimingConstraints(display_timing_constraints *dtc); - status_t SetDPMS(uint32 dpms_state); - uint32 DPMSState(void); - uint32 DPMSCapabilites(void); + const color_map* ColorMap(); - BPrivateScreen* private_screen(); + status_t GetBitmap(BBitmap** _bitmap, bool drawCursor = true, + BRect* frame = NULL); + status_t ReadBitmap(BBitmap* bitmap, bool drawCursor = true, + BRect* frame = NULL); -/*----- Private or reserved -----------------------------------------*/ -private: - status_t ProposeDisplayMode(display_mode *target, const display_mode *low, const display_mode *high); - BScreen &operator=(const BScreen &screen); - BScreen(const BScreen &screen); - void* BaseAddress(); - uint32 BytesPerRow(); + rgb_color DesktopColor(); + rgb_color DesktopColor(uint32 index); + void SetDesktopColor(rgb_color color, bool makeDefault = true); + void SetDesktopColor(rgb_color color, uint32 index, + bool makeDefault = true); - BPrivateScreen *fScreen; -}; + status_t ProposeMode(display_mode* target, const display_mode* low, + const display_mode* high); + status_t GetModeList(display_mode** _modeList, uint32* _count); + status_t GetMode(display_mode* mode); + status_t GetMode(uint32 workspace, display_mode* mode); + status_t SetMode(display_mode* mode, bool makeDefault = false); + status_t SetMode(uint32 workspace, display_mode* mode, + bool makeDefault = false); + status_t GetDeviceInfo(accelerant_device_info* info); + status_t GetMonitorInfo(monitor_info* info); + status_t GetPixelClockLimits(display_mode* mode, uint32* low, + uint32* high); + status_t GetTimingConstraints( + display_timing_constraints* timingConstraints); + status_t SetDPMS(uint32 state); + uint32 DPMSState(); + uint32 DPMSCapabilites(); + private: + BScreen& operator=(const BScreen& other); + BScreen(const BScreen& other); -/*----------------------------------------------------------------*/ -/*----- inline definitions ---------------------------------------*/ + // old and deprecated methods - should be faded out + BPrivate::BPrivateScreen* private_screen(); + status_t ProposeDisplayMode(display_mode* target, + const display_mode* low, const display_mode* high); + void* BaseAddress(); + uint32 BytesPerRow(); -inline uint8 BScreen::IndexForColor( rgb_color rgb ) - { return IndexForColor(rgb.red,rgb.green,rgb.blue,rgb.alpha); } + BPrivate::BPrivateScreen* fScreen; +}; -/*-------------------------------------------------------------*/ -/*-------------------------------------------------------------*/ -#endif /* _SCREEN_H */ +inline uint8 +BScreen::IndexForColor(rgb_color color) +{ + return IndexForColor(color.red, color.green, color.blue, color.alpha); +} + +#endif // _SCREEN_H Modified: haiku/trunk/headers/private/app/ServerProtocol.h =================================================================== --- haiku/trunk/headers/private/app/ServerProtocol.h 2007-10-15 00:42:57 UTC (rev 22562) +++ haiku/trunk/headers/private/app/ServerProtocol.h 2007-10-15 11:41:47 UTC (rev 22563) @@ -150,6 +150,7 @@ AS_GET_RETRACE_SEMAPHORE, AS_GET_ACCELERANT_INFO, + AS_GET_MONITOR_INFO, AS_GET_FRAME_BUFFER_CONFIG, AS_SET_DPMS, Modified: haiku/trunk/src/kits/interface/PrivateScreen.cpp =================================================================== --- haiku/trunk/src/kits/interface/PrivateScreen.cpp 2007-10-15 00:42:57 UTC (rev 22562) +++ haiku/trunk/src/kits/interface/PrivateScreen.cpp 2007-10-15 11:41:47 UTC (rev 22563) @@ -18,6 +18,9 @@ #include "PrivateScreen.h" #include "ServerProtocol.h" +#include +#include + #include #include #include @@ -25,19 +28,15 @@ #include #include -#include -#include +using namespace BPrivate; - static BObjectList sScreens(2, true); // used to synchronize creation/deletion of the sScreen object static BLocker sScreenLock("screen lock"); -using namespace BPrivate; - BPrivateScreen * BPrivateScreen::Get(BWindow *window) { @@ -515,6 +514,26 @@ status_t +BPrivateScreen::GetMonitorInfo(monitor_info* info) +{ + if (info == NULL) + return B_BAD_VALUE; + + BPrivate::AppServerLink link; + link.StartMessage(AS_GET_MONITOR_INFO); + link.Attach(ID()); + + status_t status = B_ERROR; + if (link.FlushWithReply(status) == B_OK && status == B_OK) { + link.Read(info); + return B_OK; + } + + return status; +} + + +status_t BPrivateScreen::GetPixelClockLimits(display_mode *mode, uint32 *low, uint32 *high) { if (mode == NULL || low == NULL || high == NULL) Modified: haiku/trunk/src/kits/interface/PrivateScreen.h =================================================================== --- haiku/trunk/src/kits/interface/PrivateScreen.h 2007-10-15 00:42:57 UTC (rev 22562) +++ haiku/trunk/src/kits/interface/PrivateScreen.h 2007-10-15 11:41:47 UTC (rev 22563) @@ -1,5 +1,5 @@ /* - * Copyright 2002-2005, Haiku Inc. + * Copyright 2002-2007, Haiku Inc. * Distributed under the terms of the MIT License. * * Authors: @@ -21,6 +21,8 @@ class BWindow; +namespace BPrivate { + class BPrivateScreen { // Constructor and destructor are private. Use the static methods // CheckOut() and Return() instead. @@ -59,6 +61,7 @@ status_t SetMode(uint32 workspace, display_mode *mode, bool makeDefault); status_t GetDeviceInfo(accelerant_device_info *info); + status_t GetMonitorInfo(monitor_info* info); status_t GetPixelClockLimits(display_mode *mode, uint32 *low, uint32 *high); status_t GetTimingConstraints(display_timing_constraints *constraints); @@ -95,4 +98,6 @@ bigtime_t fLastUpdate; }; +} // namespace BPrivate + #endif // _PRIVATE_SCREEN_H_ Modified: haiku/trunk/src/kits/interface/Screen.cpp =================================================================== --- haiku/trunk/src/kits/interface/Screen.cpp 2007-10-15 00:42:57 UTC (rev 22562) +++ haiku/trunk/src/kits/interface/Screen.cpp 2007-10-15 11:41:47 UTC (rev 22563) @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005, Haiku Inc. + * Copyright 2003-2007, Haiku Inc. * Distributed under the terms of the MIT License. * * Authors: @@ -7,7 +7,7 @@ * Axel D?rfler, axeld at pinc-software.de */ -/** BScreen lets you retrieve and change the display settings. */ +/*! BScreen lets you retrieve and change the display settings. */ #include "PrivateScreen.h" @@ -15,7 +15,9 @@ #include #include +using namespace BPrivate; + static const uint32 kCurrentWorkspaceIndex = ~0; /*! \brief Creates a BScreen object which represents the display with the given screen_id @@ -385,6 +387,15 @@ } +status_t +BScreen::GetMonitorInfo(monitor_info* info) +{ + if (fScreen != NULL) + return fScreen->GetMonitorInfo(info); + return B_ERROR; +} + + /*! \brief Returns, in low and high, the minimum and maximum pixel clock rates that are possible for the given mode. \param mode A pointer to a display_mode. @@ -455,17 +466,19 @@ } +// #pragma mark - Deprecated methods + + /*! \brief Returns the BPrivateScreen used by the BScreen object. \return A pointer to the BPrivateScreen class internally used by the BScreen object. */ -BPrivateScreen* +BPrivate::BPrivateScreen* BScreen::private_screen() { return fScreen; } -/*----- Private or reserved -----------------------------------------*/ /*! \brief Deprecated, use ProposeMode() instead. */ status_t @@ -475,22 +488,6 @@ } -/*! \brief Copy not allowed. -*/ -BScreen& -BScreen::operator=(const BScreen&) -{ - return *this; -} - - -/*! \brief Copy not allowed. -*/ -BScreen::BScreen(const BScreen &screen) -{ -} - - /*! \brief Returns the base address of the framebuffer. */ void* Modified: haiku/trunk/src/servers/app/ServerApp.cpp =================================================================== --- haiku/trunk/src/servers/app/ServerApp.cpp 2007-10-15 00:42:57 UTC (rev 22562) +++ haiku/trunk/src/servers/app/ServerApp.cpp 2007-10-15 11:41:47 UTC (rev 22563) @@ -2287,6 +2287,27 @@ break; } + case AS_GET_MONITOR_INFO: + { + STRACE(("ServerApp %s: get monitor info\n", Signature())); + + // We aren't using the screen_id for now... + screen_id id; + link.Read(&id); + + monitor_info info; + // TODO: I wonder if there should be a "desktop" lock... + status_t status = fDesktop->HWInterface()->GetMonitorInfo(&info); + if (status == B_OK) { + fLink.StartMessage(B_OK); + fLink.Attach(info); + } else + fLink.StartMessage(status); + + fLink.Flush(); + break; + } + case AS_GET_FRAME_BUFFER_CONFIG: { STRACE(("ServerApp %s: get frame buffer config\n", Signature())); Modified: haiku/trunk/src/servers/app/drawing/AccelerantHWInterface.cpp =================================================================== --- haiku/trunk/src/servers/app/drawing/AccelerantHWInterface.cpp 2007-10-15 00:42:57 UTC (rev 22562) +++ haiku/trunk/src/servers/app/drawing/AccelerantHWInterface.cpp 2007-10-15 11:41:47 UTC (rev 22563) @@ -351,6 +351,7 @@ fAccGetTimingConstraints = (get_timing_constraints)fAccelerantHook(B_GET_TIMING_CONSTRAINTS, NULL); fAccProposeDisplayMode = (propose_display_mode)fAccelerantHook(B_PROPOSE_DISPLAY_MODE, NULL); fAccGetPreferredDisplayMode = (get_preferred_display_mode)fAccelerantHook(B_GET_PREFERRED_DISPLAY_MODE, NULL); + fAccGetMonitorInfo = (get_monitor_info)fAccelerantHook(B_GET_MONITOR_INFO, NULL); fAccGetEDIDInfo = (get_edid_info)fAccelerantHook(B_GET_EDID_INFO, NULL); // cursor @@ -777,35 +778,71 @@ status_t -AccelerantHWInterface::GetMonitorInfo(BString& name, BString& serial) +AccelerantHWInterface::GetMonitorInfo(monitor_info* info) { + status_t status = B_NOT_SUPPORTED; + + if (fAccGetMonitorInfo != NULL) { + status = fAccGetMonitorInfo(info); + if (status == B_OK) + return B_OK; + } + if (fAccGetEDIDInfo == NULL) - return B_NOT_SUPPORTED; + return status; - edid1_info info; + edid1_info edid; uint32 version; - status_t status = fAccGetEDIDInfo(&info, sizeof(info), &version); + status = fAccGetEDIDInfo(&edid, sizeof(edid), &version); if (status < B_OK) return status; if (version != EDID_VERSION_1) return B_NOT_SUPPORTED; + memset(info, 0, sizeof(monitor_info)); + strlcpy(info->vendor, edid.vendor.manufacturer, sizeof(info->vendor)); + snprintf(info->serial_number, sizeof(info->serial_number), "%lu", + edid.vendor.serial); + info->product_id = edid.vendor.prod_id; + info->width = edid.display.h_size; + info->height = edid.display.v_size; + uint32 found = 0; - for (uint32 i = 0; i < EDID1_NUM_DETAILED_MONITOR_DESC; ++i) { - edid1_detailed_monitor *monitor = &info.detailed_monitor[i]; + edid1_detailed_monitor *monitor = &edid.detailed_monitor[i]; switch (monitor->monitor_desc_type) { case EDID1_SERIAL_NUMBER: - serial.SetTo(monitor->data.serial_number); + strlcpy(info->serial_number, monitor->data.serial_number, + sizeof(info->serial_number)); found++; break; case EDID1_MONITOR_NAME: - name.SetTo(monitor->data.monitor_name); + strlcpy(info->name, monitor->data.monitor_name, + sizeof(info->name)); found++; break; + case EDID1_MONITOR_RANGES: + { + edid1_monitor_range& range = monitor->data.monitor_range; + + info->min_horizontal_frequency = range.min_h; + info->max_horizontal_frequency = range.max_h; + info->min_vertical_frequency = range.min_v; + info->max_vertical_frequency = range.max_v; + info->max_pixel_clock = range.max_clock * 10000; + break; + } + + case EDID1_IS_DETAILED_TIMING: + { + edid1_detailed_timing& timing = monitor->data.detailed_timing; + info->width = timing.h_size / 10.0; + info->height = timing.v_size / 10.0; + } + default: break; } Modified: haiku/trunk/src/servers/app/drawing/AccelerantHWInterface.h =================================================================== --- haiku/trunk/src/servers/app/drawing/AccelerantHWInterface.h 2007-10-15 00:42:57 UTC (rev 22562) +++ haiku/trunk/src/servers/app/drawing/AccelerantHWInterface.h 2007-10-15 11:41:47 UTC (rev 22563) @@ -42,7 +42,7 @@ const display_mode *low, const display_mode *high); virtual status_t GetPreferredMode(display_mode* mode); - virtual status_t GetMonitorInfo(BString& name, BString& serial); + virtual status_t GetMonitorInfo(monitor_info* info); virtual sem_id RetraceSemaphore(); virtual status_t WaitForRetrace(bigtime_t timeout = B_INFINITE_TIMEOUT); @@ -131,6 +131,7 @@ get_timing_constraints fAccGetTimingConstraints; propose_display_mode fAccProposeDisplayMode; get_preferred_display_mode fAccGetPreferredDisplayMode; + get_monitor_info fAccGetMonitorInfo; get_edid_info fAccGetEDIDInfo; fill_rectangle fAccFillRect; invert_rectangle fAccInvertRect; Modified: haiku/trunk/src/servers/app/drawing/HWInterface.cpp =================================================================== --- haiku/trunk/src/servers/app/drawing/HWInterface.cpp 2007-10-15 00:42:57 UTC (rev 22562) +++ haiku/trunk/src/servers/app/drawing/HWInterface.cpp 2007-10-15 11:41:47 UTC (rev 22563) @@ -97,7 +97,7 @@ status_t -HWInterface::GetMonitorInfo(BString& name, BString& serial) +HWInterface::GetMonitorInfo(monitor_info* info) { return B_NOT_SUPPORTED; } Modified: haiku/trunk/src/servers/app/drawing/HWInterface.h =================================================================== --- haiku/trunk/src/servers/app/drawing/HWInterface.h 2007-10-15 00:42:57 UTC (rev 22562) +++ haiku/trunk/src/servers/app/drawing/HWInterface.h 2007-10-15 11:41:47 UTC (rev 22563) @@ -78,7 +78,7 @@ const display_mode *low, const display_mode *high) = 0; virtual status_t GetPreferredMode(display_mode* mode); - virtual status_t GetMonitorInfo(BString& name, BString& serial); + virtual status_t GetMonitorInfo(monitor_info* info); virtual sem_id RetraceSemaphore() = 0; virtual status_t WaitForRetrace(bigtime_t timeout = B_INFINITE_TIMEOUT) = 0; From nielx at mail.berlios.de Mon Oct 15 13:49:57 2007 From: nielx at mail.berlios.de (nielx at BerliOS) Date: Mon, 15 Oct 2007 13:49:57 +0200 Subject: [Haiku-commits] r22564 - haiku/trunk/docs/user/app Message-ID: <200710151149.l9FBnviG029142@sheep.berlios.de> Author: nielx Date: 2007-10-15 13:49:54 +0200 (Mon, 15 Oct 2007) New Revision: 22564 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22564&view=rev Added: haiku/trunk/docs/user/app/Message.dox Modified: haiku/trunk/docs/user/app/MessageFilter.dox Log: Phase I of the Message.dox file Added: haiku/trunk/docs/user/app/Message.dox =================================================================== --- haiku/trunk/docs/user/app/Message.dox 2007-10-15 11:41:47 UTC (rev 22563) +++ haiku/trunk/docs/user/app/Message.dox 2007-10-15 11:49:54 UTC (rev 22564) @@ -0,0 +1,2190 @@ +/* + * Copyright 2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Niels Sascha Reedijk, niels.reedijk at gmail.com + * + * Corresponds to: + * /trunk/headers/os/app/Message.h rev 21562 + * /trunk/src/kits/app/Message.cpp rev 22240 + */ + + +/*! + \file Message.h + \brief Provides the BMessage class. +*/ + +///// Name lengths and Scripting specifiers ///// + +/*! + \def B_FIELD_NAME_LENGTH + \brief Undocumented... +*/ + + +/*! + \def B_PROPERTY_NAME_LENGTH + \brief Undocumented... +*/ + + +/*! + \var B_NO_SPECIFIER + \brief Undocumented... +*/ + + +/*! + \var B_DIRECT_SPECIFIER + \brief Undocumented... +*/ + + +/*! + \var B_INDEX_SPECIFIER + \brief Undocumented... +*/ + + +/*! + \var B_REVERSE_INDEX_SPECIFIER, + \brief Undocumented... +*/ + + +/*! + \var B_RANGE_SPECIFIER + \brief Undocumented... +*/ + + +/*! + \var B_REVERSE_RANGE_SPECIFIER + \brief Undocumented... +*/ + + +/*! + \var B_NAME_SPECIFIER + \brief Undocumented... +*/ + + +/*! + \var B_ID_SPECIFIER + \brief Undocumented... +*/ + + +/*! + \var B_SPECIFIERS_END + \brief Undocumented... +*/ + + +///// Class BMessage ///// + + +/*! + \class BMessage + \ingroup app + \brief A container that can be send and received using the Haiku messaging + subsystem. + + This class is at the center of the web of messaging classes, in the sense + that it defines the actual structure of the messages. Messages have two + important elements: the #what identifer, and the data members. The first + can be directly manipulated, the latter can be manipulated through + AddData(), FindData() and ReplaceData() and their deratives. Neither of + these elements are mandatory. + + The second important role of BMessage is that it stores meta data: who sent + the message and with what intention? The methods of BMessage will disclose + if the message was a reply (IsReply()), where it came from + (IsSourceRemote()), whether a reply is expected (IsSourceWaiting()), and in + case the message is a reply, what it's a reply to (Previous()). + + All methods can be classified in these areas: + - Adding, Finding, Replacing and Removing Data. + - Statistics and Miscelanous information. + - Delivery information. + - Utilities to reply to messages. + + To see how messages fit in with the greater picture, have a look at the + \ref app_messaging "Messaging Introduction". +*/ + + +/*! + \var BMessage::what + \brief A 4-byte constant that determines the type of message. + + You can directly manipulate this data member. +*/ + + +/*! + \fn BMessage::BMessage() + \brief Construct an empty message, without any data members and with a + \c what constant set to zero (0). + + \see BMessage(uint32 what) + \see BMessage(const BMessage &other) +*/ + + +/*! + \fn BMessage::BMessage(uint32 what) + \brief Construct an empty message with the \c what member set tot the + specified value. + + \see BMessage::BMessage() + \see BMessage::BMessage(const BMessage &other) +*/ + + +/*! + \fn BMessage::BMessage(const BMessage &other) + \brief Construct a new message that is a copy of another message. + + The \c what member and the data values are copied. The metadata, such as + whether or not the message is a drop message or reply information, is + not copied. So if the original message is a reply to a previous message, + which will make IsReply() return \c true, calling the same method on a copy + of the message will return \c false. + + \remarks BeOS R5 did keep the metadata of the message. Haiku deviates from + this behaviour. Please use the Haiku implementation of message copying as + the default behavior. This will keep your applications backwards + compatible. + + \see BMessage::BMessage() + \see BMessage(uint32 what) +*/ + + +/*! + \fn BMessage::~BMessage() + \brief Free the data members associated with the message. + + If there still is a sender waiting for a reply, the \c B_NO_REPLY message + will be sent to inform them that there won't be a reply. +*/ + + +/*! + \fn BMessage &BMessage::operator=(const BMessage &other) + \brief Copy one message into another. + + See the copy constructor, BMessage(const BMessage &other), for details on what is + copied, and what isn't. +*/ + + +/*! + \name Statistics and Miscelanous Information +*/ + + +//! @{ + + +/*! + \fn status_t BMessage::GetInfo(type_code typeRequested, int32 index, + char **nameFound, type_code *typeFound, int32 *countFound) const + \brief Retrieve the name, the type and the number of items in a message by + an \a index. + + \param[in] typeRequested If you want to limit the search to only one type, + pass that type code here. If you don't care which type the data has, + you can pass \c B_ANY_TYPE. + \param[in] index The index of the data you want to investigate. + \param[out] nameFound The name of the item if it is found. Haiku will fill + in a pointer to the internal name buffer in the message. This means + that you should not manipulate this name. If you are not interested in + the name, you can safely pass \c NULL. + \param[out] typeFound The type of the item at \a index. If you are not + interested in the type (because you specifically asked for a type), you + can safely pass NULL. + \param[out] countFound The number of items at \a index. If data items have + the same name, they will be placed under the same index. + + \return If the \a index is found, and matches the requested type, the + other parameters will be filled in. If this is not the case, the method + will return with an error. + + \retval B_OK An match was found. The values have been filled in. + \retval B_BAD_INDEX The \a index was out of range. None of the passed + variables have been altered. + \retval B_BAD_TYPE The data field at \a index does not have the requested + type. +*/ + + +/*! + \fn status_t BMessage::GetInfo(const char *name, type_code *typeFound, + int32 *countFound) const + \brief Retrieve the type and the number of data items in this message that + are associated with a \a name. + + \param[in] name The name of the data member that you are looking for. + \param[out] typeFound In case of a match, the name of the data member will + be put in this parameter. In case you are not interested, you can pass + \c NULL. + \param[out] countFound In case of a match, the number of items at this + label will be in this parameter. In case you are not interested, you + can safely pass \c NULL. + + \return If the message has data associated with the given \a name, the + other parameters will contain information associated with the data. + Else, the method will return with an error. + + \retval B_OK A match was found. The other parameters have been filled in. + \retval B_BAD_VALUE You passed \c NULL as argument to \a name. + \retval B_NAME_NOT_FOUND There is no data with the label \a name. +*/ + + +/*! + \fn status_t BMessage::GetInfo(const char *name, type_code *typeFound, + bool *fixedSize) const + \brief Retrieve the type and whether or not the size of the data is fixed + associated with a \a name. + + This method is the same as GetInfo(const char *,type_code *, int32 *) const , with the difference that you can find out whether or + not the size of the data associated with the \a name is fixed. You will + get this value in the variable you passed as \a fixedSize parameter. +*/ + + +/*! + \fn int32 BMessage::CountNames(type_code type) const + \brief Count the number of names of a certain \a type. + + This method can be used to count the number of items of a certain type. + It's practical use is limited to debugging purposes. + + \param type The type you want to find. If you pass \c B_ANY_TYPE, this + method will return the total number of data items. + + \return The number of data items in this message with the specified + \a type, or zero in case no items match the type. +*/ + + +/*! + \fn bool BMessage::IsEmpty() const + \brief Check if the message has data members. + + \return If this message contains data members, this method will return + \c true, else it will return \c false. + \see MakeEmpty() +*/ + + +/*! + \fn bool BMessage::IsSystem() const + \brief Check if the message is a system message. + + \return If this message is a system message, the method will return + \c true. +*/ + + +/*! + \fn bool BMessage::IsReply() const + \brief Check if the message is a reply to a (previous) message. + + \return If this message is a reply, this method will return \c true. +*/ + + +/*! + \fn void BMessage::PrintToStream() const + \brief Print the message to the standard output. + + This method can be used to debug your application. It can be used to check + if it creates the messages properly, by checking if all the required fields + are present, and it can be used to debug your message handling routines, + especially the handling of those that are sent by external applications, to + see if you understand the semantics correctly. +*/ + + +/*! + \fn status_t BMessage::Rename(const char *oldEntry, const char *newEntry) + \brief Rename a data label. + + \param oldEntry The name of the label you want to rename. + \param newEntry The new name of the data entry. + + \retval B_OK Renaming succeeded. + \retval B_BAD_VALUE Either the \a oldEntry or the \a newEntry pointers are + \c NULL. + \retval B_NAME_NOT_FOUND There is no data associated with the label + \a oldEntry. +*/ + + +//! @} + +/*! + \name Delivery Info +*/ + +//! @{ + + +/*! + \fn bool BMessage::WasDelivered() const + \brief Check if this message was delivered through the delivery methods. + + If this message is passed via a BMessenger or BLooper::PostMessage(), this + method will return \c true. + + \warning This method should not be abused by a thread that sends a message + to track whether or not a message was delivered. This is because the + ownership of the message goes to the receiving looper, which will + delete the message as soon as it is done with it. + + \warning If you need to check whether a message is delivered, you should + either ask for a reply, or use one of the synchronous + BMessenger::SendMessage() methods. +*/ + + +/*! + \fn bool BMessage::IsSourceWaiting() const + \brief Check if the sender expects a reply. + + This method will return \c true, if the sender flagged that it is waiting + for a reply, and such a reply has not yet been sent. +*/ + + +/*! + \fn bool BMessage::IsSourceRemote() const + \brief Check if the message is sent by another application. +*/ + + +/*! + \fn BMessenger BMessage::ReturnAddress() const + \brief Get a messenger that points to the sender of the message. + + Using this method, you can fetch a BMessenger that can be used to deliver + replies to this message. This method works both for local and remote + deliveries. + + For remote deliveries, this approach is preferred over sending the reply + using a standard BMessenger that is created with the signature of the + application. A standard BMessenger sends the messages to the main BLooper + of the application, the BApplication object. With the delivery data stored + in the messages, the reply using this messenger will be directed at a + specific looper that is able to handle the replies. + + If this method is called on a message that has not been delivered (yet), + it will return an empty BMessenger object. +*/ + + +/*! + \fn const BMessage *BMessage::Previous() const + \brief Get the message to which this message is a reply. + + \return Returns a new BMessage with the same data stuctures as the message + to which this message is a reply. You get the ownership of this + message, so free it when you're done. If this message isn't a reply to + another message, this method will return \c NULL. +*/ + + +/*! + \fn bool BMessage::WasDropped() const + \brief Check if the message was delivered through 'drag and drop'. + + \return This method returns \c true if the message has been delivered + through drag and drop. It returns \c false if it has been delivered + through the regular messaging functions, or if the message has not + been delivered at all. + \see DropPoint() +*/ + + +/*! + \fn BPoint BMessage::DropPoint(BPoint *offset) const + \brief Get the coordinates of the drop point of the message. + + If the message has been delivered because of drag and drop, which can be + verified with the WasDropped() method, this method will return a BPoint to + where exactly the drop off was made. + + Because drop messages are delivered to the BWindow in which they were + dropped, and BWindow is a subclass of BLooper, you can use BWindow to + determine based on the location, how you should react to it. + + If this message was not delivered through drag and drop, it will return + a \c NULL pointer. + + \see WasDropped() +*/ + + +//! @} + + +/*! + \name Replying +*/ + + +//! @{ + + +/*! + \fn status_t BMessage::SendReply(uint32 command, BHandler *replyTo) + \brief Asynchronously send a reply to this message. + + This is an overloaded member of SendReply(BMessage *, BMessenger, bigtime_t). + Use this variant if you want to send a message without data members. +*/ + + +/*! + \fn status_t BMessage::SendReply(BMessage *reply, BHandler *replyTo, + bigtime_t timeout) + \brief Asynchronously send a reply to this message. + + This is an overloaded member of SendReply(BMessage *, BMessenger, bigtime_t). + Use this variant if you want to send the message to a specific handler + (instead of a complete messenger). +*/ + + +/*! + \fn status_t BMessage::SendReply(BMessage *reply, BMessenger replyTo, + bigtime_t timeout) + \brief Asynchronously send a reply to this message. + + This method sends a reply to this message to the sender. On your turn, + you specify a messenger that handles a reply back to the message you + specify as the \a reply argument. You can set a timeout for the message + to be delivered. This method blocks until the message has been received, + or the \a timeout has been reached. + + \param reply The message that is in reply to this message. + \param replyTo In case the receiver needs to reply to the message you are + sending, you can specify the return address with this argument. + \param timeout The maximum time in microseconds this delivery may take. The + \a timeout is a relative timeout. You can also use + \c B_INFINITE_TIMEOUT if you want to wait infinitely for the message + to be delivered. + + \retval B_OK The message has been delivered. + \retval B_DUPLICATE_REPLY There already has been a reply to this message. + \retval B_BAD_PORT_ID The reply address is not valid (anymore). + \retval B_WOULD_BLOCK The delivery \a timeout was \c B_INFINITE_TIMEOUT + (zero) and the target port was full when trying to deliver the message. + \retval B_TIMED_OUT The timeout expired while trying to deliver the + message. + \see SendReply(uint32 command, BHandler *replyTo) +*/ + + +/*! + \fn status_t BMessage::SendReply(uint32 command, BMessage *replyToReply) + \brief Synchronously send a reply to this message, and wait for a reply + back. + + This is an overloaded member of SendReply(BMessage *, BMessage *, + bigtime_t, bigtime_t) Use this variant if you want to send a message + without data members. +*/ + + +/*! + \fn status_t BMessage::SendReply(BMessage *reply, BMessage *replyToReply, + bigtime_t sendTimeout, bigtime_t replyTimeout) + \brief Synchronously send a reply to this message, and wait for a reply + back. + + This method sends a reply to this message to the sender. The \a reply is + delivered, and then the method waits for a reply from the receiver. If a + reply is received, that reply is copied into the \a replyToReply argument. + If the message was delivered properly, but the receiver did not reply + within the specified \a replyTimeout, the \c what member of \a replyToReply + will be set to \c B_NO_REPLY. + + \param reply The message that is in reply to this message. + \param[out] replyToReply The reply is copied into this argument. + \param sendTimeout The maximum time in microseconds this delivery may take. + The \a timeout is a relative timeout. You can also use + \c B_INFINITE_TIMEOUT if you want to wait infinitely for the message + to be delivered. + \param replyTimeout The maximum time in microseconds you want to wait for a + reply. Note that the timer starts when the message has been delivered. + + \retval B_OK The message has been delivered. + \retval B_DUPLICATE_REPLY There already has been a reply to this message. + \retval B_BAD_VALUE Either \a reply or \a replyToReply is \c NULL. + \retval B_BAD_PORT_ID The reply address is not valid (anymore). + \retval B_WOULD_BLOCK The delivery \a timeout was \c B_INFINITE_TIMEOUT + (zero) and the target port was full when trying to deliver the message. + \retval B_TIMED_OUT The timeout expired while trying to deliver the + message. + \retval B_NO_MORE_PORTS All reply ports are in use. + \see SendReply(uint32 command, BMessage *replyToReply) +*/ + + +//! @} + + +/*! + \name Flattening methods + + Because of historical reasons and for binary compatibility, this class + provides a flattening API without inheriting the BFlattenable class. The + API is more or less the same, but you are inconvenienced when you want to + use messages in methods that handle BFlattenable objects. +*/ + + +//! @{ + + +/*! + \fn ssize_t BMessage::FlattenedSize() const + \brief Return the size in bytes required when you want to flatten this + message to a stream of bytes. +*/ + + +/*! + \fn status_t BMessage::Flatten(char *buffer, ssize_t size) const + \brief Flatten the message to a \a buffer. + + \param buffer The buffer to write the data to. + \param size The size of the buffer. + + \return \c B_OK in case of success, or an error code in case something went + awry. + + \warning Make sure the buffer is large enough to hold the message. This + method does not double-check for you! + \see FlattenedSize() + \see Flatten(BDataIO *stream, ssize_t *size) const +*/ + + +/*! + \fn status_t BMessage::Flatten(BDataIO *stream, ssize_t *size) const + \brief Flatten the message to a \a stream. + + \param[in] stream The stream to flatten the message to. + \param[out] size The method writes the number of bytes actually written to + this argument. + \return \c B_OK in case of success, or an error code in case something went + awry. + + \warning Make sure the subclass of the BDataIO interface either protects + against buffer overwrites, or check if the number of bytes that is + going to be written isn't larger than it can handle. + \see FlattenedSize() + \see Flatten(char *buffer, ssize_t size) const +*/ + + +/*! + \fn status_t BMessage::Unflatten(const char *flatBuffer) + \brief Unflatten a message from a buffer and put it into the current + object. + + This action clears the current contents of the message. + + \param flatBuffer The buffer that contains the message. + + \retval B_OK The buffer has been unflattened. + \retval B_BAD_VALUE The buffer does not contain a valid message. + \retval B_NO_MEMORY An error occured whilst allocating memory for the data + members. + \see Flatten(char *buffer, ssize_t size) const + \see Unflatten(BDataIO *stream) +*/ + + +/*! + \fn status_t BMessage::Unflatten(BDataIO *stream) + \brief Unflatten a message from a stream and put it into the current + object. + + This action clears the current contents of the message. + + \param stream The stream that contains the message. + + \retval B_OK The message has been unflattened. + \retval B_BAD_VALUE The stream does not contain a valid message. + \retval B_NO_MEMORY An error occured whilst allocating memory for the data + members. + \see Flatten(BDataIO *stream, ssize_t *size) const + \see Unflatten(const char *flatBuffer) +*/ + + +//! @} + +/*! + \name Specifiers (Scripting) +*/ + +//! @{ + + +/*! + \fn status_t BMessage::AddSpecifier(const char *property) + \brief Undocumented. +*/ + + +/*! + \fn status_t BMessage::AddSpecifier(const char *property, int32 index) + \brief Undocumented. +*/ + + +/*! + \fn status_t BMessage::AddSpecifier(const char *property, int32 index, + int32 range) + \brief Undocumented. +*/ + + +/*! + \fn status_t BMessage::AddSpecifier(const char *property, const char *name) + \brief Undocumented. +*/ + + +/*! + \fn status_t BMessage::AddSpecifier(const BMessage *specifier) + \brief Undocumented. +*/ + + +/*! + \fn status_t BMessage::SetCurrentSpecifier(int32 index) + \brief Undocumented. +*/ + + +/*! + \fn status_t BMessage::GetCurrentSpecifier(int32 *index, + BMessage *specifier, int32 *what, const char **property) const + \brief Undocumented. +*/ + + +/*! + \fn bool BMessage::HasSpecifiers() const + \brief Undocumented. +*/ + + +/*! + \fn status_t BMessage::PopSpecifier() + \brief Undocumented. +*/ + + +//! @} + + +/*! + \name Adding Data +*/ + + +//! @{ + + +/*! + \fn status_t BMessage::AddData(const char *name, type_code type, + const void *data, ssize_t numBytes, bool isFixedSize, int32 count) + \brief Add \a data of a certain \a type to the message. + + The amount of \a numBytes is copied into the message. The data is stored + at the label specified in \a name. You are responsible for specifying the + correct \a type. The Haiku API already specifies many constants, such as + B_FLOAT_TYPE or B_RECT_TYPE. See TypeConstants.h for more information on + the system-wide defined types. + + If the field with the \a name already exists, the data is added in an + array-like form. If you are adding a certain \a name for the first time, + you are able to specify some properties of this array. You can fix the size + of each data entry, and you can also instruct BMessage to allocate a + \a count of items. The latter does not mean that the number of items is + fixed; the array will grow nonetheless. Also, note that every \a name can + only be associated with one \a type of data. If consecutive method calls + specify a different \a type than the initial, these calls will fail. + + There is no limit to the number of labels, or the amount of data, but + note that searching of data members is linear, as well as that some + messages will be copied whilst being passed around, so if the amount of + data you need to pass is too big, find another way to pass it. + + \param name The label to which this data needs to be associated. If the + \a name already exists, the new data will be added in an array-like + style. + \param type The type of data. If you are adding data to the same \a name, + make sure it is the same type. + \param data The data buffer to copy the bytes from. + \param numBytes The number of bytes to be copied. If this is the first call + to this method for this type of data, and you set \a isFixedSize to + \c true, this will specify the size of all consecutive calls to this + method. + \param isFixedSize If this is the first call to this method with this + \a name, you can specify the whether or not all items in this array + should have the same fixed size. + \param count If this is the first call to this method with this + \a name, you can instruct this message to allocate a number of items in + advance. This does not limit the amount of items though. The array will + grow if needed. + + \retval B_OK The \a data is succesfully added. + \retval B_BAD_VALUE The \a numBytes is less than, or equal to zero (0), or + the size of this item is larger than the \a name allows, since it has + been specified to have a fixed size. + \retval B_ERROR There was an error whilst creating the label with your + \a name. + \retval B_BAD_TYPE The \a type you specified is different than the one + already associated with \a name. +*/ + + +/*! + \fn status_t BMessage::AddRect(const char *name, BRect aRect) + \brief Convenience method to add a BRect to the label \a name. + + This method calls AddData() with the \c B_RECT_TYPE \a type. + + \param name The label to associate the data with. + \param aRect The rectangle to store in the message. + \see AddData() for a more detailed overview of the inner workings. + \see FindRect() + \see ReplaceRect() +*/ + + +/*! + \fn status_t BMessage::AddPoint(const char *name, BPoint aPoint) + \brief Convenience method to add a BPoint to the label \a name. + + This method calls AddData() with the \c B_POINT_TYPE \a type. + + \param name The label to associate the data with. + \param aPoint The point to store in the message. + \see AddData() for a more detailed overview of the inner workings. + \see FindPoint() + \see ReplacePoint() +*/ + + +/*! + \fn status_t BMessage::AddString(const char *name, const char *aString) + \brief Convenience method to add a C-string to the label \a name. + + This method calls AddData() with the \c B_STRING_TYPE \a type. + + \param name The label to associate the data with. + \param aString The string to copy to the message. + \see AddData() for a more detailed overview of the inner workings. + \see FindString() + \see ReplaceString() +*/ + + +/*! + \fn status_t BMessage::AddString(const char *name, const BString &aString) + \brief Convenience method to add a BString to the label \a name. + + This method calls AddData() with the \c B_STRING_TYPE \a type. + + \param name The label to associate the data with. + \param aString The string to copy to the message. + \see AddData() for a more detailed overview of the inner workings. + \see FindString() + \see ReplaceString() +*/ + + +/*! + \fn status_t BMessage::AddInt8(const char *name, int8 value) + \brief Convenience method to add an \c int8 to the label \a name. + + This method calls AddData() with the \c B_INT8_TYPE \a type. + + \param name The label to associate the data with. + \param value The value to store in the message. + \see AddData() for a more detailed overview of the inner workings. + \see FindInt8() + \see ReplaceInt8() +*/ + + +/*! + \fn status_t BMessage::AddInt16(const char *name, int16 value) + \brief Convenience method to add an \c int16 to the label \a name. + + This method calls AddData() with the \c B_INT16_TYPE \a type. + + \param name The label to associate the data with. + \param value The value to store in the message. + \see AddData() for a more detailed overview of the inner workings. + \see FindInt16() + \see ReplaceInt16() +*/ + + +/*! + \fn status_t BMessage::AddInt32(const char *name, int32 value) + \brief Convenience method to add an \c int32 to the label \a name. + + This method calls AddData() with the \c B_INT32_TYPE \a type. + + \param name The label to associate the data with. + \param value The value to store in the message. + \see AddData() for a more detailed overview of the inner workings. + \see FindInt32() + \see ReplaceInt32() +*/ + + +/*! + \fn status_t BMessage::AddInt64(const char *name, int64 value) + \brief Convenience method to add an \c int64 to the label \a name. + + This method calls AddData() with the \c B_INT64_TYPE \a type. + + \param name The label to associate the data with. + \param value The value to store in the message. + \see AddData() for a more detailed overview of the inner workings. + \see FindInt64() + \see ReplaceInt64() +*/ + + +/*! + \fn status_t BMessage::AddBool(const char *name, bool aBoolean) + \brief Convenience method to add a \c bool to the label \a name. + + This method calls AddData() with the \c B_BOOL_TYPE \a type. + + \param name The label to associate the data with. + \param aBoolean The value to store in the message. + \see AddData() for a more detailed overview of the inner workings. + \see FindBool() + \see ReplaceBool() +*/ + +/*! + \fn status_t BMessage::AddFloat(const char *name, float aFloat) + \brief Convenience method to add a \c float to the label \a name. + + This method calls AddData() with the \c B_FLOAT_TYPE \a type. + + \param name The label to associate the data with. + \param aFloat The value to store in the message. + \see AddData() for a more detailed overview of the inner workings. + \see FindFloat() + \see ReplaceFloat() +*/ + + +/*! + \fn status_t BMessage::AddDouble(const char *name, double aDouble) + \brief Convenience method to add a \c double to the label \a name. + + This method calls AddData() with the \c B_DOUBLE_TYPE \a type. + + \param name The label to associate the data with. + \param aDouble The value to store in the message. + \see AddData() for a more detailed overview of the inner workings. + \see FindDouble() + \see ReplaceDouble() +*/ + + +/*! + \fn status_t BMessage::AddPointer(const char *name, const void *aPointer) + \brief Convenience method to add a \c pointer to the label \a name. + + This method calls AddData() with the \c B_POINTER_TYPE \a type. + + \warning If you want to share objects between applications, please remember + that each application has its own address space, and that it therefore + is useless to try to pass around objects by sending pointers in + messages. You should think about copying the entire object in the + message, or you should consider using shared memory. + + \param name The label to associate the data with. + \param aPointer The value to store in the message. + \see AddData() for a more detailed overview of the inner workings. + \see FindPointer() + \see ReplacePointer() +*/ + + +/*! + \fn status_t BMessage::AddMessenger(const char *name, BMessenger messenger) + \brief Convenience method to add a messenger to the label \a name. + + This method calls AddData() with the \c B_MESSENGER_TYPE \a type. + + \param name The label to associate the data with. + \param messenger The messenger to store in the message. + \see AddData() for a more detailed overview of the inner workings. + \see FindMessenger() + \see ReplaceMessenger() +*/ + + +/*! + \fn status_t BMessage::AddRef(const char *name, const entry_ref *ref) + \brief Convenience method to add an \c entry_ref to the label \a name. + + This method calls AddData() with the \c B_REF_TYPE \a type. + + \param name The label to associate the data with. + \param ref The reference to store in the message. + \see AddData() for a more detailed overview of the inner workings. + \see FindRef() + \see ReplaceRef() +*/ + + +/*! + \fn status_t BMessage::AddMessage(const char *name, const BMessage *message) + \brief Convenience method to add a message to the label \a name. + + This method calls AddData() with the \c B_MESSAGE_TYPE \a type. + + \param name The label to associate the data with. + \param message The message to store in this message. + \see AddData() for a more detailed overview of the inner workings. + \see FindMessage() + \see ReplaceMessage() +*/ + + +/*! + \fn status_t BMessage::AddFlat(const char *name, BFlattenable *object, + int32 count = 1) + \brief Convenience method to add a flattenable to the label \a name. + + This method uses BFlattenable::TypeCode() to determine the type. It also + uses BFlattenable::IsFixedSize() to determine whether or not the size of + the object is supposedly always the same. You can specify a \a count, to + pre-allocate more entries if you are going to add more than one of this + type. + + \param name The label to associate the data with. + \param object The object to flatten into the message. + \param count The number of items to pre-allocate associated with this + \a name. [... truncated: 1209 lines follow ...] From axeld at mail.berlios.de Mon Oct 15 13:57:28 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 15 Oct 2007 13:57:28 +0200 Subject: [Haiku-commits] r22565 - haiku/trunk/src/system/libroot/posix/unistd Message-ID: <200710151157.l9FBvSVW029783@sheep.berlios.de> Author: axeld Date: 2007-10-15 13:57:28 +0200 (Mon, 15 Oct 2007) New Revision: 22565 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22565&view=rev Modified: haiku/trunk/src/system/libroot/posix/unistd/conf.c Log: * Fixed warning. * Use strlcpy() to copy the confstr instead of strncpy(). Modified: haiku/trunk/src/system/libroot/posix/unistd/conf.c =================================================================== --- haiku/trunk/src/system/libroot/posix/unistd/conf.c 2007-10-15 11:49:54 UTC (rev 22564) +++ haiku/trunk/src/system/libroot/posix/unistd/conf.c 2007-10-15 11:57:28 UTC (rev 22565) @@ -1,16 +1,21 @@ -/* -** Copyright 2002-2004, Axel D?rfler, axeld at pinc-software.de. All rights reserved. -** Distributed under the terms of the Haiku License. -*/ +/* + * Copyright 2002-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ #include + +#include +#include +#include +#include #include -#include -#include +#include -int + +int getdtablesize(void) { struct rlimit rlimit; @@ -21,10 +26,10 @@ } -long +long sysconf(int name) { - // This is about what BeOS does, better POSIX conformance would be nice, though + // TODO: This is about what BeOS does, better POSIX conformance would be nice, though switch (name) { case _SC_ARG_MAX: @@ -53,7 +58,7 @@ } -long +long fpathconf(int fd, int name) { switch (name) { @@ -94,20 +99,19 @@ } -long +long pathconf(const char *path, int name) { return fpathconf(-1, name); } -#define min_c(a,b) ((a)>(b)?(b):(a)) - -size_t -confstr(int name, char *buf, size_t len) +size_t +confstr(int name, char *buffer, size_t length) { - size_t string_len = 1; + size_t stringLength = 1; char *string = ""; + switch (name) { case 0: break; @@ -115,8 +119,10 @@ errno = EINVAL; return 0; } - if (buf != NULL) - strncpy(buf, string, min_c(len, string_len)); - return string_len; + + if (buffer != NULL) + strlcpy(buffer, string, min_c(length, stringLength)); + + return stringLength; } From axeld at mail.berlios.de Mon Oct 15 14:26:27 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 15 Oct 2007 14:26:27 +0200 Subject: [Haiku-commits] r22566 - haiku/trunk/src/add-ons/kernel/file_systems/fat Message-ID: <200710151226.l9FCQRC9000516@sheep.berlios.de> Author: axeld Date: 2007-10-15 14:26:27 +0200 (Mon, 15 Oct 2007) New Revision: 22566 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22566&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/fat/file.c haiku/trunk/src/add-ons/kernel/file_systems/fat/file.h haiku/trunk/src/add-ons/kernel/file_systems/fat/rtc_info.h Log: Fixed warnings. Modified: haiku/trunk/src/add-ons/kernel/file_systems/fat/file.c =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/fat/file.c 2007-10-15 11:57:28 UTC (rev 22565) +++ haiku/trunk/src/add-ons/kernel/file_systems/fat/file.c 2007-10-15 12:26:27 UTC (rev 22566) @@ -1479,12 +1479,13 @@ status_t dosfs_read_pages(fs_volume _fs, fs_vnode _node, fs_cookie _cookie, off_t pos, - const iovec *vecs, size_t count, size_t *_numBytes, bool reenter) + const iovec *vecs, size_t count, size_t *_numBytes, bool mayBlock, + bool reenter) { - nspace *vol = (nspace *)_fs; - vnode *node = (vnode *)_node; + nspace *vol = (nspace *)_fs; + vnode *node = (vnode *)_node; status_t status; - + if (check_nspace_magic(vol, "dosfs_read_pages") || check_vnode_magic(node, "dosfs_read_pages")) return EINVAL; @@ -1492,6 +1493,7 @@ if (node->cache == NULL) return(B_BAD_VALUE); + // TODO: respect "mayBlock"! LOCK_VOL(vol); status = file_cache_read_pages(node->cache, pos, vecs, count, _numBytes); @@ -1503,10 +1505,11 @@ status_t dosfs_write_pages(fs_volume _fs, fs_vnode _node, fs_cookie _cookie, off_t pos, - const iovec *vecs, size_t count, size_t *_numBytes, bool reenter) + const iovec *vecs, size_t count, size_t *_numBytes, bool mayBlock, + bool reenter) { - nspace *vol = (nspace *)_fs; - vnode *node = (vnode *)_node; + nspace *vol = (nspace *)_fs; + vnode *node = (vnode *)_node; status_t status; if (check_nspace_magic(vol, "dosfs_write_pages") @@ -1516,6 +1519,7 @@ if (node->cache == NULL) return B_BAD_VALUE; + // TODO: respect "mayBlock"! LOCK_VOL(vol); status = file_cache_write_pages(node->cache, pos, vecs, count, _numBytes); Modified: haiku/trunk/src/add-ons/kernel/file_systems/fat/file.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/fat/file.h 2007-10-15 11:57:28 UTC (rev 22565) +++ haiku/trunk/src/add-ons/kernel/file_systems/fat/file.h 2007-10-15 12:26:27 UTC (rev 22566) @@ -31,8 +31,8 @@ struct file_io_vec *vecs, size_t *_count); bool dosfs_can_page(fs_volume _fs, fs_vnode _v, fs_cookie _cookie); status_t dosfs_read_pages(fs_volume _fs, fs_vnode _node, fs_cookie _cookie, off_t pos, - const iovec *vecs, size_t count, size_t *_numBytes, bool reenter); + const iovec *vecs, size_t count, size_t *_numBytes, bool mayBlock, bool reenter); status_t dosfs_write_pages(fs_volume _fs, fs_vnode _node, fs_cookie _cookie, off_t pos, - const iovec *vecs, size_t count, size_t *_numBytes, bool reenter); + const iovec *vecs, size_t count, size_t *_numBytes, bool mayBlock, bool reenter); #endif Modified: haiku/trunk/src/add-ons/kernel/file_systems/fat/rtc_info.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/fat/rtc_info.h 2007-10-15 11:57:28 UTC (rev 22565) +++ haiku/trunk/src/add-ons/kernel/file_systems/fat/rtc_info.h 2007-10-15 12:26:27 UTC (rev 22566) @@ -18,6 +18,6 @@ #define RTC_SETTINGS_FILE "RTC_time_settings" -extern _IMPEXP_KERNEL status_t get_rtc_info(rtc_info *); +extern status_t get_rtc_info(rtc_info *); #endif /* _RTC_INFO_H */ From axeld at mail.berlios.de Mon Oct 15 14:48:22 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 15 Oct 2007 14:48:22 +0200 Subject: [Haiku-commits] r22567 - in haiku/trunk/src/add-ons/kernel: bus_managers/agp bus_managers/ide bus_managers/ps2 generic/locked_pool Message-ID: <200710151248.l9FCmMFt003245@sheep.berlios.de> Author: axeld Date: 2007-10-15 14:48:22 +0200 (Mon, 15 Oct 2007) New Revision: 22567 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22567&view=rev Modified: haiku/trunk/src/add-ons/kernel/bus_managers/agp/module.cpp haiku/trunk/src/add-ons/kernel/bus_managers/ide/ide.c haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_module.c haiku/trunk/src/add-ons/kernel/generic/locked_pool/locked_pool.c Log: Minor cleanup. Modified: haiku/trunk/src/add-ons/kernel/bus_managers/agp/module.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/agp/module.cpp 2007-10-15 12:26:27 UTC (rev 22566) +++ haiku/trunk/src/add-ons/kernel/bus_managers/agp/module.cpp 2007-10-15 12:48:22 UTC (rev 22567) @@ -1,36 +1,32 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2003-2004, Niels S. Reedijk, -// Rudolf Cornelissen -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. +/* + * Copyright (c) 2003-2004, Niels S. Reedijk, + * Rudolf Cornelissen + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ - #include "agp.h" //void function for debug messages if logging disabled void silent(const char *, ... ) {} -/* ++++++++++ -Loading/unloading the module -++++++++++ */ - static int32 bus_std_ops(int32 op, ...) { @@ -38,9 +34,7 @@ case B_MODULE_INIT: TRACE("agp_man: bus module V0.02: init\n"); if (init() != B_OK) - { return ENODEV; - } break; case B_MODULE_UNINIT: TRACE("agp_man: bus module V0.02: uninit\n"); @@ -53,28 +47,20 @@ } -/* ++++++++++ -This module exports the AGP API -++++++++++ */ - -struct agp_module_info m_module_info = -{ - // First the bus_manager_info: +static struct agp_module_info sAGPModuleInfo = { { - //module_info { - B_AGP_MODULE_NAME , - B_KEEP_LOADED , // Keep loaded, even if no driver requires it + B_AGP_MODULE_NAME, + B_KEEP_LOADED, // Keep loaded, even if no driver requires it bus_std_ops - } , - NULL // the rescan function - } , - //my functions + }, + NULL // the rescan function + }, get_nth_agp_info, enable_agp }; -_EXPORT module_info *modules[] = { - (module_info *)&m_module_info , +module_info *modules[] = { + (module_info *)&sAGPModuleInfo, NULL }; Modified: haiku/trunk/src/add-ons/kernel/bus_managers/ide/ide.c =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/ide/ide.c 2007-10-15 12:26:27 UTC (rev 22566) +++ haiku/trunk/src/add-ons/kernel/bus_managers/ide/ide.c 2007-10-15 12:48:22 UTC (rev 22567) @@ -1,16 +1,10 @@ /* -** Copyright 2002/03, Thomas Kurschel. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ + * Copyright 2002/03, Thomas Kurschel. All rights reserved. + * Distributed under the terms of the MIT License. + */ -/* - Part of Open IDE bus manager +/*! Contains interface used by IDE controller driver. */ - Main file - - Contains interface used by IDE controller driver. -*/ - #include "ide_internal.h" #include "ide_sim.h" @@ -19,7 +13,6 @@ #if !_BUILDING_kernel && !BOOT -_EXPORT module_info *modules[] = { (module_info *)&ide_for_controller_module, (module_info *)&ide_sim_module, Modified: haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_module.c =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_module.c 2007-10-15 12:26:27 UTC (rev 22566) +++ haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_module.c 2007-10-15 12:48:22 UTC (rev 22567) @@ -1,5 +1,5 @@ /* - * Copyright 2005 Marcus Overhagen + * Copyright 2005-2007 Marcus Overhagen * Distributed under the terms of the MIT License. * * PS/2 bus manager @@ -8,17 +8,20 @@ * Marcus Overhagen (marcus at overhagen.de) */ + #include "PS2.h" #include "ps2_common.h" -static int32 function1() +static int32 +function1() { return 0; } -static int32 function2() +static int32 +function2() { return 0; } @@ -41,8 +44,7 @@ } -static ps2_module_info ps2_module = -{ +static ps2_module_info ps2_module = { .binfo = { .minfo = { .name = B_PS2_MODULE_NAME, @@ -56,8 +58,7 @@ }; -_EXPORT module_info *modules[] = -{ - (module_info *) &ps2_module, +module_info *modules[] = { + (module_info *)&ps2_module, NULL }; Modified: haiku/trunk/src/add-ons/kernel/generic/locked_pool/locked_pool.c =================================================================== --- haiku/trunk/src/add-ons/kernel/generic/locked_pool/locked_pool.c 2007-10-15 12:26:27 UTC (rev 22566) +++ haiku/trunk/src/add-ons/kernel/generic/locked_pool/locked_pool.c 2007-10-15 12:48:22 UTC (rev 22567) @@ -586,7 +586,6 @@ }; #if !_BUILDING_kernel && !BOOT -_EXPORT module_info *modules[] = { &interface.minfo, NULL From axeld at mail.berlios.de Mon Oct 15 16:09:14 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 15 Oct 2007 16:09:14 +0200 Subject: [Haiku-commits] r22568 - in haiku/trunk: headers/private/media src/kits/media Message-ID: <200710151409.l9FE9Eg6008580@sheep.berlios.de> Author: axeld Date: 2007-10-15 16:09:14 +0200 (Mon, 15 Oct 2007) New Revision: 22568 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22568&view=rev Modified: haiku/trunk/headers/private/media/DefaultMediaTheme.h haiku/trunk/src/kits/media/DefaultMediaTheme.cpp Log: Some cleanup. Modified: haiku/trunk/headers/private/media/DefaultMediaTheme.h =================================================================== --- haiku/trunk/headers/private/media/DefaultMediaTheme.h 2007-10-15 12:48:22 UTC (rev 22567) +++ haiku/trunk/headers/private/media/DefaultMediaTheme.h 2007-10-15 14:09:14 UTC (rev 22568) @@ -1,32 +1,34 @@ -/* -** Copyright 2003, Axel D?rfler, axeld at pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ +/* + * Copyright 2003-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef DEFAULT_MEDIA_THEME_H #define DEFAULT_MEDIA_THEME_H #include +class BParameterGroup; + namespace BPrivate { class DefaultMediaTheme : public BMediaTheme { public: DefaultMediaTheme(); - virtual BControl *MakeControlFor(BParameter *parameter); + virtual BControl* MakeControlFor(BParameter* parameter); - static BControl *MakeViewFor(BParameter *parameter, const BRect *hintRect = NULL); + static BControl* MakeViewFor(BParameter* parameter, const BRect* hintRect = NULL); // this is also called by the BMediaTheme::MakeFallbackViewFor() // method - that's why it's a static. protected: - virtual BView *MakeViewFor(BParameterWeb *web, const BRect *hintRect = NULL); + virtual BView* MakeViewFor(BParameterWeb* web, const BRect* hintRect = NULL); private: - BView *MakeViewFor(BParameterGroup &group, const BRect &hintRect); - BView *MakeSelfHostingViewFor(BParameter ¶meter, const BRect &hintRect); + BView* MakeViewFor(BParameterGroup& group, const BRect* hintRect); + BView* MakeSelfHostingViewFor(BParameter& parameter, const BRect* hintRect); }; } // namespace BPrivate Modified: haiku/trunk/src/kits/media/DefaultMediaTheme.cpp =================================================================== --- haiku/trunk/src/kits/media/DefaultMediaTheme.cpp 2007-10-15 12:48:22 UTC (rev 22567) +++ haiku/trunk/src/kits/media/DefaultMediaTheme.cpp 2007-10-15 14:09:14 UTC (rev 22568) @@ -1,7 +1,7 @@ -/* -** Copyright 2003-2004, Axel D?rfler, axeld at pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ +/* + * Copyright 2003-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ #include "DefaultMediaTheme.h" @@ -108,7 +108,8 @@ class ContinuousMessageFilter : public MessageFilter { public: - ContinuousMessageFilter(BControl *control, BContinuousParameter ¶meter); + ContinuousMessageFilter(BControl *control, + BContinuousParameter ¶meter); virtual ~ContinuousMessageFilter(); virtual filter_result Filter(BMessage *message, BHandler **target); @@ -254,7 +255,8 @@ if (vertical || fIsDocumentScroller) rect.right -= B_V_SCROLL_BAR_WIDTH; - fHorizontalScrollBar = new BScrollBar(rect, "horizontal", fTarget, 0, width, B_HORIZONTAL); + fHorizontalScrollBar = new BScrollBar(rect, "horizontal", fTarget, 0, + width, B_HORIZONTAL); fTarget->ResizeBy(0, -B_H_SCROLL_BAR_HEIGHT); AddChild(fHorizontalScrollBar); horizontalChanged = true; @@ -266,7 +268,8 @@ if (horizontal || fIsDocumentScroller) rect.bottom -= B_H_SCROLL_BAR_HEIGHT; - fVerticalScrollBar = new BScrollBar(rect, "vertical", fTarget, 0, height, B_VERTICAL); + fVerticalScrollBar = new BScrollBar(rect, "vertical", fTarget, 0, + height, B_VERTICAL); fTarget->ResizeBy(-B_V_SCROLL_BAR_WIDTH, 0); AddChild(fVerticalScrollBar); verticalChanged = true; @@ -274,10 +277,14 @@ // adapt the scroll bars, so that they don't overlap each other if (!fIsDocumentScroller) { - if (horizontalChanged && !verticalChanged && vertical) - fVerticalScrollBar->ResizeBy(0, (horizontal ? -1 : 1) * B_H_SCROLL_BAR_HEIGHT); - if (verticalChanged && !horizontalChanged && horizontal) - fHorizontalScrollBar->ResizeBy((vertical ? -1 : 1) * B_V_SCROLL_BAR_WIDTH, 0); + if (horizontalChanged && !verticalChanged && vertical) { + fVerticalScrollBar->ResizeBy(0, (horizontal ? -1 : 1) + * B_H_SCROLL_BAR_HEIGHT); + } + if (verticalChanged && !horizontalChanged && horizontal) { + fHorizontalScrollBar->ResizeBy((vertical ? -1 : 1) + * B_V_SCROLL_BAR_WIDTH, 0); + } } // update the scroll bar range & proportions @@ -481,7 +488,8 @@ font_height fontHeight; GetFontHeight(&fontHeight); - *_height = fontHeight.ascent + fontHeight.descent + fontHeight.leading + 8; + *_height = fontHeight.ascent + fontHeight.descent + fontHeight.leading + + 8; } } @@ -504,11 +512,13 @@ switch (parameter.Type()) { case BParameter::B_CONTINUOUS_PARAMETER: - return new ContinuousMessageFilter(control, static_cast(parameter)); + return new ContinuousMessageFilter(control, + static_cast(parameter)); case BParameter::B_DISCRETE_PARAMETER: - return new DiscreteMessageFilter(control, static_cast(parameter)); - + return new DiscreteMessageFilter(control, + static_cast(parameter)); + case BParameter::B_NULL_PARAMETER: /* fall through */ default: return NULL; @@ -519,7 +529,8 @@ // #pragma mark - -ContinuousMessageFilter::ContinuousMessageFilter(BControl *control, BContinuousParameter ¶meter) +ContinuousMessageFilter::ContinuousMessageFilter(BControl *control, + BContinuousParameter ¶meter) : MessageFilter(), fParameter(parameter) { @@ -589,7 +600,8 @@ // #pragma mark - -DiscreteMessageFilter::DiscreteMessageFilter(BControl *control, BDiscreteParameter ¶meter) +DiscreteMessageFilter::DiscreteMessageFilter(BControl *control, + BDiscreteParameter ¶meter) : MessageFilter(), fParameter(parameter) { @@ -653,7 +665,7 @@ DefaultMediaTheme::DefaultMediaTheme() - : BMediaTheme("BeOS Theme", "BeOS built-in theme version 0.1") + : BMediaTheme("Haiku Theme", "Haiku built-in theme version 0.1") { CALLED(); } @@ -698,7 +710,7 @@ if (group == NULL) continue; - BView *groupView = MakeViewFor(*group, rect); + BView *groupView = MakeViewFor(*group, hintRect ? &rect : NULL); if (groupView == NULL) continue; @@ -706,7 +718,8 @@ // the top-level group views must not be larger than their hintRect, // but unlike their children, they should follow all sides when // their parent is resized - view->ResizeTo(rect.Width() - 10, rect.Height() - 10); + if (hintRect != NULL) + view->ResizeTo(rect.Width() - 10, rect.Height() - 10); view->SetResizingMode(B_FOLLOW_ALL); } @@ -728,14 +741,17 @@ BView * -DefaultMediaTheme::MakeViewFor(BParameterGroup &group, const BRect &hintRect) +DefaultMediaTheme::MakeViewFor(BParameterGroup& group, const BRect* hintRect) { CALLED(); if (group.Flags() & B_HIDDEN_PARAMETER) return NULL; - BRect rect(hintRect); + BRect rect; + if (hintRect != NULL) + rect = *hintRect; + GroupView *view = new GroupView(rect, group.Name()); // Create the parameter views - but don't add them yet @@ -749,7 +765,8 @@ if (parameter == NULL) continue; - BView *parameterView = MakeSelfHostingViewFor(*parameter, rect); + BView *parameterView = MakeSelfHostingViewFor(*parameter, + hintRect ? &rect : NULL); if (parameterView == NULL) continue; @@ -779,7 +796,7 @@ if (subGroup == NULL) continue; - BView *groupView = MakeViewFor(*subGroup, rect); + BView *groupView = MakeViewFor(*subGroup, &rect); if (groupView == NULL) continue; @@ -864,18 +881,18 @@ } -/** This creates a view that handles all incoming messages itself - that's - * what is meant with self-hosting. - */ - +/*! This creates a view that handles all incoming messages itself - that's + what is meant with self-hosting. +*/ BView * -DefaultMediaTheme::MakeSelfHostingViewFor(BParameter ¶meter, const BRect &hintRect) +DefaultMediaTheme::MakeSelfHostingViewFor(BParameter& parameter, + const BRect* hintRect) { if (parameter.Flags() & B_HIDDEN_PARAMETER || parameter_should_be_hidden(parameter)) return NULL; - BView *view = MakeViewFor(¶meter, &hintRect); + BView *view = MakeViewFor(¶meter, hintRect); if (view == NULL) { // The MakeViewFor() method above returns a BControl - which we // don't need for a null parameter; that's why it returns NULL. @@ -886,12 +903,13 @@ // this is the first parameter in this group, so // let's use a nice title view - TitleView *titleView = new TitleView(hintRect, parameter.Name()); + TitleView *titleView = new TitleView(BRect(0, 0, 10, 10), parameter.Name()); titleView->ResizeToPreferred(); return titleView; } - BStringView *stringView = new BStringView(hintRect, parameter.Name(), parameter.Name()); + BStringView *stringView = new BStringView(BRect(0, 0, 10, 10), + parameter.Name(), parameter.Name()); stringView->SetAlignment(B_ALIGN_CENTER); stringView->ResizeToPreferred(); @@ -932,14 +950,15 @@ || discrete.CountItems() == 0) { // create a checkbox item - BCheckBox *checkBox = new BCheckBox(rect, discrete.Name(), discrete.Name(), NULL); + BCheckBox *checkBox = new BCheckBox(rect, discrete.Name(), + discrete.Name(), NULL); checkBox->ResizeToPreferred(); return checkBox; } else { // create a pop up menu field - // ToDo: replace BOptionPopUp (or fix it in OpenBeOS...) + // ToDo: replace BOptionPopUp (or fix it in Haiku...) // this is a workaround for a bug in BOptionPopUp - you need to // know the actual width before creating the object - very nice... @@ -953,7 +972,8 @@ width += font.StringWidth(discrete.Name()) + 55; rect.right = rect.left + width; - BOptionPopUp *popUp = new BOptionPopUp(rect, discrete.Name(), discrete.Name(), NULL); + BOptionPopUp *popUp = new BOptionPopUp(rect, discrete.Name(), + discrete.Name(), NULL); for (int32 i = 0; i < discrete.CountItems(); i++) { popUp->AddOption(discrete.ItemNameAt(i), discrete.ItemValueAt(i)); @@ -970,8 +990,7 @@ BContinuousParameter &continuous = static_cast(*parameter); if (!strcmp(continuous.Kind(), B_MASTER_GAIN) - || !strcmp(continuous.Kind(), B_GAIN)) - { + || !strcmp(continuous.Kind(), B_GAIN)) { BChannelSlider *slider = new BChannelSlider(rect, continuous.Name(), continuous.Name(), NULL, B_VERTICAL, continuous.CountChannels()); @@ -994,8 +1013,10 @@ // ToDo: take BContinuousParameter::GetResponse() & ValueStep() into account! - for (int32 i = 0; i < continuous.CountChannels(); i++) - slider->SetLimitsFor(i, int32(continuous.MinValue() * 1000), int32(continuous.MaxValue() * 1000)); + for (int32 i = 0; i < continuous.CountChannels(); i++) { + slider->SetLimitsFor(i, int32(continuous.MinValue() * 1000), + int32(continuous.MaxValue() * 1000)); + } return slider; } From axeld at mail.berlios.de Mon Oct 15 19:36:34 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 15 Oct 2007 19:36:34 +0200 Subject: [Haiku-commits] r22569 - haiku/trunk/src/apps/packageinstaller Message-ID: <200710151736.l9FHaYMY005094@sheep.berlios.de> Author: axeld Date: 2007-10-15 19:36:34 +0200 (Mon, 15 Oct 2007) New Revision: 22569 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22569&view=rev Modified: haiku/trunk/src/apps/packageinstaller/InstalledPackageInfo.cpp haiku/trunk/src/apps/packageinstaller/PackageView.h Log: Fixed warnings, minor cleanup. Modified: haiku/trunk/src/apps/packageinstaller/InstalledPackageInfo.cpp =================================================================== --- haiku/trunk/src/apps/packageinstaller/InstalledPackageInfo.cpp 2007-10-15 14:09:14 UTC (rev 22568) +++ haiku/trunk/src/apps/packageinstaller/InstalledPackageInfo.cpp 2007-10-15 17:36:34 UTC (rev 22569) @@ -8,14 +8,15 @@ #include "InstalledPackageInfo.h" -#include -#include -#include + #include #include -#include +#include +#include +#include + const char * kPackagesDir = "packages"; @@ -215,7 +216,7 @@ // Try to remove all entries that are present in the list for (i = 0; i < count; i++) { iter = static_cast(fInstalledItems.ItemAt(count - i - 1)); - fprintf(stderr, "Removing: %s (%d/%d)\n", iter->String(), i, count); + fprintf(stderr, "Removing: %s (%ld/%ld)\n", iter->String(), i, count); ret = entry.SetTo(iter->String()); if (ret == B_BUSY) { // The entry's directory is locked - wait a few cycles for it to Modified: haiku/trunk/src/apps/packageinstaller/PackageView.h =================================================================== --- haiku/trunk/src/apps/packageinstaller/PackageView.h 2007-10-15 14:09:14 UTC (rev 22568) +++ haiku/trunk/src/apps/packageinstaller/PackageView.h 2007-10-15 17:36:34 UTC (rev 22569) @@ -5,17 +5,23 @@ * Author: * ?ukasz 'Sil2100' Zemczak */ -#ifndef PACKAGEVIEW_H -#define PACKAGEVIEW_H +#ifndef PACKAGE_VIEW_H +#define PACKAGE_VIEW_H + #include "PackageInfo.h" #include "PackageStatus.h" + #include #include #include #include #include +class BPopUpMenu; +class BTextView; + + enum { P_MSG_GROUP_CHANGED = 'gpch', P_MSG_PATH_CHANGED, @@ -23,7 +29,6 @@ P_MSG_INSTALL }; - class PackageView : public BView { public: PackageView(BRect frame, const entry_ref *ref); @@ -54,6 +59,5 @@ PackageStatus *fStatusWindow; }; +#endif // PACKAGE_VIEW_H -#endif - From korli at mail.berlios.de Mon Oct 15 19:51:58 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Mon, 15 Oct 2007 19:51:58 +0200 Subject: [Haiku-commits] r22570 - haiku/trunk/src/apps/launchbox Message-ID: <200710151751.l9FHpwsL005990@sheep.berlios.de> Author: korli Date: 2007-10-15 19:51:57 +0200 (Mon, 15 Oct 2007) New Revision: 22570 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22570&view=rev Modified: haiku/trunk/src/apps/launchbox/App.cpp Log: fix signature Modified: haiku/trunk/src/apps/launchbox/App.cpp =================================================================== --- haiku/trunk/src/apps/launchbox/App.cpp 2007-10-15 17:36:34 UTC (rev 22569) +++ haiku/trunk/src/apps/launchbox/App.cpp 2007-10-15 17:51:57 UTC (rev 22570) @@ -23,7 +23,7 @@ // constructor App::App() - : BApplication("application/x.vnd-YellowBites.LaunchBox") + : BApplication("application/x-vnd.Haiku-LaunchBox") { } From korli at mail.berlios.de Mon Oct 15 20:03:21 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Mon, 15 Oct 2007 20:03:21 +0200 Subject: [Haiku-commits] r22571 - haiku/trunk/headers/os Message-ID: <200710151803.l9FI3LHw006828@sheep.berlios.de> Author: korli Date: 2007-10-15 20:03:21 +0200 (Mon, 15 Oct 2007) New Revision: 22571 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22571&view=rev Modified: haiku/trunk/headers/os/BeBuild.h Log: fix build Modified: haiku/trunk/headers/os/BeBuild.h =================================================================== --- haiku/trunk/headers/os/BeBuild.h 2007-10-15 17:51:57 UTC (rev 22570) +++ haiku/trunk/headers/os/BeBuild.h 2007-10-15 18:03:21 UTC (rev 22571) @@ -219,7 +219,7 @@ class _IMPEXP_BE _BMCMenuBar_; class _IMPEXP_BE _BMCItem_; class _IMPEXP_BE _BWidthBuffer_; -class _IMPEXP_BE BPrivateScreen; +//class _IMPEXP_BE BPrivateScreen; /* net kit */ class _IMPEXP_NET _Allocator; From korli at mail.berlios.de Mon Oct 15 20:11:08 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Mon, 15 Oct 2007 20:11:08 +0200 Subject: [Haiku-commits] r22572 - haiku/trunk/src/bin/findutils/locate Message-ID: <200710151811.l9FIB7xc007314@sheep.berlios.de> Author: korli Date: 2007-10-15 20:11:07 +0200 (Mon, 15 Oct 2007) New Revision: 22572 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22572&view=rev Modified: haiku/trunk/src/bin/findutils/locate/Jamfile Log: generate with a different name to avoid rewriting on the same file Modified: haiku/trunk/src/bin/findutils/locate/Jamfile =================================================================== --- haiku/trunk/src/bin/findutils/locate/Jamfile 2007-10-15 18:03:21 UTC (rev 22571) +++ haiku/trunk/src/bin/findutils/locate/Jamfile 2007-10-15 18:11:07 UTC (rev 22572) @@ -48,8 +48,8 @@ $(2[1]) > $(1) ; } -MkUpdateDb updatedb : updatedb.sh [ FGristFiles version.c ] ; +MkUpdateDb updatedbgen : updatedb.sh [ FGristFiles version.c ] ; MakeLocatePlatform updatedb ; -Shell updatedb : updatedb ; +Shell updatedb : updatedbgen ; SEARCH on [ FGristFiles version.c ] = [ FDirName $(SUBDIR) $(DOTDOT) find ] ; From phoudoin at mail.berlios.de Mon Oct 15 20:17:28 2007 From: phoudoin at mail.berlios.de (phoudoin at BerliOS) Date: Mon, 15 Oct 2007 20:17:28 +0200 Subject: [Haiku-commits] r22573 - haiku/trunk/src/tests/kits/opengl/direct_mode Message-ID: <200710151817.l9FIHSuN007666@sheep.berlios.de> Author: phoudoin Date: 2007-10-15 20:17:28 +0200 (Mon, 15 Oct 2007) New Revision: 22573 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22573&view=rev Modified: haiku/trunk/src/tests/kits/opengl/direct_mode/GLDirectMode.cpp Log: Applied pieterpan's patch to disallow window to get too small. #1542 is not fixed yet, as the crash happened in Mesa Software Renderer add-on first. Modified: haiku/trunk/src/tests/kits/opengl/direct_mode/GLDirectMode.cpp =================================================================== --- haiku/trunk/src/tests/kits/opengl/direct_mode/GLDirectMode.cpp 2007-10-15 18:11:07 UTC (rev 22572) +++ haiku/trunk/src/tests/kits/opengl/direct_mode/GLDirectMode.cpp 2007-10-15 18:17:28 UTC (rev 22573) @@ -71,8 +71,16 @@ SampleGLWindow::SampleGLWindow(BRect frame, uint32 type) - : BDirectWindow(frame, "OpenGL Test", B_TITLED_WINDOW, 0) + : BDirectWindow(frame, "GLDirectMode", B_TITLED_WINDOW, 0) { + float minWidth = 0.0f; + float maxWidth = 0.0f; + float minHeight = 0.0f; + float maxHeight = 0.0f; + + GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight); + SetSizeLimits(50.0f, maxWidth, 50.0f, maxHeight); + BRect r = Bounds(); r.InsetBy(10, 10); @@ -208,10 +216,12 @@ void SampleGLView::gReshape(int width, int height) { glViewport(0, 0, width, height); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(45, width / (float) height, 1, 500); - glMatrixMode(GL_MODELVIEW); + if (height) { // Avoid Divide By Zero error... + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(45, width / (float) height, 1, 500); + glMatrixMode(GL_MODELVIEW); + } } From axeld at mail.berlios.de Mon Oct 15 20:39:04 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 15 Oct 2007 20:39:04 +0200 Subject: [Haiku-commits] r22574 - haiku/trunk/src/apps/fontdemo Message-ID: <200710151839.l9FId4cl009081@sheep.berlios.de> Author: axeld Date: 2007-10-15 20:39:04 +0200 (Mon, 15 Oct 2007) New Revision: 22574 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22574&view=rev Modified: haiku/trunk/src/apps/fontdemo/FontDemoView.cpp Log: Fixed warning. Modified: haiku/trunk/src/apps/fontdemo/FontDemoView.cpp =================================================================== --- haiku/trunk/src/apps/fontdemo/FontDemoView.cpp 2007-10-15 18:17:28 UTC (rev 22573) +++ haiku/trunk/src/apps/fontdemo/FontDemoView.cpp 2007-10-15 18:39:04 UTC (rev 22574) @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku, Inc. All Rights Reserved. + * Copyright 2006-2007, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -132,9 +132,6 @@ xCoordArray[i] = 0.0f; yCoordArray[i] = 0.0f; - const float height = boundBoxes[i].Height(); - const float width = boundBoxes[i].Width(); - yCoordArray[i] = sinus * (xCoord - xCoordArray[i]); xCoordArray[i] = cosinus * xCoord; From korli at mail.berlios.de Mon Oct 15 21:07:53 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Mon, 15 Oct 2007 21:07:53 +0200 Subject: [Haiku-commits] r22575 - haiku/trunk/src/system/kernel/arch/ppc Message-ID: <200710151907.l9FJ7r3c010909@sheep.berlios.de> Author: korli Date: 2007-10-15 21:07:52 +0200 (Mon, 15 Oct 2007) New Revision: 22575 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22575&view=rev Modified: haiku/trunk/src/system/kernel/arch/ppc/arch_platform.cpp Log: fix ppc build Modified: haiku/trunk/src/system/kernel/arch/ppc/arch_platform.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/ppc/arch_platform.cpp 2007-10-15 18:39:04 UTC (rev 22574) +++ haiku/trunk/src/system/kernel/arch/ppc/arch_platform.cpp 2007-10-15 19:07:52 UTC (rev 22575) @@ -181,7 +181,7 @@ struct tm t; rtc_secs_to_tm(seconds, &t); - t.tm_year += RTC_EPOCHE_BASE_YEAR; + t.tm_year += RTC_EPOCH_BASE_YEAR; t.tm_mon++; if (of_call_method(fRTC, "set-time", 6, 0, t.tm_year, t.tm_mon, t.tm_mday, @@ -201,7 +201,7 @@ return 0; } - t.tm_year -= RTC_EPOCHE_BASE_YEAR; + t.tm_year -= RTC_EPOCH_BASE_YEAR; t.tm_mon--; return rtc_tm_to_secs(&t); From nielx at mail.berlios.de Mon Oct 15 21:56:05 2007 From: nielx at mail.berlios.de (nielx at BerliOS) Date: Mon, 15 Oct 2007 21:56:05 +0200 Subject: [Haiku-commits] r22576 - haiku/trunk/docs/user/app Message-ID: <200710151956.l9FJu5WD015538@sheep.berlios.de> Author: nielx Date: 2007-10-15 21:56:05 +0200 (Mon, 15 Oct 2007) New Revision: 22576 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22576&view=rev Modified: haiku/trunk/docs/user/app/_app_messaging.dox Log: Some improvements suggested by Axel. Thanks. Modified: haiku/trunk/docs/user/app/_app_messaging.dox =================================================================== --- haiku/trunk/docs/user/app/_app_messaging.dox 2007-10-15 19:07:52 UTC (rev 22575) +++ haiku/trunk/docs/user/app/_app_messaging.dox 2007-10-15 19:56:05 UTC (rev 22576) @@ -13,8 +13,10 @@ One of the foundations of the Haiku API is the messaging system. This framework is the basis for the efficient multithreaded Haiku applications, because it solves one of the fundamental issues of multithreading: it - allows you to easily and securely communicate between threads. But the - framework goes even further: it allows inter-application communication! + allows you to easily and securely communicate between threads. The + framework allows inter-application messaging as well as + intra-application messaging, and it will always use the most effective + mechanism for the communication automatically. This page will introduce you to the subject of messaging. It is meant as a broad overview to the classes, rather than a tutorial. If you are looking @@ -39,7 +41,9 @@ - Zero or more data objects. BMessage is a powerful data container that keeps track of different sorts of data. BMessage provides many convenient Add*() methods, for example BMessage::AddBool(). With the corresponding - Find*() method (in this example, FindBook()) you can retrieve the data. + Find*() method (in this example, + \link BMessage::FindBool(const char *, int32, bool *) const FindBool() \endlink) + you can retrieve the data. BMessage itself is generic, its syntax and semantics are determined by the context. The Haiku API defines several messages and their required data @@ -50,9 +54,9 @@ Objects of the BLooper type are objects that run message loops. Every object runs in its own thread. The BLooper objects continually check for - incoming messages, and they try to find a BHandler to actually handle the - messages within their thread context. Message handling within a thread is - synchronous. + incoming messages. To process the messages, the looper looks for message + handlers that handle the messages within the thread's context. Message + handling within a looper is synchronous. BLooper inherits BHandler, the base class for message handling. However, it is possible to chain additional handlers to the object. For example, if you @@ -101,12 +105,12 @@ If your handler cannot handle the object, it will pass the message on to the parent class. - \warning Don't forget to actuall call - baseclass::MessageReceived(). Failing to do this will mean - that the message chain will not completely be followed, which can lead - to unhandled messages. There might be some internal system messages - that the Haiku API classes handle, and not actually handling these - messages could lead to inconsistent internal behavior. + \warning Don't forget to actuall call the MessageReceived() method of the + base class. Failing to do this will mean that the message chain will + not completely be followed, which can lead to unhandled messages. There + might be some internal system messages that the Haiku API classes + handle, and not actually handling these messages could lead to + inconsistent internal behavior. \subsection app_messaging_overview_bmessenger BMessenger @@ -138,7 +142,8 @@ - BMessageFilter is the base class of the filters. Filters can be applied to BLoopers to filter all incoming messages, or to BHandlers to filter messages that could be handled by that object. The filter object can be - subclassed and extended by overriding the Filter() method. + subclassed and extended by overriding the \link BMessageFilter::Filter() + Filter() \endlink method. \section app-messaging-receiving Receiving Messages From axeld at mail.berlios.de Mon Oct 15 22:14:07 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 15 Oct 2007 22:14:07 +0200 Subject: [Haiku-commits] r22577 - in haiku/trunk: headers/os headers/os/add-ons/graphics headers/os/add-ons/input_server headers/os/app headers/os/device headers/os/game headers/os/interface headers/os/kernel headers/os/mail headers/os/media headers/os/midi headers/os/net headers/os/storage headers/os/support headers/os/translation headers/private/app headers/private/graphics/common headers/private/interface headers/private/print/libprint headers/private/storage headers/private/storage/mime headers/private/tracker src/add-ons/accelerants/common src/add-ons/media/media-add-ons/dvb src/add-ons/media/media-add-ons/mixer src/add-ons/media/media-add-ons/usb_webcam src/add-ons/media/plugins/avi_reader/libOpenDML src/add-ons/media/plugins/ogg src/apps/codycam src/apps/cortex/DiagramView src/apps/cortex/InfoView src/apps/cortex/ParameterView src/apps/cortex/Persistence src/apps/cortex/RouteApp src/apps/cortex/TransportView src/apps/cortex/support src/apps/diskprobe src/apps/installer src/apps/mail ! src/apps/people src/apps/showimage src/apps/stylededit src/apps/sudoku src/apps/tv src/bin src/kits/interface src/kits/media src/kits/textencoding src/kits/tracker src/preferences/datatranslations src/preferences/mail src/preferences/mouse src/preferences/network src/preferences/print src/servers/app src/servers/app/drawing src/servers/registrar Message-ID: <200710152014.l9FKE7OY016400@sheep.berlios.de> Author: axeld Date: 2007-10-15 22:13:55 +0200 (Mon, 15 Oct 2007) New Revision: 22577 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22577&view=rev Modified: haiku/trunk/headers/os/BeBuild.h haiku/trunk/headers/os/add-ons/graphics/GraphicsCard.h haiku/trunk/headers/os/add-ons/input_server/InputServerFilter.h haiku/trunk/headers/os/add-ons/input_server/InputServerMethod.h haiku/trunk/headers/os/app/Application.h haiku/trunk/headers/os/app/Handler.h haiku/trunk/headers/os/app/Roster.h haiku/trunk/headers/os/device/Joystick.h haiku/trunk/headers/os/game/FileGameSound.h haiku/trunk/headers/os/interface/Deskbar.h haiku/trunk/headers/os/interface/Dragger.h haiku/trunk/headers/os/interface/Font.h haiku/trunk/headers/os/interface/GraphicsDefs.h haiku/trunk/headers/os/interface/Input.h haiku/trunk/headers/os/interface/InterfaceDefs.h haiku/trunk/headers/os/interface/ListItem.h haiku/trunk/headers/os/interface/Menu.h haiku/trunk/headers/os/interface/Picture.h haiku/trunk/headers/os/interface/PrintJob.h haiku/trunk/headers/os/interface/Screen.h haiku/trunk/headers/os/interface/Shape.h haiku/trunk/headers/os/interface/Shelf.h haiku/trunk/headers/os/interface/TabView.h haiku/trunk/headers/os/interface/TextView.h haiku/trunk/headers/os/interface/View.h haiku/trunk/headers/os/kernel/image.h haiku/trunk/headers/os/kernel/scheduler.h haiku/trunk/headers/os/mail/E-mail.h haiku/trunk/headers/os/media/BufferConsumer.h haiku/trunk/headers/os/media/BufferGroup.h haiku/trunk/headers/os/media/BufferProducer.h haiku/trunk/headers/os/media/FileInterface.h haiku/trunk/headers/os/media/MediaAddOn.h haiku/trunk/headers/os/media/MediaDefs.h haiku/trunk/headers/os/media/MediaFile.h haiku/trunk/headers/os/media/MediaFormats.h haiku/trunk/headers/os/media/MediaNode.h haiku/trunk/headers/os/media/MediaRoster.h haiku/trunk/headers/os/media/MediaTheme.h haiku/trunk/headers/os/media/ParameterWeb.h haiku/trunk/headers/os/media/PlaySound.h haiku/trunk/headers/os/media/RealtimeAlloc.h haiku/trunk/headers/os/media/Sound.h haiku/trunk/headers/os/media/SoundPlayer.h haiku/trunk/headers/os/media/TimeCode.h haiku/trunk/headers/os/media/TimedEventQueue.h haiku/trunk/headers/os/midi/Synth.h haiku/trunk/headers/os/net/net_settings.h haiku/trunk/headers/os/storage/Node.h haiku/trunk/headers/os/storage/SymLink.h haiku/trunk/headers/os/support/Debug.h haiku/trunk/headers/os/support/TypeConstants.h haiku/trunk/headers/os/translation/TranslationUtils.h haiku/trunk/headers/os/translation/Translator.h haiku/trunk/headers/os/translation/TranslatorAddOn.h haiku/trunk/headers/os/translation/TranslatorFormats.h haiku/trunk/headers/os/translation/TranslatorRoster.h haiku/trunk/headers/private/app/AreaLink.h haiku/trunk/headers/private/app/LooperList.h haiku/trunk/headers/private/app/ServerLink.h haiku/trunk/headers/private/app/TokenSpace.h haiku/trunk/headers/private/graphics/common/edid_raw.h haiku/trunk/headers/private/interface/BMCPrivate.h haiku/trunk/headers/private/interface/ColorConversion.h haiku/trunk/headers/private/interface/ColorTools.h haiku/trunk/headers/private/interface/PictureDataWriter.h haiku/trunk/headers/private/interface/PicturePlayer.h haiku/trunk/headers/private/interface/input_globals.h haiku/trunk/headers/private/print/libprint/PrinterDriver.h haiku/trunk/headers/private/storage/DiskDeviceList.h haiku/trunk/headers/private/storage/mime/AssociatedTypes.h haiku/trunk/headers/private/storage/mime/SnifferRules.h haiku/trunk/headers/private/storage/mime/database_support.h haiku/trunk/headers/private/tracker/NavMenu.h haiku/trunk/headers/private/tracker/tracker_private.h haiku/trunk/src/add-ons/accelerants/common/create_display_modes.cpp haiku/trunk/src/add-ons/media/media-add-ons/dvb/DVBMediaNode.h haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerSettings.h haiku/trunk/src/add-ons/media/media-add-ons/usb_webcam/CamDevice.h haiku/trunk/src/add-ons/media/plugins/avi_reader/libOpenDML/FallbackIndex.h haiku/trunk/src/add-ons/media/plugins/avi_reader/libOpenDML/Index.h haiku/trunk/src/add-ons/media/plugins/ogg/OggReaderPlugin.h haiku/trunk/src/apps/codycam/SettingsHandler.h haiku/trunk/src/apps/cortex/DiagramView/DiagramItem.h haiku/trunk/src/apps/cortex/InfoView/DormantNodeInfoView.h haiku/trunk/src/apps/cortex/InfoView/InfoWindowManager.h haiku/trunk/src/apps/cortex/ParameterView/ParameterWindow.h haiku/trunk/src/apps/cortex/Persistence/ExportContext.h haiku/trunk/src/apps/cortex/RouteApp/RouteWindow.h haiku/trunk/src/apps/cortex/TransportView/TransportView.h haiku/trunk/src/apps/cortex/support/MediaIcon.h haiku/trunk/src/apps/diskprobe/DataEditor.h haiku/trunk/src/apps/installer/FSUtils.cpp haiku/trunk/src/apps/installer/FSUtils.h haiku/trunk/src/apps/mail/ComboBox.h haiku/trunk/src/apps/mail/Header.h haiku/trunk/src/apps/mail/MailSupport.h haiku/trunk/src/apps/mail/MailWindow.h haiku/trunk/src/apps/mail/Prefs.h haiku/trunk/src/apps/mail/QueryMenu.h haiku/trunk/src/apps/mail/Status.h haiku/trunk/src/apps/people/PeopleApp.h haiku/trunk/src/apps/showimage/ResizerWindow.h haiku/trunk/src/apps/stylededit/StyledEditView.h haiku/trunk/src/apps/sudoku/SudokuView.h haiku/trunk/src/apps/tv/Controller.h haiku/trunk/src/apps/tv/VideoNode.h haiku/trunk/src/apps/tv/VideoView.h haiku/trunk/src/bin/setdecor.cpp haiku/trunk/src/kits/interface/InterfaceDefs.cpp haiku/trunk/src/kits/interface/View.cpp haiku/trunk/src/kits/media/TimeSourceObjectManager.h haiku/trunk/src/kits/textencoding/character_sets.cpp haiku/trunk/src/kits/tracker/Bitmaps.h haiku/trunk/src/kits/tracker/ContainerWindow.cpp haiku/trunk/src/kits/tracker/FBCPadding.cpp haiku/trunk/src/kits/tracker/FSUtils.h haiku/trunk/src/kits/tracker/FilePanel.cpp haiku/trunk/src/kits/tracker/FindPanel.h haiku/trunk/src/kits/tracker/Model.cpp haiku/trunk/src/kits/tracker/Tracker.cpp haiku/trunk/src/kits/tracker/Utilities.cpp haiku/trunk/src/preferences/datatranslations/DataTranslationsWindow.h haiku/trunk/src/preferences/mail/ConfigViews.h haiku/trunk/src/preferences/mouse/MouseSettings.h haiku/trunk/src/preferences/network/EthernetSettingsView.h haiku/trunk/src/preferences/print/PrintersWindow.h haiku/trunk/src/servers/app/FontManager.h haiku/trunk/src/servers/app/ProfileMessageSupport.cpp haiku/trunk/src/servers/app/ServerScreen.h haiku/trunk/src/servers/app/ViewLayer.h haiku/trunk/src/servers/app/drawing/PatternHandler.h haiku/trunk/src/servers/app/drawing/drawing_support.h haiku/trunk/src/servers/registrar/RecentApps.h haiku/trunk/src/servers/registrar/RecentEntries.h Log: * Rewrote BeBuild.h which had "a few" consequences (got rid of all those class definitions). * Minor cleanup here and there. Modified: haiku/trunk/headers/os/BeBuild.h =================================================================== --- haiku/trunk/headers/os/BeBuild.h 2007-10-15 19:56:05 UTC (rev 22576) +++ haiku/trunk/headers/os/BeBuild.h 2007-10-15 20:13:55 UTC (rev 22577) @@ -1,387 +1,26 @@ -/****************************************************************************** -/ -/ File: BeBuild.h -/ -/ Description: Import/export macros -/ -/ Copyright 1993-98, Be Incorporated -/ -*******************************************************************************/ - +/* + * Copyright 2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + */ #ifndef _BE_BUILD_H #define _BE_BUILD_H + #define B_BEOS_VERSION_4 0x0400 #define B_BEOS_VERSION_4_5 0x0450 #define B_BEOS_VERSION_5 0x0500 #define B_BEOS_VERSION B_BEOS_VERSION_5 -#define B_BEOS_VERSION_MAUI B_BEOS_VERSION_5 +#define B_BEOS_VERSION_MAUI B_BEOS_VERSION_5 -#if defined(__POWERPC__) - // the PowerPC build is using GCC now (BeOS R5 used to use the Metrowerks - // compiler), so it is not compatible to any BeOS version on that platform - // before. However, that wouldn't rule out source compatibility, which - // we do here (for now). - #define _PR2_COMPATIBLE_ 0 - #define _PR3_COMPATIBLE_ 0 - #define _R4_COMPATIBLE_ 0 - #define _R4_5_COMPATIBLE_ 0 -#elif defined(__INTEL__) - #define _PR2_COMPATIBLE_ 0 - #define _PR3_COMPATIBLE_ 0 - #define _R4_COMPATIBLE_ 1 - #define _R4_5_COMPATIBLE_ 1 -#else -# error Configure BeBuild.h for your platform -#endif +#define B_HAIKU_VERSION_1 0x0100 -#if __MWERKS__ -# define _UNUSED(x) -# define _PACKED -#endif - #if __GNUC__ -# define _UNUSED(x) x -# define _PACKED __attribute__((packed)) -#endif - -#if defined(__INTEL__) || defined(__POWERPC__) - -// This is the standard import/export definitions used for -// the ELF binary format - this should be usable by all flavors -// of OpenBeOS. - +# define _UNUSED(argument) argument +# define _PACKED __attribute__((packed)) +# define _PRINTFLIKE(_format_, _args_) \ + __attribute__((format(__printf__, _format_, _args_))) # define _EXPORT -# define _IMPORT - -# define _IMPEXP_KERNEL -# define _IMPEXP_GL -# define _IMPEXP_ROOT -# define _IMPEXP_NET -# define _IMPEXP_NETDEV -# define _IMPEXP_ATALK -# define _IMPEXP_BE -# define _IMPEXP_TRACKER -# define _IMPEXP_MAIL -# define _IMPEXP_DEVICE -# define _IMPEXP_MEDIA -# define _IMPEXP_MIDI -# define _IMPEXP_MIDI2 -# define _IMPEXP_GAME -# define _IMPEXP_GSOUND -# define _IMPEXP_TRANSLATION -# define _IMPEXP_TEXTENCODING -# define _IMPEXP_INPUT #endif - -#ifdef __cplusplus - -/* cpp kit */ - -// /* -- */ -// class _IMPEXP_ROOT bad_cast; -// class _IMPEXP_ROOT bad_typeid; -// class _IMPEXP_ROOT type_info; -// -// /* -- */ -// class _IMPEXP_ROOT exception; -// class _IMPEXP_ROOT bad_exception; -// -// /* -- */ -// class _IMPEXP_ROOT bad_alloc; -// -// /* -- */ -// class _IMPEXP_ROOT logic_error; -// class _IMPEXP_ROOT domain_error; -// class _IMPEXP_ROOT invalid_argument; -// class _IMPEXP_ROOT length_error; -// class _IMPEXP_ROOT out_of_range; -// class _IMPEXP_ROOT runtime_error; -// class _IMPEXP_ROOT range_error; -// class _IMPEXP_ROOT overflow_error; - -/* support kit */ -class _IMPEXP_BE BArchivable; -class _IMPEXP_BE BAutolock; -class _IMPEXP_BE BBlockCache; -class _IMPEXP_BE BBufferIO; -class _IMPEXP_BE BDataIO; -class _IMPEXP_BE BPositionIO; -class _IMPEXP_BE BMallocIO; -class _IMPEXP_BE BMemoryIO; -class _IMPEXP_BE BFlattenable; -class _IMPEXP_BE BList; -class _IMPEXP_BE BLocker; -class _IMPEXP_BE BStopWatch; -class _IMPEXP_BE BString; - -class _IMPEXP_BE PointerList; - -/*storage kit */ -struct _IMPEXP_BE entry_ref; -struct _IMPEXP_BE node_ref; -class _IMPEXP_BE BAppFileInfo; -class _IMPEXP_BE BDirectory; -class _IMPEXP_BE BEntry; -class _IMPEXP_BE BFile; -class _IMPEXP_BE BRefFilter; -class _IMPEXP_BE BMimeType; -class _IMPEXP_BE BNode; -class _IMPEXP_BE BNodeInfo; -class _IMPEXP_BE BPath; -class _IMPEXP_BE BQuery; -class _IMPEXP_BE BResources; -class _IMPEXP_BE BResourceStrings; -class _IMPEXP_BE BStatable; -class _IMPEXP_BE BSymLink; -class _IMPEXP_BE BVolume; -class _IMPEXP_BE BVolumeRoster; - -//class _IMPEXP_BE Partition; -//class _IMPEXP_BE Session; -//class _IMPEXP_BE Device; -//class _IMPEXP_BE DeviceList; -//class _IMPEXP_BE TNodeWalker; -//class _IMPEXP_BE TQueryWalker; -//class _IMPEXP_BE TVolWalker; - -/*app kit */ -struct _IMPEXP_BE app_info; -class _IMPEXP_BE BApplication; -class _IMPEXP_BE BClipboard; -class _IMPEXP_BE BHandler; -class _IMPEXP_BE BInvoker; -class _IMPEXP_BE BLooper; -class _IMPEXP_BE BMessage; -class _IMPEXP_BE BMessageFilter; -class _IMPEXP_BE BMessageQueue; -class _IMPEXP_BE BMessageRunner; -class _IMPEXP_BE BMessenger; -class _IMPEXP_BE BPropertyInfo; -class _IMPEXP_BE BRoster; - -class _IMPEXP_BE _BAppServerLink_; -class _IMPEXP_BE _BSession_; - -/*interface kit */ -class _IMPEXP_BE BAlert; -class _IMPEXP_BE BBitmap; -class _IMPEXP_BE BBox; -class _IMPEXP_BE BButton; -class _IMPEXP_BE BChannelControl; -class _IMPEXP_BE BChannelSlider; -class _IMPEXP_BE BCheckBox; -class _IMPEXP_BE BColorControl; -class _IMPEXP_BE BControl; -class _IMPEXP_BE BDeskbar; -class _IMPEXP_BE BDragger; -class _IMPEXP_BE BFont; -class _IMPEXP_BE BInputDevice; -class _IMPEXP_BE BListItem; -class _IMPEXP_BE BListView; -class _IMPEXP_BE BStringItem; -class _IMPEXP_BE BMenu; -class _IMPEXP_BE BMenuBar; -class _IMPEXP_BE BMenuField; -class _IMPEXP_BE BMenuItem; -class _IMPEXP_BE BOptionControl; -class _IMPEXP_BE BOptionPopUp; -class _IMPEXP_BE BOutlineListView; -class _IMPEXP_BE BPicture; -class _IMPEXP_BE BPictureButton; -class _IMPEXP_BE BPoint; -class _IMPEXP_BE BPolygon; -class _IMPEXP_BE BPopUpMenu; -class _IMPEXP_BE BPrintJob; -class _IMPEXP_BE BRadioButton; -class _IMPEXP_BE BRect; -class _IMPEXP_BE BRegion; -class _IMPEXP_BE BScreen; -class _IMPEXP_BE BScrollBar; -class _IMPEXP_BE BScrollView; -class _IMPEXP_BE BSeparatorItem; -class _IMPEXP_BE BShelf; -class _IMPEXP_BE BShape; -class _IMPEXP_BE BShapeIterator; -class _IMPEXP_BE BSlider; -class _IMPEXP_BE BStatusBar; -class _IMPEXP_BE BStringView; -class _IMPEXP_BE BTab; -class _IMPEXP_BE BTabView; -class _IMPEXP_BE BTextControl; -class _IMPEXP_BE BTextView; -class _IMPEXP_BE BView; -class _IMPEXP_BE BWindow; - -class _IMPEXP_BE _BTextInput_; -class _IMPEXP_BE _BMCMenuBar_; -class _IMPEXP_BE _BMCItem_; -class _IMPEXP_BE _BWidthBuffer_; -//class _IMPEXP_BE BPrivateScreen; - -/* net kit */ -class _IMPEXP_NET _Allocator; -class _IMPEXP_NET _Transacter; -class _IMPEXP_NET _FastIPC; - -/* netdev kit */ -class _IMPEXP_NETDEV BNetPacket; -class _IMPEXP_NETDEV BStandardPacket; -class _IMPEXP_NETDEV BTimeoutHandler; -class _IMPEXP_NETDEV BPacketHandler; -class _IMPEXP_NETDEV BNetProtocol; -class _IMPEXP_NETDEV BNetDevice; -class _IMPEXP_NETDEV BCallBackHandler; -class _IMPEXP_NETDEV BNetConfig; -class _IMPEXP_NETDEV BIpDevice; - -class _IMPEXP_NETDEV _NetBufList; -class _IMPEXP_NETDEV _BSem; - -/* atalk kit */ -class _IMPEXP_ATALK _PrinterNode; - -/* tracker kit */ -class _IMPEXP_TRACKER BFilePanel; -class _IMPEXP_TRACKER BRecentItemsList; -class _IMPEXP_TRACKER BRecentFilesList; -class _IMPEXP_TRACKER BRecentFoldersList; -class _IMPEXP_TRACKER BRecentAppsList; - -/* mail kit */ -class _IMPEXP_MAIL BMailMessage; - -/* device kit */ -class _IMPEXP_DEVICE BA2D; -class _IMPEXP_DEVICE BD2A; -class _IMPEXP_DEVICE BDigitalPort; -class _IMPEXP_DEVICE BJoystick; -class _IMPEXP_DEVICE BSerialPort; - -/* media kit */ -class _IMPEXP_MEDIA BDACRenderer; -class _IMPEXP_MEDIA BAudioFileStream; -class _IMPEXP_MEDIA BADCStream; -class _IMPEXP_MEDIA BDACStream; -class _IMPEXP_MEDIA BAbstractBufferStream; -class _IMPEXP_MEDIA BBufferStreamManager; -class _IMPEXP_MEDIA BBufferStream; -class _IMPEXP_MEDIA BSoundFile; -class _IMPEXP_MEDIA BSubscriber; - -class _IMPEXP_MEDIA BMediaRoster; -class _IMPEXP_MEDIA BMediaNode; -class _IMPEXP_MEDIA BTimeSource; -class _IMPEXP_MEDIA BBufferProducer; -class _IMPEXP_MEDIA BBufferConsumer; -class _IMPEXP_MEDIA BBuffer; -class _IMPEXP_MEDIA BBufferGroup; -class _IMPEXP_MEDIA BControllable; -class _IMPEXP_MEDIA BFileInterface; -class _IMPEXP_MEDIA BEntityInterface; -class _IMPEXP_MEDIA BMediaAddOn; -class _IMPEXP_MEDIA BMediaTheme; -class _IMPEXP_MEDIA BParameterWeb; -class _IMPEXP_MEDIA BParameterGroup; -class _IMPEXP_MEDIA BParameter; -class _IMPEXP_MEDIA BNullParameter; -class _IMPEXP_MEDIA BDiscreteParameter; -class _IMPEXP_MEDIA BContinuousParameter; -class _IMPEXP_MEDIA BMediaFiles; -class _IMPEXP_MEDIA BSound; -class _IMPEXP_MEDIA BSoundCard; -class _IMPEXP_MEDIA BSoundPlayer; -class _IMPEXP_MEDIA BMediaFormats; -class _IMPEXP_MEDIA BTimedEventQueue; -//class _IMPEXP_MEDIA BEventIterator; -class _IMPEXP_MEDIA BMediaEventLooper; -class _IMPEXP_MEDIA BMediaFile; -class _IMPEXP_MEDIA BMediaTrack; - -class _IMPEXP_MEDIA media_node; -struct _IMPEXP_MEDIA media_input; -struct _IMPEXP_MEDIA media_output; -struct _IMPEXP_MEDIA live_node_info; -struct _IMPEXP_MEDIA buffer_clone_info; -struct _IMPEXP_MEDIA media_source; -struct _IMPEXP_MEDIA media_destination; -struct _IMPEXP_MEDIA media_raw_audio_format; -struct _IMPEXP_MEDIA media_raw_video_format; -struct _IMPEXP_MEDIA media_video_display_info; -struct _IMPEXP_MEDIA flavor_info; -struct _IMPEXP_MEDIA dormant_node_info; -struct _IMPEXP_MEDIA dormant_flavor_info; -struct _IMPEXP_MEDIA media_source; -struct _IMPEXP_MEDIA media_destination; -struct _IMPEXP_MEDIA _media_format_description; -struct _IMPEXP_MEDIA media_timed_event; - -/* midi kit */ -class _IMPEXP_MIDI BMidi; -class _IMPEXP_MIDI BMidiPort; -class _IMPEXP_MIDI BMidiStore; -class _IMPEXP_MIDI BMidiSynth; -class _IMPEXP_MIDI BMidiSynthFile; -class _IMPEXP_MIDI BMidiText; -class _IMPEXP_MIDI BSamples; -class _IMPEXP_MIDI BSynth; - -class _IMPEXP_MIDI2 BMidiEndpoint; -class _IMPEXP_MIDI2 BMidiProducer; -class _IMPEXP_MIDI2 BMidiConsumer; -class _IMPEXP_MIDI2 BMidiLocalProducer; -class _IMPEXP_MIDI2 BMidiLocalConsumer; -class _IMPEXP_MIDI2 BMidiRoster; - -/* game kit */ -class _IMPEXP_GAME BWindowScreen; -class _IMPEXP_GAME BDirectWindow; - -/* gamesound kit */ -class _IMPEXP_GSOUND BGameSound; -class _IMPEXP_GSOUND BSimpleGameSound; -class _IMPEXP_GSOUND BStreamingGameSound; -class _IMPEXP_GSOUND BFileGameSound; -class _IMPEXP_GSOUND BPushGameSound; - -/* translation kit */ -class _IMPEXP_TRANSLATION BTranslatorRoster; -class _IMPEXP_TRANSLATION BTranslationUtils; -class _IMPEXP_TRANSLATION BBitmapStream; -class _IMPEXP_TRANSLATION BTranslator; -struct _IMPEXP_TRANSLATION translation_format; -struct _IMPEXP_TRANSLATION translator_info; - -/* GL */ -class _IMPEXP_GL BGLView; -class _IMPEXP_GL BGLScreen; -class _IMPEXP_GL GLUnurbs; -class _IMPEXP_GL GLUquadric; -class _IMPEXP_GL GLUtesselator; - -typedef class _IMPEXP_GL GLUnurbs GLUnurbsObj; -typedef class _IMPEXP_GL GLUquadric GLUquadricObj; -typedef class _IMPEXP_GL GLUtesselator GLUtesselatorObj; -typedef class _IMPEXP_GL GLUtesselator GLUtriangulatorObj; - -/* input_server */ -class _IMPEXP_INPUT BInputServerDevice; -class _IMPEXP_INPUT BInputServerFilter; -class _IMPEXP_INPUT BInputServerMethod; - -#else /* __cplusplus */ -/* -//typedef struct _IMPEXP_GL GLUnurbs GLUnurbs; -//typedef struct _IMPEXP_GL GLUquadric GLUquadric; -//typedef struct _IMPEXP_GL GLUtesselator GLUtesselator; - -//typedef struct _IMPEXP_GL GLUnurbs GLUnurbsObj; -//typedef struct _IMPEXP_GL GLUquadric GLUquadricObj; -//typedef struct _IMPEXP_GL GLUtesselator GLUtesselatorObj; -//typedef struct _IMPEXP_GL GLUtesselator GLUtriangulatorObj; -*/ -#endif /* __cplusplus */ - #endif /* _BE_BUILD_H */ Modified: haiku/trunk/headers/os/add-ons/graphics/GraphicsCard.h =================================================================== --- haiku/trunk/headers/os/add-ons/graphics/GraphicsCard.h 2007-10-15 19:56:05 UTC (rev 22576) +++ haiku/trunk/headers/os/add-ons/graphics/GraphicsCard.h 2007-10-15 20:13:55 UTC (rev 22577) @@ -147,7 +147,7 @@ extern "C" { #endif -_EXPORT int32 control_graphics_card(uint32, void*); +int32 control_graphics_card(uint32, void*); #ifdef __cplusplus } Modified: haiku/trunk/headers/os/add-ons/input_server/InputServerFilter.h =================================================================== --- haiku/trunk/headers/os/add-ons/input_server/InputServerFilter.h 2007-10-15 19:56:05 UTC (rev 22576) +++ haiku/trunk/headers/os/add-ons/input_server/InputServerFilter.h 2007-10-15 20:13:55 UTC (rev 22577) @@ -15,6 +15,7 @@ #include #include +class BRegion; class BInputServerFilter { public: Modified: haiku/trunk/headers/os/add-ons/input_server/InputServerMethod.h =================================================================== --- haiku/trunk/headers/os/add-ons/input_server/InputServerMethod.h 2007-10-15 19:56:05 UTC (rev 22576) +++ haiku/trunk/headers/os/add-ons/input_server/InputServerMethod.h 2007-10-15 20:13:55 UTC (rev 22577) @@ -18,6 +18,7 @@ class _BMethodAddOn_; class AddOnManager; +class BMenu; class InputServer; class BInputServerMethod : public BInputServerFilter { Modified: haiku/trunk/headers/os/app/Application.h =================================================================== --- haiku/trunk/headers/os/app/Application.h 2007-10-15 19:56:05 UTC (rev 22576) +++ haiku/trunk/headers/os/app/Application.h 2007-10-15 20:13:55 UTC (rev 22577) @@ -1,5 +1,5 @@ /* - * Copyright 2001-2006, Haiku. + * Copyright 2001-2007, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -20,10 +20,12 @@ class BCursor; class BList; -class BWindow; +class BLocker; +class BMessageRunner; class BResources; -class BMessageRunner; class BServer; +class BWindow; +struct app_info; namespace BPrivate { class PortLink; @@ -163,7 +165,7 @@ // Global Objects -extern _IMPEXP_BE BApplication* be_app; -extern _IMPEXP_BE BMessenger be_app_messenger; +extern BApplication* be_app; +extern BMessenger be_app_messenger; #endif // _APPLICATION_H Modified: haiku/trunk/headers/os/app/Handler.h =================================================================== --- haiku/trunk/headers/os/app/Handler.h 2007-10-15 19:56:05 UTC (rev 22576) +++ haiku/trunk/headers/os/app/Handler.h 2007-10-15 20:13:55 UTC (rev 22577) @@ -16,6 +16,7 @@ class BLooper; class BMessageFilter; class BMessage; +class BMessenger; class BList; #define B_OBSERVE_WHAT_CHANGE "be:observe_change_what" Modified: haiku/trunk/headers/os/app/Roster.h =================================================================== --- haiku/trunk/headers/os/app/Roster.h 2007-10-15 19:56:05 UTC (rev 22576) +++ haiku/trunk/headers/os/app/Roster.h 2007-10-15 20:13:55 UTC (rev 22577) @@ -13,7 +13,10 @@ #include #include +class BMimeType; +class BNodeInfo; + struct app_info { app_info(); ~app_info(); Modified: haiku/trunk/headers/os/device/Joystick.h =================================================================== --- haiku/trunk/headers/os/device/Joystick.h 2007-10-15 19:56:05 UTC (rev 22576) +++ haiku/trunk/headers/os/device/Joystick.h 2007-10-15 20:13:55 UTC (rev 22577) @@ -17,8 +17,10 @@ #include class BList; +class BString; +struct entry_ref; struct _extended_joystick; -class _IMPEXP_DEVICE _BJoystickTweaker; +class _BJoystickTweaker; /* -----------------------------------------------------------------------*/ class BJoystick { @@ -107,12 +109,10 @@ BList * _fDevices; _joystick_info * m_info; char * m_dev_name; -#if !_PR3_COMPATIBLE_ virtual status_t _Reserved_Joystick_4(void *, ...); virtual status_t _Reserved_Joystick_5(void *, ...); virtual status_t _Reserved_Joystick_6(void *, ...); uint32 _reserved_Joystick_[10]; -#endif }; #endif Modified: haiku/trunk/headers/os/game/FileGameSound.h =================================================================== --- haiku/trunk/headers/os/game/FileGameSound.h 2007-10-15 19:56:05 UTC (rev 22576) +++ haiku/trunk/headers/os/game/FileGameSound.h 2007-10-15 20:13:55 UTC (rev 22577) @@ -23,28 +23,18 @@ // Author: Christopher ML Zumwalt May (zummy at users.sf.net) // Description: BFileGameSound is a class that streams data out of a file. //------------------------------------------------------------------------------ - #ifndef _FILEGAMESOUND_H #define _FILEGAMESOUND_H -// Standard Includes ----------------------------------------------------------- -// System Includes ------------------------------------------------------------- #include -// Project Includes ------------------------------------------------------------ - -// Local Includes -------------------------------------------------------------- - -// Local Defines --------------------------------------------------------------- - -// Globals --------------------------------------------------------------------- +struct entry_ref; struct _gs_media_tracker; struct _gs_ramp; -// FileGameSound ------------------------------------------------------------- -class BFileGameSound : public BStreamingGameSound -{ + +class BFileGameSound : public BStreamingGameSound { public: BFileGameSound(const entry_ref * file, bool looping = true, @@ -74,7 +64,6 @@ int32 IsPaused(); private: - _gs_media_tracker * fAudioStream; bool fStopping; @@ -133,4 +122,4 @@ virtual status_t _Reserved_BFileGameSound_23(int32 arg, ...); }; -#endif +#endif // _FILEGAMESOUND_H Modified: haiku/trunk/headers/os/interface/Deskbar.h =================================================================== --- haiku/trunk/headers/os/interface/Deskbar.h 2007-10-15 19:56:05 UTC (rev 22576) +++ haiku/trunk/headers/os/interface/Deskbar.h 2007-10-15 20:13:55 UTC (rev 22577) @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku, Inc. All Rights Reserved. + * Copyright 2006-2007, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. */ #ifndef _DESKBAR_H @@ -11,6 +11,7 @@ class BMessenger; class BView; +struct entry_ref; enum deskbar_location { Modified: haiku/trunk/headers/os/interface/Dragger.h =================================================================== --- haiku/trunk/headers/os/interface/Dragger.h 2007-10-15 19:56:05 UTC (rev 22576) +++ haiku/trunk/headers/os/interface/Dragger.h 2007-10-15 20:13:55 UTC (rev 22577) @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku, Inc. All Rights Reserved. + * Copyright 2006-2007, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. */ #ifndef _DRAGGER_H @@ -12,6 +12,7 @@ class BBitmap; class BMessage; +class BPopUpMenu; class BShelf; namespace BPrivate { Modified: haiku/trunk/headers/os/interface/Font.h =================================================================== --- haiku/trunk/headers/os/interface/Font.h 2007-10-15 19:56:05 UTC (rev 22576) +++ haiku/trunk/headers/os/interface/Font.h 2007-10-15 20:13:55 UTC (rev 22577) @@ -1,5 +1,5 @@ /* - * Copyright 2005, Haiku, Inc. All Rights Reserved. + * Copyright 2005-2007, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. */ #ifndef _FONT_H_ @@ -9,7 +9,9 @@ #include #include +class BPoint; + #define B_FONT_FAMILY_LENGTH 63 #define B_FONT_STYLE_LENGTH 63 typedef char font_family[B_FONT_FAMILY_LENGTH + 1]; Modified: haiku/trunk/headers/os/interface/GraphicsDefs.h =================================================================== --- haiku/trunk/headers/os/interface/GraphicsDefs.h 2007-10-15 19:56:05 UTC (rev 22576) +++ haiku/trunk/headers/os/interface/GraphicsDefs.h 2007-10-15 20:13:55 UTC (rev 22577) @@ -65,9 +65,9 @@ #endif // __cplusplus -extern _IMPEXP_BE const pattern B_SOLID_HIGH; -extern _IMPEXP_BE const pattern B_MIXED_COLORS; -extern _IMPEXP_BE const pattern B_SOLID_LOW; +extern const pattern B_SOLID_HIGH; +extern const pattern B_MIXED_COLORS; +extern const pattern B_SOLID_LOW; //------------------------------------------------------------------------------ @@ -115,15 +115,15 @@ //------------------------------------------------------------------------------ -extern _IMPEXP_BE const rgb_color B_TRANSPARENT_COLOR; -extern _IMPEXP_BE const uint8 B_TRANSPARENT_MAGIC_CMAP8; -extern _IMPEXP_BE const uint16 B_TRANSPARENT_MAGIC_RGBA15; -extern _IMPEXP_BE const uint16 B_TRANSPARENT_MAGIC_RGBA15_BIG; -extern _IMPEXP_BE const uint32 B_TRANSPARENT_MAGIC_RGBA32; -extern _IMPEXP_BE const uint32 B_TRANSPARENT_MAGIC_RGBA32_BIG; +extern const rgb_color B_TRANSPARENT_COLOR; +extern const uint8 B_TRANSPARENT_MAGIC_CMAP8; +extern const uint16 B_TRANSPARENT_MAGIC_RGBA15; +extern const uint16 B_TRANSPARENT_MAGIC_RGBA15_BIG; +extern const uint32 B_TRANSPARENT_MAGIC_RGBA32; +extern const uint32 B_TRANSPARENT_MAGIC_RGBA32_BIG; -extern _IMPEXP_BE const uint8 B_TRANSPARENT_8_BIT; -extern _IMPEXP_BE const rgb_color B_TRANSPARENT_32_BIT; +extern const uint8 B_TRANSPARENT_8_BIT; +extern const rgb_color B_TRANSPARENT_32_BIT; //------------------------------------------------------------------------------ @@ -160,7 +160,7 @@ struct screen_id { int32 id; }; -extern _IMPEXP_BE const struct screen_id B_MAIN_SCREEN_ID; +extern const struct screen_id B_MAIN_SCREEN_ID; //------------------------------------------------------------------------------ @@ -272,7 +272,7 @@ B_VIEWS_SUPPORT_DRAW_BITMAP = 0x1, B_BITMAPS_SUPPORT_ATTACHED_VIEWS = 0x2 }; -_IMPEXP_BE bool bitmaps_support_space(color_space space, uint32 * support_flags); +bool bitmaps_support_space(color_space space, uint32 * support_flags); //------------------------------------------------------------------------------ // "pixel_chunk" is the native increment from one pixel starting on an integral byte @@ -281,7 +281,7 @@ // sets pixel_chunk to 1, row_alignment to 4 and pixels_per_chunk to 8, whereas // B_RGB24 sets pixel_chunk to 3, row_alignment to 4 and pixels_per_chunk to 1. //------------------------------------------------------------------------------ -_IMPEXP_BE status_t get_pixel_size_for(color_space space, size_t * pixel_chunk, +status_t get_pixel_size_for(color_space space, size_t * pixel_chunk, size_t * row_alignment, size_t * pixels_per_chunk); Modified: haiku/trunk/headers/os/interface/Input.h =================================================================== --- haiku/trunk/headers/os/interface/Input.h 2007-10-15 19:56:05 UTC (rev 22576) +++ haiku/trunk/headers/os/interface/Input.h 2007-10-15 20:13:55 UTC (rev 22577) @@ -15,7 +15,9 @@ #include #include +class BList; + enum input_method_op { B_INPUT_METHOD_STARTED = 0, B_INPUT_METHOD_STOPPED = 1, @@ -47,9 +49,9 @@ class BInputDevice; -_IMPEXP_BE BInputDevice* find_input_device(const char *name); -_IMPEXP_BE status_t get_input_devices(BList *list); -_IMPEXP_BE status_t watch_input_devices(BMessenger target, bool start); +BInputDevice* find_input_device(const char *name); +status_t get_input_devices(BList *list); +status_t watch_input_devices(BMessenger target, bool start); class BInputDevice { Modified: haiku/trunk/headers/os/interface/InterfaceDefs.h =================================================================== --- haiku/trunk/headers/os/interface/InterfaceDefs.h 2007-10-15 19:56:05 UTC (rev 22576) +++ haiku/trunk/headers/os/interface/InterfaceDefs.h 2007-10-15 20:13:55 UTC (rev 22577) @@ -251,54 +251,54 @@ /*----------------------------------------------------------------*/ -_IMPEXP_BE status_t get_deskbar_frame(BRect *frame); +status_t get_deskbar_frame(BRect *frame); -_IMPEXP_BE const color_map *system_colors(); +const color_map *system_colors(); -_IMPEXP_BE status_t set_screen_space(int32 index, uint32 res, - bool stick = true); +status_t set_screen_space(int32 index, uint32 res, + bool stick = true); -_IMPEXP_BE status_t get_scroll_bar_info(scroll_bar_info *info); -_IMPEXP_BE status_t set_scroll_bar_info(scroll_bar_info *info); +status_t get_scroll_bar_info(scroll_bar_info *info); +status_t set_scroll_bar_info(scroll_bar_info *info); -_IMPEXP_BE status_t get_mouse_type(int32 *type); -_IMPEXP_BE status_t set_mouse_type(int32 type); -_IMPEXP_BE status_t get_mouse_map(mouse_map *map); -_IMPEXP_BE status_t set_mouse_map(mouse_map *map); -_IMPEXP_BE status_t get_click_speed(bigtime_t *speed); -_IMPEXP_BE status_t set_click_speed(bigtime_t speed); -_IMPEXP_BE status_t get_mouse_speed(int32 *speed); -_IMPEXP_BE status_t set_mouse_speed(int32 speed); -_IMPEXP_BE status_t get_mouse_acceleration(int32 *speed); -_IMPEXP_BE status_t set_mouse_acceleration(int32 speed); +status_t get_mouse_type(int32 *type); +status_t set_mouse_type(int32 type); +status_t get_mouse_map(mouse_map *map); +status_t set_mouse_map(mouse_map *map); +status_t get_click_speed(bigtime_t *speed); +status_t set_click_speed(bigtime_t speed); +status_t get_mouse_speed(int32 *speed); +status_t set_mouse_speed(int32 speed); +status_t get_mouse_acceleration(int32 *speed); +status_t set_mouse_acceleration(int32 speed); -_IMPEXP_BE status_t get_key_repeat_rate(int32 *rate); -_IMPEXP_BE status_t set_key_repeat_rate(int32 rate); -_IMPEXP_BE status_t get_key_repeat_delay(bigtime_t *delay); -_IMPEXP_BE status_t set_key_repeat_delay(bigtime_t delay); +status_t get_key_repeat_rate(int32 *rate); +status_t set_key_repeat_rate(int32 rate); +status_t get_key_repeat_delay(bigtime_t *delay); +status_t set_key_repeat_delay(bigtime_t delay); -_IMPEXP_BE uint32 modifiers(); -_IMPEXP_BE status_t get_key_info(key_info *info); -_IMPEXP_BE void get_key_map(key_map **map, char **key_buffer); -_IMPEXP_BE status_t get_keyboard_id(uint16 *id); -_IMPEXP_BE void set_modifier_key(uint32 modifier, uint32 key); -_IMPEXP_BE void set_keyboard_locks(uint32 modifiers); +uint32 modifiers(); +status_t get_key_info(key_info *info); +void get_key_map(key_map **map, char **key_buffer); +status_t get_keyboard_id(uint16 *id); +void set_modifier_key(uint32 modifier, uint32 key); +void set_keyboard_locks(uint32 modifiers); -_IMPEXP_BE rgb_color keyboard_navigation_color(); +rgb_color keyboard_navigation_color(); -_IMPEXP_BE int32 count_workspaces(); -_IMPEXP_BE void set_workspace_count(int32 count); -_IMPEXP_BE int32 current_workspace(); -_IMPEXP_BE void activate_workspace(int32 workspace); +int32 count_workspaces(); +void set_workspace_count(int32 count); +int32 current_workspace(); +void activate_workspace(int32 workspace); -_IMPEXP_BE bigtime_t idle_time(); +bigtime_t idle_time(); -_IMPEXP_BE void run_select_printer_panel(); -_IMPEXP_BE void run_add_printer_panel(); -_IMPEXP_BE void run_be_about(); +void run_select_printer_panel(); +void run_add_printer_panel(); +void run_be_about(); -_IMPEXP_BE void set_focus_follows_mouse(bool follow); -_IMPEXP_BE bool focus_follows_mouse(); +void set_focus_follows_mouse(bool follow); +bool focus_follows_mouse(); enum mode_mouse { B_NORMAL_MOUSE = 0, @@ -307,8 +307,8 @@ B_INSTANT_WARP_MOUSE = 7 }; -_IMPEXP_BE void set_mouse_mode(mode_mouse mode); -_IMPEXP_BE mode_mouse mouse_mode(); +void set_mouse_mode(mode_mouse mode); +mode_mouse mouse_mode(); enum color_which { B_PANEL_BACKGROUND_COLOR = 1, @@ -350,10 +350,10 @@ B_WINDOW_INACTIVE_TEXT_COLOR = 24 }; -_IMPEXP_BE rgb_color ui_color(color_which which); -_IMPEXP_BE void set_ui_color(const color_which &which, +rgb_color ui_color(color_which which); +void set_ui_color(const color_which &which, const rgb_color &color); -_IMPEXP_BE rgb_color tint_color(rgb_color color, float tint); +rgb_color tint_color(rgb_color color, float tint); extern "C" status_t _init_interface_kit_(); /* effects on standard gray level */ Modified: haiku/trunk/headers/os/interface/ListItem.h =================================================================== --- haiku/trunk/headers/os/interface/ListItem.h 2007-10-15 19:56:05 UTC (rev 22576) +++ haiku/trunk/headers/os/interface/ListItem.h 2007-10-15 20:13:55 UTC (rev 22577) @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku, Inc. All Rights Reserved. + * Copyright 2006-2007, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. */ #ifndef _LIST_ITEM_H @@ -10,6 +10,7 @@ #include class BFont; +class BList; class BMessage; class BOutlineListView; class BView; Modified: haiku/trunk/headers/os/interface/Menu.h =================================================================== --- haiku/trunk/headers/os/interface/Menu.h 2007-10-15 19:56:05 UTC (rev 22576) +++ haiku/trunk/headers/os/interface/Menu.h 2007-10-15 20:13:55 UTC (rev 22577) @@ -10,8 +10,9 @@ #include #include +class BMenu; +class BMenuBar; class BMenuItem; -class BMenuBar; namespace BPrivate { Modified: haiku/trunk/headers/os/interface/Picture.h =================================================================== --- haiku/trunk/headers/os/interface/Picture.h 2007-10-15 19:56:05 UTC (rev 22576) +++ haiku/trunk/headers/os/interface/Picture.h 2007-10-15 20:13:55 UTC (rev 22577) @@ -33,7 +33,7 @@ #include #include - +class BDataIO; class BView; struct _BPictureExtent_; Modified: haiku/trunk/headers/os/interface/PrintJob.h =================================================================== --- haiku/trunk/headers/os/interface/PrintJob.h 2007-10-15 19:56:05 UTC (rev 22576) +++ haiku/trunk/headers/os/interface/PrintJob.h 2007-10-15 20:13:55 UTC (rev 22577) @@ -15,6 +15,7 @@ #include /* For convenience */ #include +class BFile; class BView; /*----------------------------------------------------------------*/ Modified: haiku/trunk/headers/os/interface/Screen.h =================================================================== --- haiku/trunk/headers/os/interface/Screen.h 2007-10-15 19:56:05 UTC (rev 22576) +++ haiku/trunk/headers/os/interface/Screen.h 2007-10-15 20:13:55 UTC (rev 22577) @@ -12,6 +12,7 @@ #include +class BBitmap; class BWindow; namespace BPrivate { Modified: haiku/trunk/headers/os/interface/Shape.h =================================================================== --- haiku/trunk/headers/os/interface/Shape.h 2007-10-15 19:56:05 UTC (rev 22576) +++ haiku/trunk/headers/os/interface/Shape.h 2007-10-15 20:13:55 UTC (rev 22577) @@ -1,96 +1,90 @@ /* - * Copyright 2006, Haiku, Inc. All Rights Reserved. + * Copyright 2006-2007, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. */ - #ifndef _SHAPE_H #define _SHAPE_H + #include #include +class BPoint; +class BRect; +class BShape; + namespace BPrivate { class ServerLink; class PicturePlayer; }; -/*----------------------------------------------------------------*/ -/*----- BShapeIterator class -------------------------------------*/ - class BShapeIterator { - public: BShapeIterator(); -virtual ~BShapeIterator(); + virtual ~BShapeIterator(); -virtual status_t IterateMoveTo(BPoint *point); -virtual status_t IterateLineTo(int32 lineCount, BPoint *linePts); -virtual status_t IterateBezierTo(int32 bezierCount, BPoint *bezierPts); -virtual status_t IterateClose(); + virtual status_t IterateMoveTo(BPoint *point); + virtual status_t IterateLineTo(int32 lineCount, BPoint *linePts); + virtual status_t IterateBezierTo(int32 bezierCount, BPoint *bezierPts); + virtual status_t IterateClose(); - status_t Iterate(BShape *shape); + status_t Iterate(BShape *shape); private: + virtual void _ReservedShapeIterator1(); [... truncated: 4005 lines follow ...] From korli at mail.berlios.de Tue Oct 16 00:35:53 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Tue, 16 Oct 2007 00:35:53 +0200 Subject: [Haiku-commits] r22578 - in haiku/trunk: headers/os/app headers/os/mail headers/os/media headers/os/storage src/kits/tracker Message-ID: <200710152235.l9FMZrJx010138@sheep.berlios.de> Author: korli Date: 2007-10-16 00:35:52 +0200 (Tue, 16 Oct 2007) New Revision: 22578 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22578&view=rev Modified: haiku/trunk/headers/os/app/Roster.h haiku/trunk/headers/os/mail/MailAttachment.h haiku/trunk/headers/os/media/MediaNode.h haiku/trunk/headers/os/media/Sound.h haiku/trunk/headers/os/storage/Directory.h haiku/trunk/headers/os/storage/File.h haiku/trunk/headers/os/storage/Node.h haiku/trunk/src/kits/tracker/FindPanel.h haiku/trunk/src/kits/tracker/InfoWindow.h Log: fix a bit of gcc4 build Modified: haiku/trunk/headers/os/app/Roster.h =================================================================== --- haiku/trunk/headers/os/app/Roster.h 2007-10-15 20:13:55 UTC (rev 22577) +++ haiku/trunk/headers/os/app/Roster.h 2007-10-15 22:35:52 UTC (rev 22578) @@ -13,6 +13,7 @@ #include #include +class BFile; class BMimeType; class BNodeInfo; Modified: haiku/trunk/headers/os/mail/MailAttachment.h =================================================================== --- haiku/trunk/headers/os/mail/MailAttachment.h 2007-10-15 20:13:55 UTC (rev 22577) +++ haiku/trunk/headers/os/mail/MailAttachment.h 2007-10-15 22:35:52 UTC (rev 22578) @@ -11,6 +11,8 @@ #include #include +class BFile; + class BMailAttachment : public BMailComponent { public: virtual void SetFileName(const char *name) = 0; Modified: haiku/trunk/headers/os/media/MediaNode.h =================================================================== --- haiku/trunk/headers/os/media/MediaNode.h 2007-10-15 20:13:55 UTC (rev 22577) +++ haiku/trunk/headers/os/media/MediaNode.h 2007-10-15 22:35:52 UTC (rev 22578) @@ -20,6 +20,7 @@ #include class BBufferConsumer; +class BBufferProducer; class BControllable; class BFileInterface; class BMediaAddOn; Modified: haiku/trunk/headers/os/media/Sound.h =================================================================== --- haiku/trunk/headers/os/media/Sound.h 2007-10-15 20:13:55 UTC (rev 22577) +++ haiku/trunk/headers/os/media/Sound.h 2007-10-15 22:35:52 UTC (rev 22578) @@ -8,6 +8,7 @@ class BMediaFile; class BSoundFile; +class BSoundPlayer; struct entry_ref; namespace BPrivate { Modified: haiku/trunk/headers/os/storage/Directory.h =================================================================== --- haiku/trunk/headers/os/storage/Directory.h 2007-10-15 20:13:55 UTC (rev 22577) +++ haiku/trunk/headers/os/storage/Directory.h 2007-10-15 22:35:52 UTC (rev 22578) @@ -10,6 +10,7 @@ #include #include +class BFile; class BSymLink; Modified: haiku/trunk/headers/os/storage/File.h =================================================================== --- haiku/trunk/headers/os/storage/File.h 2007-10-15 20:13:55 UTC (rev 22577) +++ haiku/trunk/headers/os/storage/File.h 2007-10-15 22:35:52 UTC (rev 22578) @@ -10,6 +10,9 @@ #include +class BEntry; + + class BFile : public BNode, public BPositionIO { public: BFile(); Modified: haiku/trunk/headers/os/storage/Node.h =================================================================== --- haiku/trunk/headers/os/storage/Node.h 2007-10-15 20:13:55 UTC (rev 22577) +++ haiku/trunk/headers/os/storage/Node.h 2007-10-15 22:35:52 UTC (rev 22578) @@ -9,6 +9,7 @@ #include class BDirectory; +class BEntry; class BString; struct entry_ref; Modified: haiku/trunk/src/kits/tracker/FindPanel.h =================================================================== --- haiku/trunk/src/kits/tracker/FindPanel.h 2007-10-15 20:13:55 UTC (rev 22577) +++ haiku/trunk/src/kits/tracker/FindPanel.h 2007-10-15 22:35:52 UTC (rev 22578) @@ -54,6 +54,7 @@ class BCheckBox; class BMenuField; class BFile; +class BPopUpMenu; namespace BPrivate { Modified: haiku/trunk/src/kits/tracker/InfoWindow.h =================================================================== --- haiku/trunk/src/kits/tracker/InfoWindow.h 2007-10-15 20:13:55 UTC (rev 22577) +++ haiku/trunk/src/kits/tracker/InfoWindow.h 2007-10-15 22:35:52 UTC (rev 22578) @@ -44,6 +44,7 @@ #include "Utilities.h" +class BFilePanel; class BMenuField; namespace BPrivate { From axeld at mail.berlios.de Tue Oct 16 00:56:38 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 16 Oct 2007 00:56:38 +0200 Subject: [Haiku-commits] r22579 - haiku/trunk/headers/os/add-ons/tracker Message-ID: <200710152256.l9FMucFi003876@sheep.berlios.de> Author: axeld Date: 2007-10-16 00:56:37 +0200 (Tue, 16 Oct 2007) New Revision: 22579 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22579&view=rev Removed: haiku/trunk/headers/os/add-ons/tracker/Background.h Modified: haiku/trunk/headers/os/add-ons/tracker/TrackerAddOn.h Log: * Rewrote TrackerAddOn.h header :-) * Removed Background.h - to be replaced by the one in be_apps (which has OT license) Deleted: haiku/trunk/headers/os/add-ons/tracker/Background.h Modified: haiku/trunk/headers/os/add-ons/tracker/TrackerAddOn.h =================================================================== --- haiku/trunk/headers/os/add-ons/tracker/TrackerAddOn.h 2007-10-15 22:35:52 UTC (rev 22578) +++ haiku/trunk/headers/os/add-ons/tracker/TrackerAddOn.h 2007-10-15 22:56:37 UTC (rev 22579) @@ -1,27 +1,14 @@ -/****************************************************************************** -/ -/ File: TrackerAddOn.h -/ -/ Description: Protocol for the process_refs() hook function. -/ -/ Copyright 1995-98, Be Incorporated, All Rights Reserved. -/ -*******************************************************************************/ - +/* + * Copyright (c) 2007, Haiku, Inc. + * Distributed under the terms of the MIT license. + */ #ifndef _TRACKER_ADDON_H #define _TRACKER_ADDON_H -#include +struct entry_ref; +class BMessage; -struct entry_ref; -class BMessage; +extern "C" void process_refs(entry_ref directory, BMessage* refs, + void* reserved); -/*-------------------------------------------------------------*/ -/*------- This is why you're here: ----------------------------*/ -extern "C" _EXPORT void process_refs(entry_ref dir_ref, BMessage* msg, void*); - - -/*-------------------------------------------------------------*/ -/*-------------------------------------------------------------*/ - -#endif /* _TRACKER_ADDON_H */ +#endif // _TRACKER_ADDON_H From korli at mail.berlios.de Tue Oct 16 01:03:16 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Tue, 16 Oct 2007 01:03:16 +0200 Subject: [Haiku-commits] r22580 - in haiku/trunk/src: add-ons/media/media-add-ons/mixer add-ons/print/drivers/preview apps/codycam apps/cortex/NodeManager apps/deskbar apps/people preferences/screensaver Message-ID: <200710152303.l9FN3GJH009394@sheep.berlios.de> Author: korli Date: 2007-10-16 01:03:15 +0200 (Tue, 16 Oct 2007) New Revision: 22580 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22580&view=rev Modified: haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerCore.h haiku/trunk/src/add-ons/print/drivers/preview/PrinterDriver.h haiku/trunk/src/apps/codycam/CodyCam.h haiku/trunk/src/apps/cortex/NodeManager/AddOnHost.cpp haiku/trunk/src/apps/deskbar/DeskBarUtils.h haiku/trunk/src/apps/people/PeopleView.h haiku/trunk/src/preferences/screensaver/ScreenSaverWindow.h Log: more on gcc4 build fix Modified: haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerCore.h =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerCore.h 2007-10-15 22:56:37 UTC (rev 22579) +++ haiku/trunk/src/add-ons/media/media-add-ons/mixer/MixerCore.h 2007-10-15 23:03:15 UTC (rev 22580) @@ -12,6 +12,7 @@ #include class AudioMixer; +class BBufferGroup; class MixerInput; class MixerOutput; class Resampler; Modified: haiku/trunk/src/add-ons/print/drivers/preview/PrinterDriver.h =================================================================== --- haiku/trunk/src/add-ons/print/drivers/preview/PrinterDriver.h 2007-10-15 22:56:37 UTC (rev 22579) +++ haiku/trunk/src/add-ons/print/drivers/preview/PrinterDriver.h 2007-10-15 23:03:15 UTC (rev 22580) @@ -16,6 +16,8 @@ #include #include "InterfaceUtils.h" +class BNode; + #ifndef ROUND_UP #define ROUND_UP(x, y) (((x) + (y) - 1) & ~((y) - 1)) #endif Modified: haiku/trunk/src/apps/codycam/CodyCam.h =================================================================== --- haiku/trunk/src/apps/codycam/CodyCam.h 2007-10-15 22:56:37 UTC (rev 22579) +++ haiku/trunk/src/apps/codycam/CodyCam.h 2007-10-15 23:03:15 UTC (rev 22580) @@ -16,6 +16,10 @@ #include "Settings.h" #include"VideoConsumer.h" + +class BMediaRoster; + + enum { msg_filename = 'file', Modified: haiku/trunk/src/apps/cortex/NodeManager/AddOnHost.cpp =================================================================== --- haiku/trunk/src/apps/cortex/NodeManager/AddOnHost.cpp 2007-10-15 22:56:37 UTC (rev 22579) +++ haiku/trunk/src/apps/cortex/NodeManager/AddOnHost.cpp 2007-10-15 23:03:15 UTC (rev 22580) @@ -1,5 +1,3 @@ -// AddOnHost.cpp - #include "AddOnHost.h" #include "AddOnHostProtocol.h" @@ -240,4 +238,3 @@ return (reply.FindInt32("error", &err) == B_OK) ? err : B_ERROR; } -// END -- AddOnHost.cpp -- \ No newline at end of file Modified: haiku/trunk/src/apps/deskbar/DeskBarUtils.h =================================================================== --- haiku/trunk/src/apps/deskbar/DeskBarUtils.h 2007-10-15 22:56:37 UTC (rev 22579) +++ haiku/trunk/src/apps/deskbar/DeskBarUtils.h 2007-10-15 23:03:15 UTC (rev 22580) @@ -37,6 +37,8 @@ #include "tracker_private.h" +class BFilePanel; + enum { msg_be_container }; Modified: haiku/trunk/src/apps/people/PeopleView.h =================================================================== --- haiku/trunk/src/apps/people/PeopleView.h 2007-10-15 22:56:37 UTC (rev 22579) +++ haiku/trunk/src/apps/people/PeopleView.h 2007-10-15 23:03:15 UTC (rev 22580) @@ -19,6 +19,7 @@ #define NAME_V 10 #define STATE_WIDTH 175 +class BPopUpMenu; class TTextControl; Modified: haiku/trunk/src/preferences/screensaver/ScreenSaverWindow.h =================================================================== --- haiku/trunk/src/preferences/screensaver/ScreenSaverWindow.h 2007-10-15 22:56:37 UTC (rev 22579) +++ haiku/trunk/src/preferences/screensaver/ScreenSaverWindow.h 2007-10-15 23:03:15 UTC (rev 22580) @@ -21,6 +21,7 @@ #include class BButton; +class BTabView; class ModulesView; class ScreenCornerSelector; From korli at mail.berlios.de Tue Oct 16 01:08:09 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Tue, 16 Oct 2007 01:08:09 +0200 Subject: [Haiku-commits] r22581 - in haiku/trunk/src/bin: coreutils/lib m4/lib Message-ID: <200710152308.l9FN89n8013726@sheep.berlios.de> Author: korli Date: 2007-10-16 01:08:08 +0200 (Tue, 16 Oct 2007) New Revision: 22581 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22581&view=rev Modified: haiku/trunk/src/bin/coreutils/lib/config.h haiku/trunk/src/bin/m4/lib/config.h Log: only define va_copy for gcc2.95 Modified: haiku/trunk/src/bin/coreutils/lib/config.h =================================================================== --- haiku/trunk/src/bin/coreutils/lib/config.h 2007-10-15 23:03:15 UTC (rev 22580) +++ haiku/trunk/src/bin/coreutils/lib/config.h 2007-10-15 23:08:08 UTC (rev 22581) @@ -1904,7 +1904,9 @@ /* #undef utime */ /* Define as a macro for copying va_list variables. */ +#if __GNUC__ < 3 #define va_copy __va_copy +#endif /* Define to empty if the keyword `volatile' does not work. Warning: valid code using `volatile' can become incorrect without. Disable with care. */ Modified: haiku/trunk/src/bin/m4/lib/config.h =================================================================== --- haiku/trunk/src/bin/m4/lib/config.h 2007-10-15 23:03:15 UTC (rev 22580) +++ haiku/trunk/src/bin/m4/lib/config.h 2007-10-15 23:08:08 UTC (rev 22581) @@ -604,4 +604,6 @@ /* #undef stack_t */ /* Define as a macro for copying va_list variables. */ +#if __GNUC__ < 3 #define va_copy gl_va_copy +#endif From axeld at mail.berlios.de Tue Oct 16 01:21:02 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 16 Oct 2007 01:21:02 +0200 Subject: [Haiku-commits] r22582 - haiku/trunk/headers/os/kernel Message-ID: <200710152321.l9FNL2Bw012886@sheep.berlios.de> Author: axeld Date: 2007-10-16 01:21:01 +0200 (Tue, 16 Oct 2007) New Revision: 22582 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22582&view=rev Modified: haiku/trunk/headers/os/kernel/image.h Log: Rewrote image.h. Modified: haiku/trunk/headers/os/kernel/image.h =================================================================== --- haiku/trunk/headers/os/kernel/image.h 2007-10-15 23:08:08 UTC (rev 22581) +++ haiku/trunk/headers/os/kernel/image.h 2007-10-15 23:21:01 UTC (rev 22582) @@ -1,37 +1,19 @@ -/****************************************************************************** -/ -/ File: image.h -/ -/ Description: Kernel interface for managing executable images. -/ -/ Copyright 1993-98, Be Incorporated -/ -******************************************************************************/ - +/* + * Copyright 2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT license. + */ #ifndef _IMAGE_H #define _IMAGE_H -#include + #include #include -#ifdef __cplusplus -extern "C" { -#endif - -/*---------------------------------------------------------*/ -/*----- Image types, info, and functions ------------------*/ - -#define B_INIT_BEFORE_FUNCTION_NAME "initialize_before" -#define B_INIT_AFTER_FUNCTION_NAME "initialize_after" -#define B_TERM_BEFORE_FUNCTION_NAME "terminate_before" -#define B_TERM_AFTER_FUNCTION_NAME "terminate_after" - typedef int32 image_id; typedef enum { - B_APP_IMAGE = 1, + B_APP_IMAGE = 1, B_LIBRARY_IMAGE, B_ADD_ON_IMAGE, B_SYSTEM_IMAGE @@ -53,60 +35,58 @@ int32 data_size; } image_info; -// flags for _kern_load_image() +// flags for clear_caches() +#define B_FLUSH_DCACHE 0x0001 /* data cache */ +#define B_FLUSH_ICACHE 0x0004 /* instruction cache */ +#define B_INVALIDATE_DCACHE 0x0002 +#define B_INVALIDATE_ICACHE 0x0008 + +// symbol types +#define B_SYMBOL_TYPE_DATA 0x1 +#define B_SYMBOL_TYPE_TEXT 0x2 +#define B_SYMBOL_TYPE_ANY 0x5 + +// initialization/termination functions of shared objects +#define B_INIT_BEFORE_FUNCTION_NAME "initialize_before" +#define B_INIT_AFTER_FUNCTION_NAME "initialize_after" +#define B_TERM_BEFORE_FUNCTION_NAME "terminate_before" +#define B_TERM_AFTER_FUNCTION_NAME "terminate_after" + +// flags for _kern_load_image() (private API) enum { - B_WAIT_TILL_LOADED = 0x01, // Wait till the loader has loaded and relocated - // (but not yet initialized) the application - // image and all dependencies. If not supplied, - // the function returns before the loader - // started to do anything at all, i.e. it - // returns success, even if the executable - // doesn't exist. + B_WAIT_TILL_LOADED = 0x01, + // Wait till the loader has loaded and relocated + // (but not yet initialized) the application + // image and all dependencies. If not supplied, + // the function returns before the loader + // started to do anything at all, i.e. it + // returns success, even if the executable + // doesn't exist. }; -extern thread_id load_image(int32 argc, const char **argv, - const char **envp); -extern image_id load_add_on(const char *path); -extern status_t unload_add_on(image_id imageID); +#ifdef __cplusplus +extern "C" { +#endif -/* private; use the macros, below */ -extern status_t _get_image_info (image_id imageID, - image_info *info, size_t size); -extern status_t _get_next_image_info (team_id team, int32 *cookie, - image_info *info, size_t size); -/* use these */ +thread_id load_image(int32 argc, const char **argv, const char **environ); +image_id load_add_on(const char *path); +status_t unload_add_on(image_id image); +status_t get_image_symbol(image_id image, const char *name, int32 symbolType, + void **_symbolLocation); +status_t get_nth_image_symbol(image_id image, int32 n, char *nameBuffer, + int32 *_nameLength, int32 *_symbolType, void **_symbolLocation); +void clear_caches(void *address, size_t length, uint32 flags); + #define get_image_info(image, info) \ - _get_image_info((image), (info), sizeof(*(info))) + _get_image_info((image), (info), sizeof(*(info))) #define get_next_image_info(team, cookie, info) \ - _get_next_image_info((team), (cookie), (info), sizeof(*(info))) + _get_next_image_info((team), (cookie), (info), sizeof(*(info))) +/* private, use the macros above */ +status_t _get_image_info (image_id image, image_info *info, size_t size); +status_t _get_next_image_info (team_id team, int32 *cookie, image_info *info, + size_t size); -/*---------------------------------------------------------*/ -/*----- symbol types and functions ------------------------*/ - -#define B_SYMBOL_TYPE_DATA 0x1 -#define B_SYMBOL_TYPE_TEXT 0x2 -#define B_SYMBOL_TYPE_ANY 0x5 - -extern status_t get_image_symbol(image_id imid, - const char *name, int32 sclass, void **ptr); -extern status_t get_nth_image_symbol(image_id imid, int32 index, - char *buf, int32 *bufsize, int32 *sclass, - void **ptr); - - -/*---------------------------------------------------------*/ -/*----- cache manipulation --------------------------------*/ - -#define B_FLUSH_DCACHE 0x0001 /* dcache = data cache */ -#define B_FLUSH_ICACHE 0x0004 /* icache = instruction cache */ -#define B_INVALIDATE_DCACHE 0x0002 -#define B_INVALIDATE_ICACHE 0x0008 - -extern void clear_caches(void *addr, size_t len, uint32 flags); - -/*---------------------------------------------------------*/ - #ifdef __cplusplus } #endif From korli at mail.berlios.de Tue Oct 16 01:47:07 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Tue, 16 Oct 2007 01:47:07 +0200 Subject: [Haiku-commits] r22583 - in haiku/trunk/src: apps/showimage preferences/backgrounds Message-ID: <200710152347.l9FNl77S016073@sheep.berlios.de> Author: korli Date: 2007-10-16 01:47:07 +0200 (Tue, 16 Oct 2007) New Revision: 22583 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22583&view=rev Modified: haiku/trunk/src/apps/showimage/Jamfile haiku/trunk/src/preferences/backgrounds/Jamfile Log: Background.h was moved to be_apps/Tracker Modified: haiku/trunk/src/apps/showimage/Jamfile =================================================================== --- haiku/trunk/src/apps/showimage/Jamfile 2007-10-15 23:21:01 UTC (rev 22582) +++ haiku/trunk/src/apps/showimage/Jamfile 2007-10-15 23:47:07 UTC (rev 22583) @@ -1,6 +1,7 @@ SubDir HAIKU_TOP src apps showimage ; UsePrivateHeaders tracker shared ; +UsePublicHeaders [ FDirName be_apps Tracker ] ; SetSubDirSupportedPlatformsBeOSCompatible ; Modified: haiku/trunk/src/preferences/backgrounds/Jamfile =================================================================== --- haiku/trunk/src/preferences/backgrounds/Jamfile 2007-10-15 23:21:01 UTC (rev 22582) +++ haiku/trunk/src/preferences/backgrounds/Jamfile 2007-10-15 23:47:07 UTC (rev 22583) @@ -4,6 +4,7 @@ AddSubDirSupportedPlatforms libbe_test ; UsePrivateHeaders shared ; +UsePublicHeaders [ FDirName be_apps Tracker ] ; Preference Backgrounds : BackgroundImage.cpp From axeld at mail.berlios.de Tue Oct 16 01:49:42 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 16 Oct 2007 01:49:42 +0200 Subject: [Haiku-commits] r22584 - haiku/trunk/src/bin/unrar Message-ID: <200710152349.l9FNngPD016149@sheep.berlios.de> Author: axeld Date: 2007-10-16 01:49:42 +0200 (Tue, 16 Oct 2007) New Revision: 22584 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22584&view=rev Modified: haiku/trunk/src/bin/unrar/Jamfile haiku/trunk/src/bin/unrar/arccmt.cpp haiku/trunk/src/bin/unrar/cmddata.cpp haiku/trunk/src/bin/unrar/dll.cpp haiku/trunk/src/bin/unrar/extract.cpp haiku/trunk/src/bin/unrar/file.cpp haiku/trunk/src/bin/unrar/filefn.cpp haiku/trunk/src/bin/unrar/find.cpp haiku/trunk/src/bin/unrar/list.cpp haiku/trunk/src/bin/unrar/model.cpp haiku/trunk/src/bin/unrar/model.hpp haiku/trunk/src/bin/unrar/pathfn.cpp haiku/trunk/src/bin/unrar/rarvm.cpp haiku/trunk/src/bin/unrar/rdwrfn.cpp haiku/trunk/src/bin/unrar/readme.txt haiku/trunk/src/bin/unrar/scantree.cpp haiku/trunk/src/bin/unrar/system.cpp haiku/trunk/src/bin/unrar/system.hpp haiku/trunk/src/bin/unrar/unpack.cpp haiku/trunk/src/bin/unrar/unpack.hpp haiku/trunk/src/bin/unrar/unpack20.cpp haiku/trunk/src/bin/unrar/unrar.rdef haiku/trunk/src/bin/unrar/version.hpp haiku/trunk/src/bin/unrar/volume.cpp Log: Updated unrar to 3.7.8, patch by Ioan Molnar - thanks! Property changes on: haiku/trunk/src/bin/unrar/Jamfile ___________________________________________________________________ Name: svn:executable - * Modified: haiku/trunk/src/bin/unrar/arccmt.cpp =================================================================== --- haiku/trunk/src/bin/unrar/arccmt.cpp 2007-10-15 23:47:07 UTC (rev 22583) +++ haiku/trunk/src/bin/unrar/arccmt.cpp 2007-10-15 23:49:42 UTC (rev 22584) @@ -46,9 +46,13 @@ uint UnpCmtLength; if (OldFormat) { +#ifdef NOCRYPT + return(false); +#else UnpCmtLength=GetByte()+(GetByte()<<8); CmtLength-=2; DataIO.SetCmt13Encryption(); +#endif } else UnpCmtLength=CommHead.UnpSize; Modified: haiku/trunk/src/bin/unrar/cmddata.cpp =================================================================== --- haiku/trunk/src/bin/unrar/cmddata.cpp 2007-10-15 23:47:07 UTC (rev 22583) +++ haiku/trunk/src/bin/unrar/cmddata.cpp 2007-10-15 23:49:42 UTC (rev 22584) @@ -466,7 +466,7 @@ case 'N': case 'X': if (Switch[1]!=0) - { + { StringList *Args=etoupper(Switch[0])=='N' ? InclArgs:ExclArgs; if (Switch[1]=='@' && !IsWildcard(Switch)) { @@ -957,7 +957,7 @@ #endif #ifndef _WIN_32 static MSGID Win32Only[]={ - MCHelpSwIEML,MCHelpSwVD,MCHelpSwAC,MCHelpSwAO,MCHelpSwOS,MCHelpSwIOFF, + MCHelpSwIEML,MCHelpSwVD,MCHelpSwAO,MCHelpSwOS,MCHelpSwIOFF, MCHelpSwEP2,MCHelpSwOC }; bool Found=false; @@ -974,6 +974,10 @@ if (Help[I]==MCHelpSwOW) continue; #endif +#if !defined(_WIN_32) && !defined(_EMX) + if (Help[I]==MCHelpSwAC) + continue; +#endif #ifndef SAVE_LINKS if (Help[I]==MCHelpSwOL) continue; @@ -1035,7 +1039,7 @@ return(true); if (InclArgs->ItemsCount()==0) return(false); - if (ExclCheckArgs(InclArgs,CheckName,CheckFullPath,MATCH_WILDSUBPATH)) + if (ExclCheckArgs(InclArgs,CheckName,false,MATCH_WILDSUBPATH)) return(false); return(true); } Modified: haiku/trunk/src/bin/unrar/dll.cpp =================================================================== --- haiku/trunk/src/bin/unrar/dll.cpp 2007-10-15 23:47:07 UTC (rev 22583) +++ haiku/trunk/src/bin/unrar/dll.cpp 2007-10-15 23:49:42 UTC (rev 22584) @@ -326,12 +326,13 @@ Data->Cmd.ProcessDataProc=ProcessDataProc; } - +#ifndef NOCRYPT void PASCAL RARSetPassword(HANDLE hArcData,char *Password) { DataSet *Data=(DataSet *)hArcData; strncpyz(Data->Cmd.Password,Password,ASIZE(Data->Cmd.Password)); } +#endif int PASCAL RARGetDllVersion() Modified: haiku/trunk/src/bin/unrar/extract.cpp =================================================================== --- haiku/trunk/src/bin/unrar/extract.cpp 2007-10-15 23:47:07 UTC (rev 22583) +++ haiku/trunk/src/bin/unrar/extract.cpp 2007-10-15 23:49:42 UTC (rev 22584) @@ -143,6 +143,11 @@ Arc.ViewComment(); + // RAR can close a corrupt encrypted archive + if (!Arc.IsOpened()) + return(EXTRACT_ARC_NEXT); + + while (1) { int Size=Arc.ReadHeader(); Modified: haiku/trunk/src/bin/unrar/file.cpp =================================================================== --- haiku/trunk/src/bin/unrar/file.cpp 2007-10-15 23:47:07 UTC (rev 22583) +++ haiku/trunk/src/bin/unrar/file.cpp 2007-10-15 23:49:42 UTC (rev 22584) @@ -253,10 +253,12 @@ bool File::Delete() { - if (HandleType!=FILE_HANDLENORMAL || !AllowDelete) + if (HandleType!=FILE_HANDLENORMAL) return(false); if (hFile!=BAD_HANDLE) Close(); + if (!AllowDelete) + return(false); return(DelFile(FileName,FileNameW)); } Modified: haiku/trunk/src/bin/unrar/filefn.cpp =================================================================== --- haiku/trunk/src/bin/unrar/filefn.cpp 2007-10-15 23:47:07 UTC (rev 22583) +++ haiku/trunk/src/bin/unrar/filefn.cpp 2007-10-15 23:49:42 UTC (rev 22584) @@ -43,7 +43,7 @@ bool CreatePath(const char *Path,const wchar *PathW,bool SkipLastName) { -#ifdef _WIN_32 +#if defined(_WIN_32) || defined(_EMX) uint DirAttr=0; #else uint DirAttr=0777; @@ -211,6 +211,7 @@ return(1457664); #elif defined(_EMX) int Drive=(!isalpha(Name[0]) || Name[1]!=':') ? 0:etoupper(Name[0])-'A'+1; +#ifndef _DJGPP if (_osmode == OS2_MODE) { FSALLOCATE fsa; @@ -221,12 +222,17 @@ return(FreeSize); } else +#endif { union REGS regs,outregs; memset(®s,0,sizeof(regs)); regs.h.ah=0x36; regs.h.dl=Drive; +#ifdef _DJGPP + int86 (0x21,®s,&outregs); +#else _int86 (0x21,®s,&outregs); +#endif if (outregs.x.ax==0xffff) return(1457664); Int64 FreeSize=outregs.x.ax*outregs.x.cx; Modified: haiku/trunk/src/bin/unrar/find.cpp =================================================================== --- haiku/trunk/src/bin/unrar/find.cpp 2007-10-15 23:47:07 UTC (rev 22583) +++ haiku/trunk/src/bin/unrar/find.cpp 2007-10-15 23:49:42 UTC (rev 22584) @@ -162,7 +162,7 @@ return(false); } #ifdef _DJGPP - fd->FileAttr=chmod(FindMask,0); + fd->FileAttr=_chmod(FindMask,0); #elif defined(_EMX) fd->FileAttr=st.st_attr; #else Modified: haiku/trunk/src/bin/unrar/list.cpp =================================================================== --- haiku/trunk/src/bin/unrar/list.cpp 2007-10-15 23:47:07 UTC (rev 22583) +++ haiku/trunk/src/bin/unrar/list.cpp 2007-10-15 23:49:42 UTC (rev 22584) @@ -38,6 +38,11 @@ if (!Bare) { Arc.ViewComment(); + + // RAR can close a corrupt encrypted archive + if (!Arc.IsOpened()) + break; + mprintf("\n"); if (Arc.Solid) mprintf(St(MListSolid)); Modified: haiku/trunk/src/bin/unrar/model.cpp =================================================================== --- haiku/trunk/src/bin/unrar/model.cpp 2007-10-15 23:47:07 UTC (rev 22583) +++ haiku/trunk/src/bin/unrar/model.cpp 2007-10-15 23:49:42 UTC (rev 22584) @@ -527,6 +527,16 @@ +// reset PPM variables after data error allowing safe resuming +// of further data processing +void ModelPPM::CleanUp() +{ + SubAlloc.StopSubAllocator(); + SubAlloc.StartSubAllocator(1); + StartModelRare(2); +} + + bool ModelPPM::DecodeInit(Unpack *UnpackRead,int &EscChar) { int MaxOrder=UnpackRead->GetChar(); Modified: haiku/trunk/src/bin/unrar/model.hpp =================================================================== --- haiku/trunk/src/bin/unrar/model.hpp 2007-10-15 23:47:07 UTC (rev 22583) +++ haiku/trunk/src/bin/unrar/model.hpp 2007-10-15 23:49:42 UTC (rev 22584) @@ -124,6 +124,7 @@ inline void ClearMask(); public: ModelPPM(); + void CleanUp(); // reset PPM variables after data error bool DecodeInit(Unpack *UnpackRead,int &EscChar); int DecodeChar(); }; Modified: haiku/trunk/src/bin/unrar/pathfn.cpp =================================================================== --- haiku/trunk/src/bin/unrar/pathfn.cpp 2007-10-15 23:47:07 UTC (rev 22583) +++ haiku/trunk/src/bin/unrar/pathfn.cpp 2007-10-15 23:49:42 UTC (rev 22584) @@ -334,6 +334,7 @@ strcpy(RARFileName,Path); if (Number!=0) return(false); +#ifndef _DJGPP if (_osmode==OS2_MODE) { PTIB ptib; @@ -342,6 +343,7 @@ DosQueryModuleName(ppib->pib_hmte,NM,Path); } else +#endif strcpy(Path,RARFileName); RemoveNameFromPath(Path); return(true); @@ -476,8 +478,12 @@ if (Name[0] && Name[1] && strchr(Name+2,':')!=NULL) return(false); for (const char *s=Name;*s!=0;s=charnext(s)) + { if (*s<32) return(false); + if (*s==' ' && IsPathDiv(s[1])) + return(false); + } #endif return(*Name!=0 && strpbrk(Name,"?*<>|\"")==NULL); } @@ -496,6 +502,8 @@ #ifndef _UNIX if (s-Name>1 && *s==':') *s='_'; + if (*s==' ' && IsPathDiv(s[1])) + *s='_'; #endif } } Modified: haiku/trunk/src/bin/unrar/rarvm.cpp =================================================================== --- haiku/trunk/src/bin/unrar/rarvm.cpp 2007-10-15 23:47:07 UTC (rev 22583) +++ haiku/trunk/src/bin/unrar/rarvm.cpp 2007-10-15 23:49:42 UTC (rev 22584) @@ -179,8 +179,10 @@ VM_PreparedCommand *Cmd=PreparedCode; while (1) { +#ifndef NORARVM uint *Op1=GetOperand(&Cmd->Op1); uint *Op2=GetOperand(&Cmd->Op2); +#endif switch(Cmd->OpCode) { #ifndef NORARVM @@ -506,7 +508,7 @@ SET_VALUE(Cmd->ByteMode,Op1,Result); } break; -#endif +#endif // for #ifndef NORARVM case VM_RET: if (R[7]>=VM_MEMSIZE) return(true); @@ -767,6 +769,8 @@ case VM_CMP: Cmd->OpCode=Cmd->ByteMode ? VM_CMPB:VM_CMPD; continue; + default: + break; } if ((VM_CmdFlags[Cmd->OpCode] & VMCF_CHFLAGS)==0) continue; @@ -801,6 +805,8 @@ case VM_NEG: Cmd->OpCode=Cmd->ByteMode ? VM_NEGB:VM_NEGD; continue; + default: + break; } } } @@ -843,12 +849,12 @@ int DataSize=R[4]; uint FileOffset=R[6]; - if (DataSize>=VM_GLOBALMEMADDR) + if (DataSize>=VM_GLOBALMEMADDR || DataSize<4) break; const int FileSize=0x1000000; byte CmpByte2=FilterType==VMSF_E8E9 ? 0xe9:0xe8; - for (uint CurPos=0;CurPos=VM_GLOBALMEMADDR) + if (DataSize>=VM_GLOBALMEMADDR || DataSize<21) break; - uint CurPos=0; + int CurPos=0; FileOffset>>=4; Modified: haiku/trunk/src/bin/unrar/rdwrfn.cpp =================================================================== --- haiku/trunk/src/bin/unrar/rdwrfn.cpp 2007-10-15 23:47:07 UTC (rev 22583) +++ haiku/trunk/src/bin/unrar/rdwrfn.cpp 2007-10-15 23:49:42 UTC (rev 22584) @@ -62,9 +62,13 @@ PackedCRC=CRC(PackedCRC,ReadAddr,ReadSize); } CurUnpRead+=RetCode; + TotalRead+=RetCode; +#ifndef NOVOLUME + // these variable are not used below in NOVOLUME mode, so it is better + // to exclude these commands to avoid compiler warnings ReadAddr+=RetCode; - TotalRead+=RetCode; Count-=RetCode; +#endif UnpPackedSize-=RetCode; if (UnpPackedSize == 0 && UnpVolume) { @@ -230,7 +234,7 @@ } -#ifndef SFX_MODULE +#if !defined(SFX_MODULE) && !defined(NOCRYPT) void ComprDataIO::SetAV15Encryption() { Decryption=15; @@ -239,7 +243,7 @@ #endif -#ifndef SFX_MODULE +#if !defined(SFX_MODULE) && !defined(NOCRYPT) void ComprDataIO::SetCmt13Encryption() { Decryption=13; Modified: haiku/trunk/src/bin/unrar/readme.txt =================================================================== --- haiku/trunk/src/bin/unrar/readme.txt 2007-10-15 23:47:07 UTC (rev 22583) +++ haiku/trunk/src/bin/unrar/readme.txt 2007-10-15 23:49:42 UTC (rev 22584) @@ -47,6 +47,7 @@ Steve Reid SHA-1 hash function Marcus Herbert makefile.unix file Tomasz Klim fixes for libunrar.so + Robert Riebisch makefile.dj and patches for DJGPP 4. Legal stuff Modified: haiku/trunk/src/bin/unrar/scantree.cpp =================================================================== --- haiku/trunk/src/bin/unrar/scantree.cpp 2007-10-15 23:47:07 UTC (rev 22583) +++ haiku/trunk/src/bin/unrar/scantree.cpp 2007-10-15 23:49:42 UTC (rev 22584) @@ -154,8 +154,19 @@ bool Error=FindData->Error; #ifdef _WIN_32 - if (Error && strstr(CurMask,"System Volume Information\\")!=NULL) - Error=false; + if (Error) + { + // Do not display an error if we cannot scan contents of reparse + // point. Vista contains a lot of reparse (or junction) points, + // which are not accessible. + if ((FindData->FileAttr & FILE_ATTRIBUTE_REPARSE_POINT)!=0) + Error=false; + + // Do not display an error if we cannot scan contents of + // "System Volume Information" folder. Normally it is not accessible. + if (strstr(CurMask,"System Volume Information\\")!=NULL) + Error=false; + } #endif if (Cmd!=NULL && Cmd->ExclCheck(CurMask,true)) Modified: haiku/trunk/src/bin/unrar/system.cpp =================================================================== --- haiku/trunk/src/bin/unrar/system.cpp 2007-10-15 23:47:07 UTC (rev 22583) +++ haiku/trunk/src/bin/unrar/system.cpp 2007-10-15 23:49:42 UTC (rev 22584) @@ -12,11 +12,6 @@ #if !defined(SFX_MODULE) && !defined(_WIN_CE) -#if defined(_WIN_32) && !defined(BELOW_NORMAL_PRIORITY_CLASS) -#define BELOW_NORMAL_PRIORITY_CLASS 0x00004000 -#define ABOVE_NORMAL_PRIORITY_CLASS 0x00008000 -#endif - void SetPriority(int Priority) { #ifdef _WIN_32 @@ -61,6 +56,11 @@ } SetPriorityClass(GetCurrentProcess(),PriorityClass); SetThreadPriority(GetCurrentThread(),PriorityLevel); + +// background mode for Vista, too slow for real life use +// if (WinNT()>=6 && Priority==1) +// SetPriorityClass(GetCurrentProcess(),PROCESS_MODE_BACKGROUND_BEGIN); + #endif } #endif @@ -79,12 +79,6 @@ #if defined(_WIN_32) && !defined(_WIN_CE) && !defined(SFX_MODULE) && !defined(SHELL_EXT) -#ifndef SHTDN_REASON_MAJOR_APPLICATION -#define SHTDN_REASON_MAJOR_APPLICATION 0x00040000 -#define SHTDN_REASON_FLAG_PLANNED 0x80000000 -#define SHTDN_REASON_MINOR_MAINTENANCE 0x00000001 -#endif - void Shutdown() { HANDLE hToken; Modified: haiku/trunk/src/bin/unrar/system.hpp =================================================================== --- haiku/trunk/src/bin/unrar/system.hpp 2007-10-15 23:47:07 UTC (rev 22583) +++ haiku/trunk/src/bin/unrar/system.hpp 2007-10-15 23:49:42 UTC (rev 22584) @@ -1,6 +1,22 @@ #ifndef _RAR_SYSTEM_ #define _RAR_SYSTEM_ +#ifdef _WIN_32 +#ifndef BELOW_NORMAL_PRIORITY_CLASS +#define BELOW_NORMAL_PRIORITY_CLASS 0x00004000 +#define ABOVE_NORMAL_PRIORITY_CLASS 0x00008000 +#endif +#ifndef PROCESS_MODE_BACKGROUND_BEGIN +#define PROCESS_MODE_BACKGROUND_BEGIN 0x00100000 +#define PROCESS_MODE_BACKGROUND_END 0x00200000 +#endif +#ifndef SHTDN_REASON_MAJOR_APPLICATION +#define SHTDN_REASON_MAJOR_APPLICATION 0x00040000 +#define SHTDN_REASON_FLAG_PLANNED 0x80000000 +#define SHTDN_REASON_MINOR_MAINTENANCE 0x00000001 +#endif +#endif + void InitSystemOptions(int SleepTime); void SetPriority(int Priority); void Wait(); Modified: haiku/trunk/src/bin/unrar/unpack.cpp =================================================================== --- haiku/trunk/src/bin/unrar/unpack.cpp 2007-10-15 23:47:07 UTC (rev 22583) +++ haiku/trunk/src/bin/unrar/unpack.cpp 2007-10-15 23:49:42 UTC (rev 22584) @@ -43,6 +43,12 @@ ExternalWindow=true; } UnpInitData(false); + +#ifndef SFX_MODULE + // RAR 1.5 decompression initialization + OldUnpInitData(false); + InitHuff(); +#endif } @@ -190,9 +196,6 @@ return; } - if (PPMError) - return; - while (true) { UnpPtr&=MAXWINMASK; @@ -218,7 +221,11 @@ int Ch=PPM.DecodeChar(); if (Ch==-1) { - PPMError=true; + PPM.CleanUp(); + + // turn off PPM compression mode in case of error, so UnRAR will + // call PPM.DecodeInit in case it needs to turn it on back later. + UnpBlockType=BLOCK_LZ; break; } if (Ch==PPMEscChar) @@ -935,13 +942,18 @@ LastDist=LastLength=0; // memset(Window,0,MAXWINSIZE); memset(UnpOldTable,0,sizeof(UnpOldTable)); + memset(&LD,0,sizeof(LD)); + memset(&DD,0,sizeof(DD)); + memset(&LDD,0,sizeof(LDD)); + memset(&RD,0,sizeof(RD)); + memset(&BD,0,sizeof(BD)); UnpPtr=WrPtr=0; PPMEscChar=2; + UnpBlockType=BLOCK_LZ; InitFilters(); } InitBitInput(); - PPMError=false; WrittenFileSize=0; ReadTop=0; ReadBorder=0; Modified: haiku/trunk/src/bin/unrar/unpack.hpp =================================================================== --- haiku/trunk/src/bin/unrar/unpack.hpp 2007-10-15 23:47:07 UTC (rev 22583) +++ haiku/trunk/src/bin/unrar/unpack.hpp 2007-10-15 23:49:42 UTC (rev 22584) @@ -159,7 +159,6 @@ bool UnpSomeRead; Int64 WrittenFileSize; bool FileExtracted; - bool PPMError; int PrevLowDist,LowDistRepCount; Modified: haiku/trunk/src/bin/unrar/unpack20.cpp =================================================================== --- haiku/trunk/src/bin/unrar/unpack20.cpp 2007-10-15 23:47:07 UTC (rev 22583) +++ haiku/trunk/src/bin/unrar/unpack20.cpp 2007-10-15 23:49:42 UTC (rev 22584) @@ -269,10 +269,12 @@ { if (!Solid) { - UnpChannelDelta=UnpCurChannel=0; + UnpAudioBlock=UnpChannelDelta=UnpCurChannel=0; UnpChannels=1; + memset(AudV,0,sizeof(AudV)); memset(UnpOldTable20,0,sizeof(UnpOldTable20)); + memset(MD,0,sizeof(MD)); } } Modified: haiku/trunk/src/bin/unrar/unrar.rdef =================================================================== --- haiku/trunk/src/bin/unrar/unrar.rdef 2007-10-15 23:47:07 UTC (rev 22583) +++ haiku/trunk/src/bin/unrar/unrar.rdef 2007-10-15 23:49:42 UTC (rev 22584) @@ -5,9 +5,9 @@ resource app_version { major = 3, middle = 7, - minor = 6, + minor = 8, variety = 0, internal = 0, - short_info = "3.76", - long_info = "3.76 Alexander Roshal" + short_info = "3.78", + long_info = "3.78 Alexander Roshal" }; Property changes on: haiku/trunk/src/bin/unrar/unrar.rdef ___________________________________________________________________ Name: svn:executable - * Modified: haiku/trunk/src/bin/unrar/version.hpp =================================================================== --- haiku/trunk/src/bin/unrar/version.hpp 2007-10-15 23:47:07 UTC (rev 22583) +++ haiku/trunk/src/bin/unrar/version.hpp 2007-10-15 23:49:42 UTC (rev 22584) @@ -1,6 +1,6 @@ #define RARVER_MAJOR 3 -#define RARVER_MINOR 70 -#define RARVER_BETA 0 -#define RARVER_DAY 22 -#define RARVER_MONTH 5 +#define RARVER_MINOR 71 +#define RARVER_BETA 1 +#define RARVER_DAY 10 +#define RARVER_MONTH 9 #define RARVER_YEAR 2007 Modified: haiku/trunk/src/bin/unrar/volume.cpp =================================================================== --- haiku/trunk/src/bin/unrar/volume.cpp 2007-10-15 23:47:07 UTC (rev 22583) +++ haiku/trunk/src/bin/unrar/volume.cpp 2007-10-15 23:49:42 UTC (rev 22584) @@ -97,7 +97,7 @@ break; } } -#else +#else // RARDLL #if !defined(SFX_MODULE) && !defined(_WIN_CE) if (!RecoveryDone) @@ -123,8 +123,8 @@ FailedOpen=true; break; } +#endif // RARDLL *NextNameW=0; -#endif } if (FailedOpen) { From axeld at mail.berlios.de Tue Oct 16 01:53:57 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 16 Oct 2007 01:53:57 +0200 Subject: [Haiku-commits] r22585 - haiku/trunk/src/add-ons/accelerants/radeon Message-ID: <200710152353.l9FNrvFM016364@sheep.berlios.de> Author: axeld Date: 2007-10-16 01:53:57 +0200 (Tue, 16 Oct 2007) New Revision: 22585 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22585&view=rev Modified: haiku/trunk/src/add-ons/accelerants/radeon/GetAccelerantHook.c haiku/trunk/src/add-ons/accelerants/radeon/GetModeInfo.c haiku/trunk/src/add-ons/accelerants/radeon/generic.h Log: The Radeon driver should now support returning EDID information as well - not yet tested, though. Modified: haiku/trunk/src/add-ons/accelerants/radeon/GetAccelerantHook.c =================================================================== --- haiku/trunk/src/add-ons/accelerants/radeon/GetAccelerantHook.c 2007-10-15 23:49:42 UTC (rev 22584) +++ haiku/trunk/src/add-ons/accelerants/radeon/GetAccelerantHook.c 2007-10-15 23:53:57 UTC (rev 22585) @@ -1,14 +1,13 @@ /* - Copyright (c) 2002, Thomas Kurschel - + * Copyright (c) 2002, Thomas Kurschel + * Distributed under the terms of the MIT License. + */ - Part of Radeon accelerant - +/*! Contains entry point to get public functions. (directly copied from sample driver) */ - #include "generic.h" /* @@ -22,9 +21,11 @@ noted on a case by case below. */ -void * get_accelerant_hook(uint32 feature, void *data) { +void * +get_accelerant_hook(uint32 feature, void *data) +{ (void)data; - + switch (feature) { /* These definitions are out of pure lazyness. @@ -59,6 +60,8 @@ HOOK(MOVE_DISPLAY); HOOK(SET_INDEXED_COLORS); //HOOK(GET_TIMING_CONSTRAINTS); + case B_GET_EDID_INFO: + return (void*)radeon_get_edid_info; HOOK(DPMS_CAPABILITIES); HOOK(DPMS_MODE); @@ -103,8 +106,6 @@ #undef HOOK #undef ZERO } -/* -Return a null pointer for any feature we don't understand. -*/ - return 0; + + return NULL; } Modified: haiku/trunk/src/add-ons/accelerants/radeon/GetModeInfo.c =================================================================== --- haiku/trunk/src/add-ons/accelerants/radeon/GetModeInfo.c 2007-10-15 23:49:42 UTC (rev 22584) +++ haiku/trunk/src/add-ons/accelerants/radeon/GetModeInfo.c 2007-10-15 23:53:57 UTC (rev 22585) @@ -1,52 +1,52 @@ /* - Copyright (c) 2002, Thomas Kurschel - + * Copyright (c) 2002, Thomas Kurschel + * Distributed under the terms of the MIT License. + */ - Part of Radeon accelerant - - Public mode-specific info functions -*/ +/*! Public mode-specific info functions */ #include "radeon_accelerant.h" #include "GlobalData.h" #include "generic.h" + #include -// public function: return current display mode -status_t GET_DISPLAY_MODE( display_mode *current_mode ) +status_t +GET_DISPLAY_MODE(display_mode *mode) { virtual_card *vc = ai->vc; - + // TBD: there is a race condition if someone else is just setting it // we won't lock up but return non-sense - *current_mode = vc->mode; - + *mode = vc->mode; + // we hide multi-monitor-mode because :- // - we want to look like an ordinary single-screen driver // - the multi-mode is already adapted to current screen configuration, // and the mode should be configuration-independant - Radeon_HideMultiMode( vc, current_mode ); - + Radeon_HideMultiMode(vc, mode); return B_OK; } -// public function: return configuration of frame buffer -status_t GET_FRAME_BUFFER_CONFIG( frame_buffer_config *afb ) + +status_t +GET_FRAME_BUFFER_CONFIG(frame_buffer_config *afb) { virtual_card *vc = ai->vc; // TBD: race condition again - + // easy again, as the last mode set stored the info in a convienient form *afb = vc->fbc; return B_OK; } -// public function: return clock limits for given display mode -status_t GET_PIXEL_CLOCK_LIMITS(display_mode *dm, uint32 *low, uint32 *high) + +status_t +GET_PIXEL_CLOCK_LIMITS(display_mode *dm, uint32 *low, uint32 *high) { // we ignore stuff like DVI/LCD restrictions - // they are handled automatically on set_display_mode @@ -62,11 +62,38 @@ return B_OK; } + +#ifdef __HAIKU__ + +status_t +radeon_get_edid_info(void* info, size_t size, uint32* _version) +{ + disp_entity* routes = &ai->si->routing; + int32 index; + + if (size < sizeof(struct edid1_info)) + return B_BUFFER_OVERFLOW; + + if (routes->port_info[0].edid_valid) + index = 0; + else if (routes->port_info[1].edid_valid) + index = 1; + else + return B_ERROR; + + memcpy(info, &routes->port_info[index].edid, sizeof(struct edid1_info)); + *_version = EDID_VERSION_1; + return B_OK; +} + +#endif // __HAIKU__ + /* Return the semaphore id that will be used to signal a vertical retrace occured. */ -sem_id ACCELERANT_RETRACE_SEMAPHORE(void) +sem_id +ACCELERANT_RETRACE_SEMAPHORE(void) { virtual_card *vc = ai->vc; @@ -80,15 +107,14 @@ // with multi-monitor mode, we have two vertical blanks! // until we find a better solution, we always return virtual port 0, // which may be either physical port 0 or 1 - int crtc_idx; - + int crtcIndex; + if( vc->used_crtc[0] ) - crtc_idx = 0; + crtcIndex = 0; else - crtc_idx = 1; - + crtcIndex = 1; + //SHOW_INFO( 3, "semaphore: %x", ai->si->ports[physical_port].vblank ); - - return ai->si->crtc[crtc_idx].vblank; - //return B_ERROR; + + return ai->si->crtc[crtcIndex].vblank; } Modified: haiku/trunk/src/add-ons/accelerants/radeon/generic.h =================================================================== --- haiku/trunk/src/add-ons/accelerants/radeon/generic.h 2007-10-15 23:49:42 UTC (rev 22584) +++ haiku/trunk/src/add-ons/accelerants/radeon/generic.h 2007-10-15 23:53:57 UTC (rev 22585) @@ -27,6 +27,7 @@ status_t MOVE_DISPLAY(uint16 h_display_start, uint16 v_display_start); status_t GET_TIMING_CONSTRAINTS(display_timing_constraints *dtc); void SET_INDEXED_COLORS(uint count, uint8 first, uint8 *color_data, uint32 flags); +status_t radeon_get_edid_info(void* info, size_t size, uint32* _version); uint32 DPMS_CAPABILITIES(void); uint32 DPMS_MODE(void); From axeld at mail.berlios.de Tue Oct 16 02:00:09 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 16 Oct 2007 02:00:09 +0200 Subject: [Haiku-commits] r22586 - haiku/trunk/src/add-ons/accelerants/radeon Message-ID: <200710160000.l9G009Gt016589@sheep.berlios.de> Author: axeld Date: 2007-10-16 02:00:09 +0200 (Tue, 16 Oct 2007) New Revision: 22586 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22586&view=rev Modified: haiku/trunk/src/add-ons/accelerants/radeon/GetAccelerantHook.c Log: Fixed build for BeOS. Modified: haiku/trunk/src/add-ons/accelerants/radeon/GetAccelerantHook.c =================================================================== --- haiku/trunk/src/add-ons/accelerants/radeon/GetAccelerantHook.c 2007-10-15 23:53:57 UTC (rev 22585) +++ haiku/trunk/src/add-ons/accelerants/radeon/GetAccelerantHook.c 2007-10-16 00:00:09 UTC (rev 22586) @@ -60,8 +60,10 @@ HOOK(MOVE_DISPLAY); HOOK(SET_INDEXED_COLORS); //HOOK(GET_TIMING_CONSTRAINTS); +#ifdef __HAIKU__ case B_GET_EDID_INFO: return (void*)radeon_get_edid_info; +#endif HOOK(DPMS_CAPABILITIES); HOOK(DPMS_MODE); From bonefish at mail.berlios.de Tue Oct 16 02:32:43 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Tue, 16 Oct 2007 02:32:43 +0200 Subject: [Haiku-commits] r22587 - in haiku/trunk: headers/private/storage src/kits/storage Message-ID: <200710160032.l9G0WhLP020935@sheep.berlios.de> Author: bonefish Date: 2007-10-16 02:32:41 +0200 (Tue, 16 Oct 2007) New Revision: 22587 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22587&view=rev Modified: haiku/trunk/headers/private/storage/Partition.h haiku/trunk/src/kits/storage/Partition.cpp Log: Coding style cleanup. Modified: haiku/trunk/headers/private/storage/Partition.h =================================================================== --- haiku/trunk/headers/private/storage/Partition.h 2007-10-16 00:00:09 UTC (rev 22586) +++ haiku/trunk/headers/private/storage/Partition.h 2007-10-16 00:32:41 UTC (rev 22587) @@ -1,8 +1,7 @@ -//---------------------------------------------------------------------- -// This software is part of the Haiku distribution and is covered -// by the MIT license. -//--------------------------------------------------------------------- - +/* + * Copyright 2003-2007, Ingo Weinhold, bonefish at cs.tu-berlin.de. + * Distributed under the terms of the MIT License. + */ #ifndef _PARTITION_H #define _PARTITION_H @@ -11,6 +10,7 @@ #include #include + class BBitmap; class BDiskDevice; class BDiskDeviceParameterEditor; @@ -22,166 +22,187 @@ class BVolume; struct user_partition_data; + class BPartition { public: // Partition Info - off_t Offset() const; // 0 for devices - off_t Size() const; - off_t ContentSize() const; // 0 if uninitialized - uint32 BlockSize() const; - int32 Index() const; // 0 for devices - uint32 Status() const; + off_t Offset() const; // 0 for devices + off_t Size() const; + off_t ContentSize() const; // 0 if uninitialized + uint32 BlockSize() const; + int32 Index() const; // 0 for devices + uint32 Status() const; - bool ContainsFileSystem() const; - bool ContainsPartitioningSystem() const; + bool ContainsFileSystem() const; + bool ContainsPartitioningSystem() const; - bool IsDevice() const; - bool IsReadOnly() const; - bool IsMounted() const; - bool IsBusy() const; + bool IsDevice() const; + bool IsReadOnly() const; + bool IsMounted() const; + bool IsBusy() const; - uint32 Flags() const; + uint32 Flags() const; - const char *Name() const; - const char *ContentName() const; - const char *Type() const; // See DiskDeviceTypes.h - const char *ContentType() const; // See DiskDeviceTypes.h - partition_id ID() const; + const char* Name() const; + const char* ContentName() const; + const char* Type() const; // See DiskDeviceTypes.h + const char* ContentType() const; // See DiskDeviceTypes.h + partition_id ID() const; + const char* Parameters() const; + const char* ContentParameters() const; - const char* Parameters() const; - const char* ContentParameters() const; - - status_t GetDiskSystem(BDiskSystem *diskSystem) const; + status_t GetDiskSystem(BDiskSystem* diskSystem) const; - virtual status_t GetPath(BPath *path) const; - status_t GetVolume(BVolume *volume) const; - status_t GetIcon(BBitmap *icon, icon_size which) const; - status_t GetMountPoint(BPath *mountPoint) const; + virtual status_t GetPath(BPath* path) const; + status_t GetVolume(BVolume* volume) const; + status_t GetIcon(BBitmap* icon, icon_size which) const; + status_t GetMountPoint(BPath* mountPoint) const; - dev_t Mount(const char *mountPoint = NULL, uint32 mountFlags = 0, - const char *parameters = NULL); - status_t Unmount(uint32 unmountFlags = 0); + dev_t Mount(const char* mountPoint = NULL, + uint32 mountFlags = 0, + const char* parameters = NULL); + status_t Unmount(uint32 unmountFlags = 0); // Hierarchy Info - BDiskDevice *Device() const; - BPartition *Parent() const; - BPartition *ChildAt(int32 index) const; - int32 CountChildren() const; - BPartition *FindDescendant(partition_id id) const; + BDiskDevice* Device() const; + BPartition* Parent() const; + BPartition* ChildAt(int32 index) const; + int32 CountChildren() const; + BPartition* FindDescendant(partition_id id) const; - status_t GetPartitioningInfo(BPartitioningInfo *info) const; + status_t GetPartitioningInfo( + BPartitioningInfo* info) const; - BPartition *VisitEachChild(BDiskDeviceVisitor *visitor); - virtual BPartition *VisitEachDescendant(BDiskDeviceVisitor *visitor); + BPartition* VisitEachChild(BDiskDeviceVisitor* visitor); + virtual BPartition* VisitEachDescendant( + BDiskDeviceVisitor* visitor); // Self Modification - bool CanDefragment(bool *whileMounted = NULL) const; - status_t Defragment() const; + bool CanDefragment(bool* whileMounted = NULL) const; + status_t Defragment() const; - bool CanRepair(bool checkOnly, bool *whileMounted = NULL) const; - status_t Repair(bool checkOnly) const; + bool CanRepair(bool checkOnly, + bool* whileMounted = NULL) const; + status_t Repair(bool checkOnly) const; - bool CanResize(bool *canResizeContents = NULL, - bool *whileMounted = NULL) const; - status_t ValidateResize(off_t *size) const; - status_t Resize(off_t size); + bool CanResize(bool* canResizeContents = NULL, + bool* whileMounted = NULL) const; + status_t ValidateResize(off_t* size) const; + status_t Resize(off_t size); - bool CanMove(BObjectList *unmovableDescendants = NULL, - BObjectList *movableOnlyIfUnmounted = NULL) const; - status_t ValidateMove(off_t *newOffset) const; - status_t Move(off_t newOffset); + bool CanMove(BObjectList* + unmovableDescendants = NULL, + BObjectList* + movableOnlyIfUnmounted = NULL) const; + status_t ValidateMove(off_t* newOffset) const; + status_t Move(off_t newOffset); - bool CanSetName() const; - status_t ValidateSetName(BString* name) const; - // adjusts name to be suitable - status_t SetName(const char *name); + bool CanSetName() const; + status_t ValidateSetName(BString* name) const; + // adjusts name to be suitable + status_t SetName(const char* name); - bool CanSetContentName(bool *whileMounted = NULL) const; - status_t ValidateSetContentName(BString* name) const; - // adjusts name to be suitable - status_t SetContentName(const char *name); + bool CanSetContentName( + bool* whileMounted = NULL) const; + status_t ValidateSetContentName(BString* name) const; + // adjusts name to be suitable + status_t SetContentName(const char* name); - bool CanSetType() const; - status_t ValidateSetType(const char *type) const; - // type must be one the parent disk system's GetNextSupportedType() - // returns. - status_t SetType(const char *type); + bool CanSetType() const; + status_t ValidateSetType(const char* type) const; + // type must be one the parent disk system's + // GetNextSupportedType() returns. + status_t SetType(const char* type); - bool CanEditParameters() const; - status_t GetParameterEditor(BDiskDeviceParameterEditor **editor); - status_t SetParameters(const char *parameters); + bool CanEditParameters() const; + status_t GetParameterEditor( + BDiskDeviceParameterEditor** editor); + status_t SetParameters(const char* parameters); - bool CanEditContentParameters(bool *whileMounted = NULL) const; - status_t GetContentParameterEditor(BDiskDeviceParameterEditor **editor); - status_t SetContentParameters(const char *parameters); + bool CanEditContentParameters( + bool* whileMounted = NULL) const; + status_t GetContentParameterEditor( + BDiskDeviceParameterEditor** editor); + status_t SetContentParameters(const char* parameters); - bool CanInitialize(const char *diskSystem) const; - status_t GetInitializationParameterEditor(const char *system, - BDiskDeviceParameterEditor **editor) const; - status_t ValidateInitialize(const char *diskSystem, BString* name, - const char *parameters); - status_t Initialize(const char *diskSystem, const char *name, - const char *parameters); - status_t Uninitialize(); + bool CanInitialize(const char* diskSystem) const; + status_t GetInitializationParameterEditor( + const char* system, + BDiskDeviceParameterEditor** editor) const; + status_t ValidateInitialize(const char* diskSystem, + BString* name, const char* parameters); + status_t Initialize(const char* diskSystem, + const char* name, const char* parameters); + status_t Uninitialize(); // Modification of child partitions - bool CanCreateChild() const; - status_t GetChildCreationParameterEditor(const char *type, - BDiskDeviceParameterEditor **editor) const; - status_t ValidateCreateChild(off_t* start, off_t* size, - const char* type, BString* name, const char* parameters) const; - status_t CreateChild(off_t start, off_t size, const char* type, - const char* name, const char* parameters, BPartition** child = NULL); + bool CanCreateChild() const; + status_t GetChildCreationParameterEditor( + const char* type, + BDiskDeviceParameterEditor** editor) const; + status_t ValidateCreateChild(off_t* start, off_t* size, + const char* type, BString* name, + const char* parameters) const; + status_t CreateChild(off_t start, off_t size, + const char* type, const char* name, + const char* parameters, + BPartition** child = NULL); - bool CanDeleteChild(int32 index) const; - status_t DeleteChild(int32 index); + bool CanDeleteChild(int32 index) const; + status_t DeleteChild(int32 index); private: - class Delegate; + class Delegate; - BPartition(); - BPartition(const BPartition &); - virtual ~BPartition(); - BPartition & operator=(const BPartition &); + BPartition(); + BPartition(const BPartition&); + virtual ~BPartition(); - status_t _SetTo(BDiskDevice *device, BPartition *parent, - user_partition_data *data); - void _Unset(); - status_t _RemoveObsoleteDescendants(user_partition_data *data, - bool *updated); - status_t _Update(user_partition_data *data, bool *updated); - void _RemoveChild(int32 index); + BPartition& operator=(const BPartition&); - bool _IsShadow() const; - partition_id _ShadowID() const; - disk_system_id _DiskSystem() const; - int32 _ChangeCounter() const; + status_t _SetTo(BDiskDevice* device, BPartition* parent, + user_partition_data* data); + void _Unset(); + status_t _RemoveObsoleteDescendants( + user_partition_data* data, bool* updated); + status_t _Update(user_partition_data* data, + bool* updated); + void _RemoveChild(int32 index); - int32 _CountDescendants() const; - int32 _Level() const; - virtual bool _AcceptVisitor(BDiskDeviceVisitor *visitor, int32 level); - BPartition *_VisitEachDescendant(BDiskDeviceVisitor *visitor, - int32 level = -1); + bool _IsShadow() const; + partition_id _ShadowID() const; + disk_system_id _DiskSystem() const; + int32 _ChangeCounter() const; - const user_partition_data* _PartitionData() const; + int32 _CountDescendants() const; + int32 _Level() const; + virtual bool _AcceptVisitor(BDiskDeviceVisitor* visitor, + int32 level); + BPartition* _VisitEachDescendant( + BDiskDeviceVisitor* visitor, + int32 level = -1); - bool _HasContent() const; - bool _SupportsOperation(uint32 flag, uint32 whileMountedFlag, - bool* whileMounted) const; - bool _SupportsChildOperation(const BPartition* child, uint32 flag) const; + const user_partition_data* _PartitionData() const; - friend class BDiskDevice; - friend class BDiskSystem; - friend class BMutablePartition; + bool _HasContent() const; + bool _SupportsOperation(uint32 flag, + uint32 whileMountedFlag, + bool* whileMounted) const; + bool _SupportsChildOperation(const BPartition* child, + uint32 flag) const; - BDiskDevice* fDevice; - BPartition* fParent; - user_partition_data* fPartitionData; - Delegate* fDelegate; + friend class BDiskDevice; + friend class BDiskSystem; + friend class BMutablePartition; + + BDiskDevice* fDevice; + BPartition* fParent; + user_partition_data* fPartitionData; + Delegate* fDelegate; }; #endif // _PARTITION_H Modified: haiku/trunk/src/kits/storage/Partition.cpp =================================================================== --- haiku/trunk/src/kits/storage/Partition.cpp 2007-10-16 00:00:09 UTC (rev 22586) +++ haiku/trunk/src/kits/storage/Partition.cpp 2007-10-16 00:32:41 UTC (rev 22587) @@ -1,9 +1,6 @@ /* - * Copyright 2003-2007, Haiku, Inc. All Rights Reserved. + * Copyright 2003-2007, Ingo Weinhold, bonefish at cs.tu-berlin.de. * Distributed under the terms of the MIT License. - * - * Authors: - * Ingo Weinhold, bonefish at cs.tu-berlin.de */ #include @@ -57,9 +54,8 @@ 0, if they are equal, or a value greater than 0, if \a str1 is greater \a str2. */ -static inline -int -compare_string(const char *str1, const char *str2) +static inline int +compare_string(const char* str1, const char* str2) { if (str1 == NULL) { if (str2 == NULL) @@ -236,7 +232,7 @@ \return The name of the partition, or \c NULL, if the partitioning system does not support names. */ -const char * +const char* BPartition::Name() const { return _PartitionData()->name; @@ -244,7 +240,7 @@ // ContentName -const char * +const char* BPartition::ContentName() const { return _PartitionData()->content_name; @@ -255,7 +251,7 @@ /*! \brief Returns a human readable string for the type of the partition. \return A human readable string for the type of the partition. */ -const char * +const char* BPartition::Type() const { return _PartitionData()->type; @@ -263,7 +259,7 @@ // ContentType -const char * +const char* BPartition::ContentType() const { return _PartitionData()->content_type; @@ -305,7 +301,7 @@ // GetDiskSystem status_t -BPartition::GetDiskSystem(BDiskSystem *diskSystem) const +BPartition::GetDiskSystem(BDiskSystem* diskSystem) const { const user_partition_data* data = _PartitionData(); if (!data || !diskSystem) @@ -320,7 +316,7 @@ // GetPath status_t -BPartition::GetPath(BPath *path) const +BPartition::GetPath(BPath* path) const { // The path is constructed on the fly using our parent if (path == NULL || Parent() == NULL || Index() < 0) @@ -335,7 +331,7 @@ if (Parent()->IsDevice()) { // Our parent is a device, so we replace `raw' by our index. - const char *leaf = path->Leaf(); + const char* leaf = path->Leaf(); if (!leaf || strcmp(leaf, "raw") != B_OK) return B_ERROR; @@ -364,7 +360,7 @@ accordingly, another error code otherwise. */ status_t -BPartition::GetVolume(BVolume *volume) const +BPartition::GetVolume(BVolume* volume) const { if (volume) return B_BAD_VALUE; @@ -387,7 +383,7 @@ \return \c B_OK, if everything went fine, another error code otherwise. */ status_t -BPartition::GetIcon(BBitmap *icon, icon_size which) const +BPartition::GetIcon(BBitmap* icon, icon_size which) const { /* status_t error = (icon ? B_OK : B_BAD_VALUE); @@ -400,7 +396,7 @@ error = volume.GetIcon(icon, which); } else { // not mounted: retrieve the icon ourselves - if (BDiskDevice *device = Device()) { + if (BDiskDevice* device = Device()) { // get the icon if (error == B_OK) error = get_device_icon(device->Path(), icon, which); @@ -430,7 +426,7 @@ \return \c B_OK, if everything went fine, an error code otherwise. */ status_t -BPartition::GetMountPoint(BPath *mountPoint) const +BPartition::GetMountPoint(BPath* mountPoint) const { if (!mountPoint || !ContainsFileSystem()) return B_BAD_VALUE; @@ -447,7 +443,7 @@ // partition not mounted // get the volume name - const char *volumeName = ContentName(); + const char* volumeName = ContentName(); if (!volumeName || strlen(volumeName) == 0) volumeName = Name(); if (!volumeName || strlen(volumeName) == 0) @@ -498,8 +494,8 @@ \return \c B_OK, if everything went fine, another error code otherwise. */ dev_t -BPartition::Mount(const char *mountPoint, uint32 mountFlags, - const char *parameters) +BPartition::Mount(const char* mountPoint, uint32 mountFlags, + const char* parameters) { if (IsMounted() || !ContainsFileSystem()) return B_BAD_VALUE; @@ -582,7 +578,7 @@ /*! \brief Returns the device this partition resides on. \return The device this partition resides on. */ -BDiskDevice * +BDiskDevice* BPartition::Device() const { return fDevice; @@ -590,7 +586,7 @@ // Parent -BPartition * +BPartition* BPartition::Parent() const { return fParent; @@ -598,7 +594,7 @@ // ChildAt -BPartition * +BPartition* BPartition::ChildAt(int32 index) const { if (fDelegate) { @@ -624,7 +620,7 @@ // FindDescendant -BPartition * +BPartition* BPartition::FindDescendant(partition_id id) const { IDFinderVisitor visitor(id); @@ -634,7 +630,7 @@ // GetPartitioningInfo status_t -BPartition::GetPartitioningInfo(BPartitioningInfo *info) const +BPartition::GetPartitioningInfo(BPartitioningInfo* info) const { if (!fDelegate || !info) return B_BAD_VALUE; @@ -644,12 +640,12 @@ // VisitEachChild -BPartition * -BPartition::VisitEachChild(BDiskDeviceVisitor *visitor) +BPartition* +BPartition::VisitEachChild(BDiskDeviceVisitor* visitor) { if (visitor) { int32 level = _Level(); - for (int32 i = 0; BPartition *child = ChildAt(i); i++) { + for (int32 i = 0; BPartition* child = ChildAt(i); i++) { if (child->_AcceptVisitor(visitor, level)) return child; } @@ -659,8 +655,8 @@ // VisitEachDescendant -BPartition * -BPartition::VisitEachDescendant(BDiskDeviceVisitor *visitor) +BPartition* +BPartition::VisitEachDescendant(BDiskDeviceVisitor* visitor) { if (visitor) return _VisitEachDescendant(visitor); @@ -670,7 +666,7 @@ // CanDefragment bool -BPartition::CanDefragment(bool *whileMounted) const +BPartition::CanDefragment(bool* whileMounted) const { return _SupportsOperation(B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING, B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING_WHILE_MOUNTED, whileMounted); @@ -690,7 +686,7 @@ // CanRepair bool -BPartition::CanRepair(bool checkOnly, bool *whileMounted) const +BPartition::CanRepair(bool checkOnly, bool* whileMounted) const { uint32 flag; uint32 whileMountedFlag; @@ -719,7 +715,7 @@ // CanResize bool -BPartition::CanResize(bool *canResizeContents, bool *whileMounted) const +BPartition::CanResize(bool* canResizeContents, bool* whileMounted) const { BPartition* parent = Parent(); if (!parent) @@ -740,7 +736,7 @@ // ValidateResize status_t -BPartition::ValidateResize(off_t *size) const +BPartition::ValidateResize(off_t* size) const { BPartition* parent = Parent(); if (!parent || !fDelegate) @@ -809,8 +805,8 @@ // CanMove bool -BPartition::CanMove(BObjectList *unmovableDescendants, - BObjectList *movableOnlyIfUnmounted) const +BPartition::CanMove(BObjectList* unmovableDescendants, + BObjectList* movableOnlyIfUnmounted) const { BPartition* parent = Parent(); if (!parent || !fDelegate) @@ -823,7 +819,7 @@ bool whileMounted; bool movable = _SupportsOperation(B_DISK_SYSTEM_SUPPORTS_MOVING, - B_DISK_SYSTEM_SUPPORTS_MOVING_WHILE_MOUNTED, &whileMounted); + B_DISK_SYSTEM_SUPPORTS_MOVING_WHILE_MOUNTED, &whileMounted); if (!movable) return false; @@ -842,7 +838,7 @@ // ValidateMove status_t -BPartition::ValidateMove(off_t *offset) const +BPartition::ValidateMove(off_t* offset) const { BPartition* parent = Parent(); if (!parent || !fDelegate) @@ -897,7 +893,7 @@ return false; return parent->_SupportsChildOperation(this, - B_DISK_SYSTEM_SUPPORTS_SETTING_NAME); + B_DISK_SYSTEM_SUPPORTS_SETTING_NAME); } @@ -915,7 +911,7 @@ // SetName status_t -BPartition::SetName(const char *name) +BPartition::SetName(const char* name) { BPartition* parent = Parent(); if (!parent || !fDelegate) @@ -927,7 +923,7 @@ // CanSetContentName bool -BPartition::CanSetContentName(bool *whileMounted) const +BPartition::CanSetContentName(bool* whileMounted) const { return _SupportsOperation(B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME, B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME_WHILE_MOUNTED, @@ -948,7 +944,7 @@ // SetContentName status_t -BPartition::SetContentName(const char *name) +BPartition::SetContentName(const char* name) { if (!fDelegate) return B_BAD_VALUE; @@ -966,13 +962,13 @@ return false; return parent->_SupportsChildOperation(this, - B_DISK_SYSTEM_SUPPORTS_SETTING_TYPE); + B_DISK_SYSTEM_SUPPORTS_SETTING_TYPE); } // ValidateSetType status_t -BPartition::ValidateSetType(const char *type) const +BPartition::ValidateSetType(const char* type) const { BPartition* parent = Parent(); if (!parent || !fDelegate) @@ -984,7 +980,7 @@ // SetType status_t -BPartition::SetType(const char *type) +BPartition::SetType(const char* type) { BPartition* parent = Parent(); if (!parent || !fDelegate) @@ -1003,13 +999,13 @@ return false; return parent->_SupportsChildOperation(this, - B_DISK_SYSTEM_SUPPORTS_SETTING_PARAMETERS); + B_DISK_SYSTEM_SUPPORTS_SETTING_PARAMETERS); } // GetParameterEditor status_t -BPartition::GetParameterEditor(BDiskDeviceParameterEditor **editor) +BPartition::GetParameterEditor(BDiskDeviceParameterEditor** editor) { BPartition* parent = Parent(); if (!parent || !fDelegate) @@ -1021,7 +1017,7 @@ // SetParameters status_t -BPartition::SetParameters(const char *parameters) +BPartition::SetParameters(const char* parameters) { BPartition* parent = Parent(); if (!parent || !fDelegate) @@ -1033,7 +1029,7 @@ // CanEditContentParameters bool -BPartition::CanEditContentParameters(bool *whileMounted) const +BPartition::CanEditContentParameters(bool* whileMounted) const { return _SupportsOperation(B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS, B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS_WHILE_MOUNTED, @@ -1043,7 +1039,7 @@ // GetContentParameterEditor status_t -BPartition::GetContentParameterEditor(BDiskDeviceParameterEditor **editor) +BPartition::GetContentParameterEditor(BDiskDeviceParameterEditor** editor) { if (!fDelegate) return B_BAD_VALUE; @@ -1054,7 +1050,7 @@ // SetContentParameters status_t -BPartition::SetContentParameters(const char *parameters) +BPartition::SetContentParameters(const char* parameters) { if (!fDelegate) return B_BAD_VALUE; @@ -1065,7 +1061,7 @@ // CanInitialize bool -BPartition::CanInitialize(const char *diskSystem) const +BPartition::CanInitialize(const char* diskSystem) const { return fDelegate && fDelegate->CanInitialize(diskSystem); } @@ -1086,7 +1082,7 @@ // ValidateInitialize status_t BPartition::ValidateInitialize(const char* diskSystem, BString* name, - const char* parameters) + const char* parameters) { if (!fDelegate) return B_BAD_VALUE; @@ -1097,8 +1093,8 @@ // Initialize status_t -BPartition::Initialize(const char *diskSystem, const char *name, - const char *parameters) +BPartition::Initialize(const char* diskSystem, const char* name, + const char* parameters) { if (!fDelegate) return B_BAD_VALUE; @@ -1150,8 +1146,8 @@ // CreateChild status_t -BPartition::CreateChild(off_t offset, off_t size, const char *type, - const char* name, const char *parameters, BPartition **child) +BPartition::CreateChild(off_t offset, off_t size, const char* type, + const char* name, const char* parameters, BPartition** child) { if (!fDelegate) return B_BAD_VALUE; @@ -1205,8 +1201,8 @@ // _SetTo status_t -BPartition::_SetTo(BDiskDevice *device, BPartition *parent, - user_partition_data *data) +BPartition::_SetTo(BDiskDevice* device, BPartition* parent, + user_partition_data* data) { _Unset(); if (!device || !data) @@ -1215,10 +1211,11 @@ fDevice = device; fParent = parent; fPartitionData->user_data = this; + // create and init children status_t error = B_OK; for (int32 i = 0; error == B_OK && i < fPartitionData->child_count; i++) { - BPartition *child = new(nothrow) BPartition; + BPartition* child = new(nothrow) BPartition; if (child) { error = child->_SetTo(fDevice, this, fPartitionData->children[i]); if (error != B_OK) @@ -1226,6 +1223,7 @@ } else error = B_NO_MEMORY; } + // cleanup on error if (error != B_OK) _Unset(); @@ -1240,11 +1238,12 @@ // delete children if (fPartitionData) { for (int32 i = 0; i < fPartitionData->child_count; i++) { - if (BPartition *child = ChildAt(i)) + if (BPartition* child = ChildAt(i)) delete child; } fPartitionData->user_data = NULL; } + fDevice = NULL; fParent = NULL; fPartitionData = NULL; @@ -1253,8 +1252,7 @@ // _RemoveObsoleteDescendants status_t -BPartition::_RemoveObsoleteDescendants(user_partition_data *data, - bool *updated) +BPartition::_RemoveObsoleteDescendants(user_partition_data* data, bool* updated) { // remove all children not longer persistent // Not exactly efficient: O(n^2), considering BList::RemoveItem() @@ -1263,7 +1261,7 @@ // BPartition to remove, which makes the list operation definitely O(n). int32 count = CountChildren(); for (int32 i = count - 1; i >= 0; i--) { - BPartition *child = ChildAt(i); + BPartition* child = ChildAt(i); bool found = false; for (int32 k = data->child_count - 1; k >= 0; k--) { if (data->children[k]->id == child->ID()) { @@ -1273,12 +1271,14 @@ data->children[k], updated); if (error != B_OK) return error; + // set the user data to the BPartition object to find it // quicker later data->children[k]->user_data = child; break; } } + // if partition is obsolete, remove it if (!found) { *updated = true; @@ -1291,9 +1291,9 @@ // _Update status_t -BPartition::_Update(user_partition_data *data, bool *updated) +BPartition::_Update(user_partition_data* data, bool* updated) { - user_partition_data *oldData = fPartitionData; + user_partition_data* oldData = fPartitionData; fPartitionData = data; // check for changes if (data->offset != oldData->offset @@ -1312,11 +1312,12 @@ oldData->content_parameters)) { *updated = true; } + // add new children and update existing ones status_t error = B_OK; for (int32 i = 0; i < data->child_count; i++) { - user_partition_data *childData = data->children[i]; - BPartition *child = (BPartition*)childData->user_data; + user_partition_data* childData = data->children[i]; + BPartition* child = (BPartition*)childData->user_data; if (child) { // old partition error = child->_Update(childData, updated); @@ -1326,12 +1327,15 @@ // new partition *updated = true; child = new(nothrow) BPartition; - if (child) { - error = child->_SetTo(fDevice, this, data->children[i]); - if (error != B_OK) - delete child; - } else + if (!child) return B_NO_MEMORY; + + error = child->_SetTo(fDevice, this, data->children[i]); + if (error != B_OK) { + delete child; + return error; + } + childData->user_data = child; } } @@ -1346,8 +1350,10 @@ int32 count = CountChildren(); if (!fPartitionData || index < 0 || index >= count) return; + // delete the BPartition and its children delete ChildAt(index); + // compact the children array for (int32 i = index + 1; i < count; i++) fPartitionData->children[i - 1] = fPartitionData->children[i]; @@ -1392,7 +1398,7 @@ BPartition::_CountDescendants() const { int32 count = 1; - for (int32 i = 0; BPartition *child = ChildAt(i); i++) + for (int32 i = 0; BPartition* child = ChildAt(i); i++) count += child->_CountDescendants(); return count; } @@ -1403,7 +1409,7 @@ BPartition::_Level() const { int32 level = 0; - const BPartition *ancestor = this; + const BPartition* ancestor = this; while ((ancestor = ancestor->Parent())) level++; return level; @@ -1412,23 +1418,23 @@ // _AcceptVisitor bool -BPartition::_AcceptVisitor(BDiskDeviceVisitor *visitor, int32 level) +BPartition::_AcceptVisitor(BDiskDeviceVisitor* visitor, int32 level) { return visitor->Visit(this, level); } // _VisitEachDescendant -BPartition * -BPartition::_VisitEachDescendant(BDiskDeviceVisitor *visitor, int32 level) +BPartition* +BPartition::_VisitEachDescendant(BDiskDeviceVisitor* visitor, int32 level) { if (level < 0) level = _Level(); if (_AcceptVisitor(visitor, level)) return this; - for (int32 i = 0; BPartition *child = ChildAt(i); i++) { - if (BPartition *result = child->_VisitEachDescendant(visitor, - level + 1)) { + for (int32 i = 0; BPartition* child = ChildAt(i); i++) { + if (BPartition* result = child->_VisitEachDescendant(visitor, + level + 1)) { return result; } } From axeld at mail.berlios.de Tue Oct 16 11:45:12 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 16 Oct 2007 11:45:12 +0200 Subject: [Haiku-commits] r22588 - haiku/trunk/src/add-ons/accelerants/radeon Message-ID: <200710160945.l9G9jCPD030668@sheep.berlios.de> Author: axeld Date: 2007-10-16 11:45:11 +0200 (Tue, 16 Oct 2007) New Revision: 22588 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22588&view=rev Modified: haiku/trunk/src/add-ons/accelerants/radeon/GetAccelerantHook.c haiku/trunk/src/add-ons/accelerants/radeon/GetModeInfo.c haiku/trunk/src/add-ons/accelerants/radeon/generic.h Log: Now also implements B_GET_PREFERRED_DISPLAY_MODE for panels that don't use EDID (like obviously on my laptop). Modified: haiku/trunk/src/add-ons/accelerants/radeon/GetAccelerantHook.c =================================================================== --- haiku/trunk/src/add-ons/accelerants/radeon/GetAccelerantHook.c 2007-10-16 00:32:41 UTC (rev 22587) +++ haiku/trunk/src/add-ons/accelerants/radeon/GetAccelerantHook.c 2007-10-16 09:45:11 UTC (rev 22588) @@ -61,6 +61,8 @@ HOOK(SET_INDEXED_COLORS); //HOOK(GET_TIMING_CONSTRAINTS); #ifdef __HAIKU__ + case B_GET_PREFERRED_DISPLAY_MODE: + return (void*)radeon_get_preferred_display_mode; case B_GET_EDID_INFO: return (void*)radeon_get_edid_info; #endif Modified: haiku/trunk/src/add-ons/accelerants/radeon/GetModeInfo.c =================================================================== --- haiku/trunk/src/add-ons/accelerants/radeon/GetModeInfo.c 2007-10-16 00:32:41 UTC (rev 22587) +++ haiku/trunk/src/add-ons/accelerants/radeon/GetModeInfo.c 2007-10-16 09:45:11 UTC (rev 22588) @@ -66,6 +66,37 @@ #ifdef __HAIKU__ status_t +radeon_get_preferred_display_mode(display_mode* mode) +{ + fp_info *fpInfo = &ai->si->flatpanels[0]; + disp_entity* routes = &ai->si->routing; + uint32 i; + + if (routes->port_info[0].edid_valid || routes->port_info[1].edid_valid) { + // prefer EDID data in this case + return B_ERROR; + } + + if ((ai->vc->connected_displays & (dd_dvi | dd_dvi_ext | dd_lvds)) == 0) + return B_NOT_SUPPORTED; + + // Mode has already been added by addFPMode(), just return it + + for (i = 0; i < ai->si->mode_count; ++i) { + if (ai->mode_list[i].timing.h_display == fpInfo->panel_xres + && ai->mode_list[i].timing.v_display == fpInfo->panel_yres + && ai->mode_list[i].virtual_width == fpInfo->panel_xres + && ai->mode_list[i].virtual_height == fpInfo->panel_yres) { + memcpy(mode, &ai->mode_list[i], sizeof(display_mode)); + return B_OK; + } + } + + return B_ERROR; +} + + +status_t radeon_get_edid_info(void* info, size_t size, uint32* _version) { disp_entity* routes = &ai->si->routing; Modified: haiku/trunk/src/add-ons/accelerants/radeon/generic.h =================================================================== --- haiku/trunk/src/add-ons/accelerants/radeon/generic.h 2007-10-16 00:32:41 UTC (rev 22587) +++ haiku/trunk/src/add-ons/accelerants/radeon/generic.h 2007-10-16 09:45:11 UTC (rev 22588) @@ -27,6 +27,7 @@ status_t MOVE_DISPLAY(uint16 h_display_start, uint16 v_display_start); status_t GET_TIMING_CONSTRAINTS(display_timing_constraints *dtc); void SET_INDEXED_COLORS(uint count, uint8 first, uint8 *color_data, uint32 flags); +status_t radeon_get_preferred_display_mode(display_mode *mode); status_t radeon_get_edid_info(void* info, size_t size, uint32* _version); uint32 DPMS_CAPABILITIES(void); From mmlr at mlotz.ch Tue Oct 16 15:09:12 2007 From: mmlr at mlotz.ch (Michael Lotz) Date: Tue, 16 Oct 2007 15:09:12 +0200 Subject: [Haiku-commits] r22564 - haiku/trunk/docs/user/app In-Reply-To: <200710151149.l9FBnviG029142@sheep.berlios.de> References: <200710151149.l9FBnviG029142@sheep.berlios.de> Message-ID: <20071016125924.M25842@mlotz.ch> Hi Niels > Phase I of the Message.dox file Some input from my side: After reading the introduction I see that you focus heavily on the message delivery and the BMessage used as a real "messages". While this is certainly one central point of BMessages they are, from an technical point of view, mostly storage containers which enable easy and quick access to named and typed fields. A common usage of BMessages which is often forgotten for example is to save settings files or archives of some sort. If I'm not mistaken also some file formats (WonderBrush?) are based on BMessage. Otherwise it looks good (as far as I have read). Notify me when you need me to review the document. I know that I'm still lacking behind on the USB documentation review and I'm sorry for that BTW. Regards Michael From axeld at mail.berlios.de Tue Oct 16 18:52:35 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 16 Oct 2007 18:52:35 +0200 Subject: [Haiku-commits] r22589 - in haiku/trunk: headers/private/graphics/intel_extreme src/add-ons/kernel/drivers/graphics/intel_extreme Message-ID: <200710161652.l9GGqZxc022185@sheep.berlios.de> Author: axeld Date: 2007-10-16 18:52:34 +0200 (Tue, 16 Oct 2007) New Revision: 22589 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22589&view=rev Modified: haiku/trunk/headers/private/graphics/intel_extreme/intel_extreme.h haiku/trunk/src/add-ons/kernel/drivers/graphics/intel_extreme/intel_extreme.cpp haiku/trunk/src/add-ons/kernel/drivers/graphics/intel_extreme/intel_extreme_private.h Log: Allocating additional memory should now work on the i965 as well (but bad things will happen on earlier i9xx chips for now...). Not yet tested. Modified: haiku/trunk/headers/private/graphics/intel_extreme/intel_extreme.h =================================================================== --- haiku/trunk/headers/private/graphics/intel_extreme/intel_extreme.h 2007-10-16 09:45:11 UTC (rev 22588) +++ haiku/trunk/headers/private/graphics/intel_extreme/intel_extreme.h 2007-10-16 16:52:34 UTC (rev 22589) @@ -158,7 +158,10 @@ #define INTEL_PAGE_TABLE_CONTROL 0x02020 #define INTEL_PAGE_TABLE_ERROR 0x02024 #define INTEL_HARDWARE_STATUS_PAGE 0x02080 -#define INTEL_GTT_BASE 0x10000 // (- 0x2ffff) +#define i830_GTT_BASE 0x10000 // (- 0x2ffff) +#define i830_GTT_SIZE 0x20000 +#define i965_GTT_BASE 0x80000 // (- 0xfffff) +#define i965_GTT_SIZE 0x80000 #define GTT_ENTRY_VALID 0x01 #define GTT_ENTRY_LOCAL_MEMORY 0x02 Modified: haiku/trunk/src/add-ons/kernel/drivers/graphics/intel_extreme/intel_extreme.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/graphics/intel_extreme/intel_extreme.cpp 2007-10-16 09:45:11 UTC (rev 22588) +++ haiku/trunk/src/add-ons/kernel/drivers/graphics/intel_extreme/intel_extreme.cpp 2007-10-16 16:52:34 UTC (rev 22589) @@ -191,7 +191,7 @@ static void set_gtt_entry(intel_info &info, uint32 offset, uint8 *physicalAddress) { - write32(info.registers + INTEL_GTT_BASE + (offset >> 10), + write32(info.gtt_base + (offset >> 10), (uint32)physicalAddress | GTT_ENTRY_VALID); } @@ -391,6 +391,21 @@ if (info.memory_manager == NULL) return B_NO_MEMORY; + if ((info.device_type & INTEL_TYPE_9xx) != 0) { + if ((info.device_type & INTEL_TYPE_GROUP_MASK) == INTEL_TYPE_965) { + info.gtt_base = info.registers + i965_GTT_BASE; + info.gtt_size = i965_GTT_SIZE; + } else { + // TODO: map it in??? + info.gtt_base = (uint8*)info.pci->u.h0.base_register_sizes[3]; + info.gtt_size = i830_GTT_SIZE; + // TODO: for now... + } + } else { + info.gtt_base = info.registers + i830_GTT_BASE; + info.gtt_size = i830_GTT_SIZE; + } + // reserve ring buffer memory (currently, this memory is placed in // the graphics memory), but this could bring us problems with // write combining... @@ -474,11 +489,11 @@ physical_entry physicalEntry; get_memory_map(additionalMemory + offset - stolenSize, totalSize - offset, &physicalEntry, 1); - + for (size_t i = 0; i < physicalEntry.size; i += B_PAGE_SIZE) { set_gtt_entry(info, offset + i, (uint8 *)physicalEntry.address + i); } - + offset += physicalEntry.size; } } Modified: haiku/trunk/src/add-ons/kernel/drivers/graphics/intel_extreme/intel_extreme_private.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/graphics/intel_extreme/intel_extreme_private.h 2007-10-16 09:45:11 UTC (rev 22588) +++ haiku/trunk/src/add-ons/kernel/drivers/graphics/intel_extreme/intel_extreme_private.h 2007-10-16 16:52:34 UTC (rev 22589) @@ -29,6 +29,8 @@ struct overlay_registers *overlay_registers; // update buffer, shares an area with shared_info + uint8 *gtt_base; + size_t gtt_size; uint8 *graphics_memory; area_id graphics_memory_area; area_id additional_memory_area; From korli at mail.berlios.de Tue Oct 16 21:02:29 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Tue, 16 Oct 2007 21:02:29 +0200 Subject: [Haiku-commits] r22590 - haiku/trunk/src/kits/media Message-ID: <200710161902.l9GJ2Tba009123@sheep.berlios.de> Author: korli Date: 2007-10-16 21:02:28 +0200 (Tue, 16 Oct 2007) New Revision: 22590 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22590&view=rev Modified: haiku/trunk/src/kits/media/OldBufferStream.h Log: fix gcc4 build Modified: haiku/trunk/src/kits/media/OldBufferStream.h =================================================================== --- haiku/trunk/src/kits/media/OldBufferStream.h 2007-10-16 16:52:34 UTC (rev 22589) +++ haiku/trunk/src/kits/media/OldBufferStream.h 2007-10-16 19:02:28 UTC (rev 22590) @@ -1,310 +1,314 @@ -/****************************************************************************** - - File: BufferStream.h - - Copyright 1995-97, Be Incorporated - -******************************************************************************/ -#ifndef _BUFFER_STREAM_H -#define _BUFFER_STREAM_H - -#include -#include -#include -#include -#include -#include - -/* ================ - Per-subscriber information. - ================ */ - -struct _sbuf_info; - -typedef struct _sub_info { - _sub_info *fNext; /* next subscriber in the stream*/ - _sub_info *fPrev; /* previous subscriber in the stream */ - _sbuf_info *fRel; /* next buf to be released */ - _sbuf_info *fAcq; /* next buf to be acquired */ - sem_id fSem; /* semaphore used for blocking */ - bigtime_t fTotalTime; /* accumulated time between acq/rel */ - int32 fHeld; /* # of buffers acq'd but not yet rel'd */ - sem_id fBlockedOn; /* the semaphore being waited on */ - /* or B_BAD_SEM_ID if not blocked */ -} *subscriber_id; - - -/* ================ - Per-buffer information - ================ */ - -typedef struct _sbuf_info { - _sbuf_info *fNext; /* next "newer" buffer in the chain */ - subscriber_id fAvailTo; /* next subscriber to acquire this buffer */ - subscriber_id fHeldBy; /* subscriber that's acquired this buffer */ - bigtime_t fAcqTime; /* time at which this buffer was acquired */ - area_id fAreaID; /* for system memory allocation calls */ - char *fAddress; - int32 fSize; /* usable portion can be smaller than ... */ - int32 fAreaSize; /* ... the size of the area. */ - bool fIsFinal; /* TRUE => stream is stopping */ -} *buffer_id; - - -/* ================ - Interface definition for BBufferStream class - ================ */ - -/* We've chosen B_MAX_SUBSCRIBER_COUNT and B_MAX_BUFFER_COUNT to be small - * enough so that a BBufferStream structure fits in one 4096 byte page. - */ -#define B_MAX_SUBSCRIBER_COUNT 52 -#define B_MAX_BUFFER_COUNT 32 - -class BBufferStream; -class BBufferStreamManager; - -typedef BBufferStream* stream_id; // for now - - -class BAbstractBufferStream -{ -public: - - virtual status_t GetStreamParameters(size_t *bufferSize, - int32 *bufferCount, - bool *isRunning, - int32 *subscriberCount) const; - - virtual status_t SetStreamBuffers(size_t bufferSize, - int32 bufferCount); - - virtual status_t StartStreaming(); - virtual status_t StopStreaming(); - -protected: - -virtual void _ReservedAbstractBufferStream1(); -virtual void _ReservedAbstractBufferStream2(); -virtual void _ReservedAbstractBufferStream3(); -virtual void _ReservedAbstractBufferStream4(); - - friend class BSubscriber; - friend class BBufferStreamManager; - - virtual stream_id StreamID() const; - /* stream identifier for direct access */ - - /* Create or delete a subscriber id for subsequent operations */ - virtual status_t Subscribe(char *name, - subscriber_id *subID, - sem_id semID); - virtual status_t Unsubscribe(subscriber_id subID); - -/* Enter into or quit the stream */ - virtual status_t EnterStream(subscriber_id subID, - subscriber_id neighbor, - bool before); - - virtual status_t ExitStream(subscriber_id subID); - - virtual BMessenger* Server() const; /* message pipe to server */ - status_t SendRPC(BMessage* msg, BMessage* reply = NULL) const; -}; - - -class BBufferStream : public BAbstractBufferStream -{ -public: - - BBufferStream(size_t headerSize, - BBufferStreamManager* controller, - BSubscriber* headFeeder, - BSubscriber* tailFeeder); - virtual ~BBufferStream(); - -/* BBufferStreams are allocated on shared memory pages */ - void *operator new(size_t size); - void operator delete(void *stream, size_t size); - -/* Return header size */ - size_t HeaderSize() const; - -/* These four functions are delegated to the stream controller */ - status_t GetStreamParameters(size_t *bufferSize, - int32 *bufferCount, - bool *isRunning, - int32 *subscriberCount) const; - - status_t SetStreamBuffers(size_t bufferSize, - int32 bufferCount); - - status_t StartStreaming(); - status_t StopStreaming(); - -/* Get the controller for delegation */ - BBufferStreamManager *StreamManager() const; - -/* number of buffers in stream */ - int32 CountBuffers() const; - -/* Create or delete a subscriber id for subsequent operations */ - status_t Subscribe(char *name, - subscriber_id *subID, - sem_id semID); - - status_t Unsubscribe(subscriber_id subID); - -/* Enter into or quit the stream */ - status_t EnterStream(subscriber_id subID, - subscriber_id neighbor, - bool before); - - status_t ExitStream(subscriber_id subID); - -/* queries about a subscriber */ - bool IsSubscribed(subscriber_id subID); - bool IsEntered(subscriber_id subID); - - status_t SubscriberInfo(subscriber_id subID, - char** name, - stream_id* streamID, - int32* position); - -/* Force an error return of a subscriber if it's blocked */ - status_t UnblockSubscriber(subscriber_id subID); - -/* Acquire and release a buffer */ - status_t AcquireBuffer(subscriber_id subID, - buffer_id *bufID, - bigtime_t timeout); - status_t ReleaseBuffer(subscriber_id subID); - -/* Get the attributes of a particular buffer */ - size_t BufferSize(buffer_id bufID) const; - char *BufferData(buffer_id bufID) const; - bool IsFinalBuffer(buffer_id bufID) const; - -/* Get attributes of a particular subscriber */ - int32 CountBuffersHeld(subscriber_id subID); - -/* Queries for the BBufferStream */ - int32 CountSubscribers() const; - int32 CountEnteredSubscribers() const; - - subscriber_id FirstSubscriber() const; - subscriber_id LastSubscriber() const; - subscriber_id NextSubscriber(subscriber_id subID); - subscriber_id PrevSubscriber(subscriber_id subID); - -/* debugging aids */ - void PrintStream(); - void PrintBuffers(); - void PrintSubscribers(); - -/* gaining exclusive access to the BBufferStream */ - bool Lock(); - void Unlock(); - -/* introduce a new buffer into the "newest" end of the chain */ - status_t AddBuffer(buffer_id bufID); - -/* remove a buffer from the "oldest" end of the chain */ - buffer_id RemoveBuffer(bool force); - -/* allocate a buffer from shared memory and create a bufID for it. */ - buffer_id CreateBuffer(size_t size, bool isFinal); - -/* deallocate a buffer and returns its bufID to the freelist */ - void DestroyBuffer(buffer_id bufID); - -/* remove and destroy any "newest" buffers from the head of the chain - * that have not yet been claimed by any subscribers. If there are - * no subscribers, this clears the entire chain. - */ - void RescindBuffers(); - -/* ================ - Private member functions that assume locking already has been done. - ================ */ - -private: - -virtual void _ReservedBufferStream1(); -virtual void _ReservedBufferStream2(); -virtual void _ReservedBufferStream3(); -virtual void _ReservedBufferStream4(); - -/* initialize the free list of subscribers */ - void InitSubscribers(); - -/* return TRUE if subID appears valid */ - bool IsSubscribedSafe(subscriber_id subID) const; - -/* return TRUE if subID is entered into the stream */ - bool IsEnteredSafe(subscriber_id subID) const; - -/* initialize the free list of buffer IDs */ - void InitBuffers(); - -/* Wake a blocked subscriber */ - status_t WakeSubscriber(subscriber_id subID); - -/* Give subID all the buffers it can get */ - void InheritBuffers(subscriber_id subID); - -/* Relinquish any buffers held by subID */ - void BequeathBuffers(subscriber_id subID); - -/* Fast version of ReleaseBuffer() */ - status_t ReleaseBufferSafe(subscriber_id subID); - -/* Release a buffer to a subscriber */ - status_t ReleaseBufferTo(buffer_id bufID, subscriber_id subID); - -/* deallocate all buffers */ - void FreeAllBuffers(); - -/* deallocate all subscribers */ - void FreeAllSubscribers(); - -/* ================ - Private data members - ================ */ - - BLocker fLock; - area_id fAreaID; /* area id for this BBufferStream */ - BBufferStreamManager *fStreamManager; - BSubscriber *fHeadFeeder; - BSubscriber *fTailFeeder; - size_t fHeaderSize; - - /* ================ - subscribers - ================ */ - - _sub_info *fFreeSubs; /* free list of subscribers */ - _sub_info *fFirstSub; /* first entered in itinierary */ - _sub_info *fLastSub; /* last entered in itinerary */ - - sem_id fFirstSem; /* semaphore used by fFirstSub */ - int32 fSubCount; - int32 fEnteredSubCount; - - _sub_info fSubscribers[B_MAX_SUBSCRIBER_COUNT]; - - /* ================ - buffers - ================ */ - - _sbuf_info *fFreeBuffers; - _sbuf_info *fOldestBuffer; /* first in line */ - _sbuf_info *fNewestBuffer; /* fNewest->fNext = NULL */ - int32 fCountBuffers; - - _sbuf_info fBuffers[B_MAX_BUFFER_COUNT]; - - uint32 _reserved[4]; -}; - -#endif // #ifdef _BUFFER_STREAM_H +/****************************************************************************** + + File: BufferStream.h + + Copyright 1995-97, Be Incorporated + +******************************************************************************/ +#ifndef _BUFFER_STREAM_H +#define _BUFFER_STREAM_H + +#include +#include +#include +#include +#include +#include + + +class BSubscriber; + + +/* ================ + Per-subscriber information. + ================ */ + +struct _sbuf_info; + +typedef struct _sub_info { + _sub_info *fNext; /* next subscriber in the stream*/ + _sub_info *fPrev; /* previous subscriber in the stream */ + _sbuf_info *fRel; /* next buf to be released */ + _sbuf_info *fAcq; /* next buf to be acquired */ + sem_id fSem; /* semaphore used for blocking */ + bigtime_t fTotalTime; /* accumulated time between acq/rel */ + int32 fHeld; /* # of buffers acq'd but not yet rel'd */ + sem_id fBlockedOn; /* the semaphore being waited on */ + /* or B_BAD_SEM_ID if not blocked */ +} *subscriber_id; + + +/* ================ + Per-buffer information + ================ */ + +typedef struct _sbuf_info { + _sbuf_info *fNext; /* next "newer" buffer in the chain */ + subscriber_id fAvailTo; /* next subscriber to acquire this buffer */ + subscriber_id fHeldBy; /* subscriber that's acquired this buffer */ + bigtime_t fAcqTime; /* time at which this buffer was acquired */ + area_id fAreaID; /* for system memory allocation calls */ + char *fAddress; + int32 fSize; /* usable portion can be smaller than ... */ + int32 fAreaSize; /* ... the size of the area. */ + bool fIsFinal; /* TRUE => stream is stopping */ +} *buffer_id; + + +/* ================ + Interface definition for BBufferStream class + ================ */ + +/* We've chosen B_MAX_SUBSCRIBER_COUNT and B_MAX_BUFFER_COUNT to be small + * enough so that a BBufferStream structure fits in one 4096 byte page. + */ +#define B_MAX_SUBSCRIBER_COUNT 52 +#define B_MAX_BUFFER_COUNT 32 + +class BBufferStream; +class BBufferStreamManager; + +typedef BBufferStream* stream_id; // for now + + +class BAbstractBufferStream +{ +public: + + virtual status_t GetStreamParameters(size_t *bufferSize, + int32 *bufferCount, + bool *isRunning, + int32 *subscriberCount) const; + + virtual status_t SetStreamBuffers(size_t bufferSize, + int32 bufferCount); + + virtual status_t StartStreaming(); + virtual status_t StopStreaming(); + +protected: + +virtual void _ReservedAbstractBufferStream1(); +virtual void _ReservedAbstractBufferStream2(); +virtual void _ReservedAbstractBufferStream3(); +virtual void _ReservedAbstractBufferStream4(); + + friend class BSubscriber; + friend class BBufferStreamManager; + + virtual stream_id StreamID() const; + /* stream identifier for direct access */ + + /* Create or delete a subscriber id for subsequent operations */ + virtual status_t Subscribe(char *name, + subscriber_id *subID, + sem_id semID); + virtual status_t Unsubscribe(subscriber_id subID); + +/* Enter into or quit the stream */ + virtual status_t EnterStream(subscriber_id subID, + subscriber_id neighbor, + bool before); + + virtual status_t ExitStream(subscriber_id subID); + + virtual BMessenger* Server() const; /* message pipe to server */ + status_t SendRPC(BMessage* msg, BMessage* reply = NULL) const; +}; + + +class BBufferStream : public BAbstractBufferStream +{ +public: + + BBufferStream(size_t headerSize, + BBufferStreamManager* controller, + BSubscriber* headFeeder, + BSubscriber* tailFeeder); + virtual ~BBufferStream(); + +/* BBufferStreams are allocated on shared memory pages */ + void *operator new(size_t size); + void operator delete(void *stream, size_t size); + +/* Return header size */ + size_t HeaderSize() const; + +/* These four functions are delegated to the stream controller */ + status_t GetStreamParameters(size_t *bufferSize, + int32 *bufferCount, + bool *isRunning, + int32 *subscriberCount) const; + + status_t SetStreamBuffers(size_t bufferSize, + int32 bufferCount); + + status_t StartStreaming(); + status_t StopStreaming(); + +/* Get the controller for delegation */ + BBufferStreamManager *StreamManager() const; + +/* number of buffers in stream */ + int32 CountBuffers() const; + +/* Create or delete a subscriber id for subsequent operations */ + status_t Subscribe(char *name, + subscriber_id *subID, + sem_id semID); + + status_t Unsubscribe(subscriber_id subID); + +/* Enter into or quit the stream */ + status_t EnterStream(subscriber_id subID, + subscriber_id neighbor, + bool before); + + status_t ExitStream(subscriber_id subID); + +/* queries about a subscriber */ + bool IsSubscribed(subscriber_id subID); + bool IsEntered(subscriber_id subID); + + status_t SubscriberInfo(subscriber_id subID, + char** name, + stream_id* streamID, + int32* position); + +/* Force an error return of a subscriber if it's blocked */ + status_t UnblockSubscriber(subscriber_id subID); + +/* Acquire and release a buffer */ + status_t AcquireBuffer(subscriber_id subID, + buffer_id *bufID, + bigtime_t timeout); + status_t ReleaseBuffer(subscriber_id subID); + +/* Get the attributes of a particular buffer */ + size_t BufferSize(buffer_id bufID) const; + char *BufferData(buffer_id bufID) const; + bool IsFinalBuffer(buffer_id bufID) const; + +/* Get attributes of a particular subscriber */ + int32 CountBuffersHeld(subscriber_id subID); + +/* Queries for the BBufferStream */ + int32 CountSubscribers() const; + int32 CountEnteredSubscribers() const; + + subscriber_id FirstSubscriber() const; + subscriber_id LastSubscriber() const; + subscriber_id NextSubscriber(subscriber_id subID); + subscriber_id PrevSubscriber(subscriber_id subID); + +/* debugging aids */ + void PrintStream(); + void PrintBuffers(); + void PrintSubscribers(); + +/* gaining exclusive access to the BBufferStream */ + bool Lock(); + void Unlock(); + +/* introduce a new buffer into the "newest" end of the chain */ + status_t AddBuffer(buffer_id bufID); + +/* remove a buffer from the "oldest" end of the chain */ + buffer_id RemoveBuffer(bool force); + +/* allocate a buffer from shared memory and create a bufID for it. */ + buffer_id CreateBuffer(size_t size, bool isFinal); + +/* deallocate a buffer and returns its bufID to the freelist */ + void DestroyBuffer(buffer_id bufID); + +/* remove and destroy any "newest" buffers from the head of the chain + * that have not yet been claimed by any subscribers. If there are + * no subscribers, this clears the entire chain. + */ + void RescindBuffers(); + +/* ================ + Private member functions that assume locking already has been done. + ================ */ + +private: + +virtual void _ReservedBufferStream1(); +virtual void _ReservedBufferStream2(); +virtual void _ReservedBufferStream3(); +virtual void _ReservedBufferStream4(); + +/* initialize the free list of subscribers */ + void InitSubscribers(); + +/* return TRUE if subID appears valid */ + bool IsSubscribedSafe(subscriber_id subID) const; + +/* return TRUE if subID is entered into the stream */ + bool IsEnteredSafe(subscriber_id subID) const; + +/* initialize the free list of buffer IDs */ + void InitBuffers(); + +/* Wake a blocked subscriber */ + status_t WakeSubscriber(subscriber_id subID); + +/* Give subID all the buffers it can get */ + void InheritBuffers(subscriber_id subID); + +/* Relinquish any buffers held by subID */ + void BequeathBuffers(subscriber_id subID); + +/* Fast version of ReleaseBuffer() */ + status_t ReleaseBufferSafe(subscriber_id subID); + +/* Release a buffer to a subscriber */ + status_t ReleaseBufferTo(buffer_id bufID, subscriber_id subID); + +/* deallocate all buffers */ + void FreeAllBuffers(); + +/* deallocate all subscribers */ + void FreeAllSubscribers(); + +/* ================ + Private data members + ================ */ + + BLocker fLock; + area_id fAreaID; /* area id for this BBufferStream */ + BBufferStreamManager *fStreamManager; + BSubscriber *fHeadFeeder; + BSubscriber *fTailFeeder; + size_t fHeaderSize; + + /* ================ + subscribers + ================ */ + + _sub_info *fFreeSubs; /* free list of subscribers */ + _sub_info *fFirstSub; /* first entered in itinierary */ + _sub_info *fLastSub; /* last entered in itinerary */ + + sem_id fFirstSem; /* semaphore used by fFirstSub */ + int32 fSubCount; + int32 fEnteredSubCount; + + _sub_info fSubscribers[B_MAX_SUBSCRIBER_COUNT]; + + /* ================ + buffers + ================ */ + + _sbuf_info *fFreeBuffers; + _sbuf_info *fOldestBuffer; /* first in line */ + _sbuf_info *fNewestBuffer; /* fNewest->fNext = NULL */ + int32 fCountBuffers; + + _sbuf_info fBuffers[B_MAX_BUFFER_COUNT]; + + uint32 _reserved[4]; +}; + +#endif // #ifdef _BUFFER_STREAM_H From bonefish at mail.berlios.de Wed Oct 17 02:03:24 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 17 Oct 2007 02:03:24 +0200 Subject: [Haiku-commits] r22591 - haiku/trunk/src/kits/storage Message-ID: <200710170003.l9H03Obh010877@sheep.berlios.de> Author: bonefish Date: 2007-10-17 02:03:23 +0200 (Wed, 17 Oct 2007) New Revision: 22591 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22591&view=rev Modified: haiku/trunk/src/kits/storage/DiskSystem.cpp Log: Style cleanup. Modified: haiku/trunk/src/kits/storage/DiskSystem.cpp =================================================================== --- haiku/trunk/src/kits/storage/DiskSystem.cpp 2007-10-16 19:02:28 UTC (rev 22590) +++ haiku/trunk/src/kits/storage/DiskSystem.cpp 2007-10-17 00:03:23 UTC (rev 22591) @@ -1,7 +1,7 @@ -//---------------------------------------------------------------------- -// This software is part of the OpenBeOS distribution and is covered -// by the OpenBeOS license. -//--------------------------------------------------------------------- +/* + * Copyright 2003-2007, Ingo Weinhold, bonefish at cs.tu-berlin.de. + * Distributed under the terms of the MIT License. + */ #include #include @@ -9,6 +9,7 @@ #include #include + // constructor BDiskSystem::BDiskSystem() : fID(B_NO_INIT), @@ -18,6 +19,7 @@ { } + // copy constructor BDiskSystem::BDiskSystem(const BDiskSystem& other) : fID(other.fID), @@ -27,11 +29,13 @@ { } + // destructor BDiskSystem::~BDiskSystem() { } + // InitCheck status_t BDiskSystem::InitCheck() const @@ -39,23 +43,26 @@ return (fID > 0 ? B_OK : fID); } + // Name -const char * +const char* BDiskSystem::Name() const { return fName.String(); } + // PrettyName -const char * +const char* BDiskSystem::PrettyName() const { return fPrettyName.String(); } + // SupportsDefragmenting bool -BDiskSystem::SupportsDefragmenting(bool *whileMounted) const +BDiskSystem::SupportsDefragmenting(bool* whileMounted) const { if (InitCheck() != B_OK || !(fFlags & B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING)) { @@ -63,36 +70,44 @@ *whileMounted = false; return false; } + if (whileMounted) { *whileMounted = (IsFileSystem() && (fFlags & B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING_WHILE_MOUNTED)); } + return true; } + // SupportsRepairing bool -BDiskSystem::SupportsRepairing(bool checkOnly, bool *whileMounted) const +BDiskSystem::SupportsRepairing(bool checkOnly, bool* whileMounted) const { uint32 mainBit = B_DISK_SYSTEM_SUPPORTS_REPAIRING; uint32 mountedBit = B_DISK_SYSTEM_SUPPORTS_REPAIRING_WHILE_MOUNTED; + if (checkOnly) { mainBit = B_DISK_SYSTEM_SUPPORTS_CHECKING; mountedBit = B_DISK_SYSTEM_SUPPORTS_CHECKING_WHILE_MOUNTED; } + if (InitCheck() != B_OK || !(fFlags & mainBit)) { if (whileMounted) *whileMounted = false; return false; } + if (whileMounted) *whileMounted = (IsFileSystem() && (fFlags & mountedBit)); + return true; } + // SupportsResizing bool -BDiskSystem::SupportsResizing(bool *whileMounted) const +BDiskSystem::SupportsResizing(bool* whileMounted) const { if (InitCheck() != B_OK || !(fFlags & B_DISK_SYSTEM_SUPPORTS_RESIZING)) { @@ -100,24 +115,28 @@ *whileMounted = false; return false; } + if (whileMounted) { *whileMounted = (IsFileSystem() && (fFlags & B_DISK_SYSTEM_SUPPORTS_RESIZING_WHILE_MOUNTED)); } + return true; } + // SupportsResizingChild bool BDiskSystem::SupportsResizingChild() const { return (InitCheck() == B_OK && IsPartitioningSystem() - && (fFlags & B_DISK_SYSTEM_SUPPORTS_RESIZING_CHILD)); + && (fFlags & B_DISK_SYSTEM_SUPPORTS_RESIZING_CHILD)); } + // SupportsMoving bool -BDiskSystem::SupportsMoving(bool *whileMounted) const +BDiskSystem::SupportsMoving(bool* whileMounted) const { if (InitCheck() != B_OK || !(fFlags & B_DISK_SYSTEM_SUPPORTS_MOVING)) { @@ -125,29 +144,34 @@ *whileMounted = false; return false; } + if (whileMounted) { *whileMounted = (IsFileSystem() && (fFlags & B_DISK_SYSTEM_SUPPORTS_MOVING_WHILE_MOUNTED)); } + return true; } + // SupportsMovingChild bool BDiskSystem::SupportsMovingChild() const { return (InitCheck() == B_OK && IsPartitioningSystem() - && (fFlags & B_DISK_SYSTEM_SUPPORTS_MOVING_CHILD)); + && (fFlags & B_DISK_SYSTEM_SUPPORTS_MOVING_CHILD)); } + // SupportsName bool BDiskSystem::SupportsName() const { return (InitCheck() == B_OK && IsPartitioningSystem() - && (fFlags & B_DISK_SYSTEM_SUPPORTS_NAME)); + && (fFlags & B_DISK_SYSTEM_SUPPORTS_NAME)); } + // SupportsContentName bool BDiskSystem::SupportsContentName() const @@ -156,17 +180,19 @@ && (fFlags & B_DISK_SYSTEM_SUPPORTS_CONTENT_NAME)); } + // SupportsSettingName bool BDiskSystem::SupportsSettingName() const { return (InitCheck() == B_OK && IsPartitioningSystem() - && (fFlags & B_DISK_SYSTEM_SUPPORTS_SETTING_NAME)); + && (fFlags & B_DISK_SYSTEM_SUPPORTS_SETTING_NAME)); } + // SupportsSettingContentName bool -BDiskSystem::SupportsSettingContentName(bool *whileMounted) const +BDiskSystem::SupportsSettingContentName(bool* whileMounted) const { if (InitCheck() != B_OK || !(fFlags & B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME)) { @@ -174,33 +200,38 @@ *whileMounted = false; return false; } + if (whileMounted) { *whileMounted = (IsFileSystem() && (fFlags & B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME_WHILE_MOUNTED)); } + return true; } + // SupportsSettingType bool BDiskSystem::SupportsSettingType() const { return (InitCheck() == B_OK && IsPartitioningSystem() - && (fFlags & B_DISK_SYSTEM_SUPPORTS_SETTING_TYPE)); + && (fFlags & B_DISK_SYSTEM_SUPPORTS_SETTING_TYPE)); } + // SupportsSettingParameters bool BDiskSystem::SupportsSettingParameters() const { return (InitCheck() == B_OK && IsPartitioningSystem() - && (fFlags & B_DISK_SYSTEM_SUPPORTS_SETTING_PARAMETERS)); + && (fFlags & B_DISK_SYSTEM_SUPPORTS_SETTING_PARAMETERS)); } + // SupportsSettingContentParameters bool -BDiskSystem::SupportsSettingContentParameters(bool *whileMounted) const +BDiskSystem::SupportsSettingContentParameters(bool* whileMounted) const { if (InitCheck() != B_OK || !(fFlags & B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS)) { @@ -208,42 +239,48 @@ *whileMounted = false; return false; } + if (whileMounted) { - *whileMounted = (IsFileSystem() - && (fFlags - & B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS_WHILE_MOUNTED)); + uint32 whileMountedFlag + = B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS_WHILE_MOUNTED; + *whileMounted = (IsFileSystem() && (fFlags & whileMountedFlag)); } + return true; } + // SupportsCreatingChild bool BDiskSystem::SupportsCreatingChild() const { return (InitCheck() == B_OK && IsPartitioningSystem() - && (fFlags & B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD)); + && (fFlags & B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD)); } + // SupportsDeletingChild bool BDiskSystem::SupportsDeletingChild() const { return (InitCheck() == B_OK && IsPartitioningSystem() - && (fFlags & B_DISK_SYSTEM_SUPPORTS_DELETING_CHILD)); + && (fFlags & B_DISK_SYSTEM_SUPPORTS_DELETING_CHILD)); } + // SupportsInitializing bool BDiskSystem::SupportsInitializing() const { return (InitCheck() == B_OK - && (fFlags & B_DISK_SYSTEM_SUPPORTS_INITIALIZING)); + && (fFlags & B_DISK_SYSTEM_SUPPORTS_INITIALIZING)); } + // GetNextSupportedType status_t -BDiskSystem::GetNextSupportedType(BPartition *partition, int32 *cookie, - char *type) const +BDiskSystem::GetNextSupportedType(BPartition* partition, int32* cookie, + char* type) const { // TODO: We probably need a second method for and modify the partitioning // system module hook a little. This method takes the parent partition of @@ -261,9 +298,10 @@ partition->_ChangeCounter(), cookie, type); } + // GetTypeForContentType status_t -BDiskSystem::GetTypeForContentType(const char *contentType, char *type) const +BDiskSystem::GetTypeForContentType(const char* contentType, char* type) const { if (InitCheck() != B_OK) return InitCheck(); @@ -272,6 +310,7 @@ return _kern_get_partition_type_for_content_type(fID, contentType, type); } + // IsPartitioningSystem bool BDiskSystem::IsPartitioningSystem() const @@ -279,6 +318,7 @@ return (InitCheck() == B_OK && !(fFlags & B_DISK_SYSTEM_IS_FILE_SYSTEM)); } + // IsFileSystem bool BDiskSystem::IsFileSystem() const @@ -286,16 +326,18 @@ return (InitCheck() == B_OK && (fFlags & B_DISK_SYSTEM_IS_FILE_SYSTEM)); } + // IsSubSystemFor bool -BDiskSystem::IsSubSystemFor(BPartition *parent) const +BDiskSystem::IsSubSystemFor(BPartition* parent) const { return (InitCheck() == B_OK - && parent && parent->_IsShadow() - && _kern_is_sub_disk_system_for(fID, parent->_ShadowID(), - parent->_ChangeCounter())); + && parent && parent->_IsShadow() + && _kern_is_sub_disk_system_for(fID, parent->_ShadowID(), + parent->_ChangeCounter())); } + // = BDiskSystem& BDiskSystem::operator=(const BDiskSystem& other) @@ -308,34 +350,43 @@ return *this; } + // _SetTo status_t BDiskSystem::_SetTo(disk_system_id id) { _Unset(); + if (id < 0) return fID; + user_disk_system_info info; status_t error = _kern_get_disk_system_info(id, &info); if (error != B_OK) return (fID = error); + return _SetTo(&info); } + // _SetTo status_t -BDiskSystem::_SetTo(user_disk_system_info *info) +BDiskSystem::_SetTo(user_disk_system_info* info) { _Unset(); + if (!info) return (fID = B_BAD_VALUE); + fID = info->id; fName = info->name; fPrettyName = info->pretty_name; fFlags = info->flags; + return B_OK; } + // _Unset void BDiskSystem::_Unset() @@ -345,4 +396,3 @@ fPrettyName = (const char*)NULL; fFlags = 0; } - From bonefish at mail.berlios.de Wed Oct 17 03:01:54 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 17 Oct 2007 03:01:54 +0200 Subject: [Haiku-commits] r22592 - in haiku/trunk: headers/private/storage src/kits/storage Message-ID: <200710170101.l9H11srH016202@sheep.berlios.de> Author: bonefish Date: 2007-10-17 03:01:49 +0200 (Wed, 17 Oct 2007) New Revision: 22592 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22592&view=rev Modified: haiku/trunk/headers/private/storage/DiskSystem.h haiku/trunk/headers/private/storage/DiskSystemAddOn.h haiku/trunk/headers/private/storage/Partition.h haiku/trunk/src/kits/storage/DiskSystem.cpp haiku/trunk/src/kits/storage/DiskSystemAddOn.cpp haiku/trunk/src/kits/storage/Partition.cpp haiku/trunk/src/kits/storage/PartitionDelegate.cpp haiku/trunk/src/kits/storage/PartitionDelegate.h Log: * Moved GetNextSupportedType() and IsSubSystemFor() from BDiskSystem to BPartition and reimplemented them using the userland add-on backend instead of syscalls. As a side effect this solves the TODO I recently added in GetNextSupportedType(). * Reimplemented BDiskSystem::GetTypeForContentType() using the userland add-on backend instead of a syscall. * Moved GetTypeForContentType() and IsSubSystemFor() from BPartitionHandle to BDiskSystemAddOn. They were misplaced. Modified: haiku/trunk/headers/private/storage/DiskSystem.h =================================================================== --- haiku/trunk/headers/private/storage/DiskSystem.h 2007-10-17 00:03:23 UTC (rev 22591) +++ haiku/trunk/headers/private/storage/DiskSystem.h 2007-10-17 01:01:49 UTC (rev 22592) @@ -9,9 +9,12 @@ #include #include + class BPartition; +class BString; struct user_disk_system_info; + class BDiskSystem { public: BDiskSystem(); @@ -40,21 +43,17 @@ bool SupportsDeletingChild() const; bool SupportsInitializing() const; - status_t GetNextSupportedType(BPartition *partition, int32 *cookie, - char *type) const; - // Returns all types the disk system supports for children of the - // supplied partition. - status_t GetTypeForContentType(const char *contentType, char *type) const; + status_t GetTypeForContentType(const char *contentType, + BString* type) const; bool IsPartitioningSystem() const; bool IsFileSystem() const; - bool IsSubSystemFor(BPartition *parent) const; BDiskSystem& operator=(const BDiskSystem& other); private: status_t _SetTo(disk_system_id id); - status_t _SetTo(user_disk_system_info *info); + status_t _SetTo(const user_disk_system_info *info); void _Unset(); friend class BDiskDeviceRoster; Modified: haiku/trunk/headers/private/storage/DiskSystemAddOn.h =================================================================== --- haiku/trunk/headers/private/storage/DiskSystemAddOn.h 2007-10-17 00:03:23 UTC (rev 22591) +++ haiku/trunk/headers/private/storage/DiskSystemAddOn.h 2007-10-17 01:01:49 UTC (rev 22592) @@ -41,6 +41,10 @@ const char* name, const char* parameters, BPartitionHandle** handle); + virtual status_t GetTypeForContentType(const char* contentType, + BString* type); + virtual bool IsSubSystemFor(const BMutablePartition* child); + private: BString fName; uint32 fFlags; @@ -62,14 +66,11 @@ virtual bool SupportsInitializingChild( const BMutablePartition* child, const char* diskSystem); - virtual bool IsSubSystemFor(const BMutablePartition* child); virtual status_t GetNextSupportedType( const BMutablePartition* child, int32* cookie, BString* type); // child can be NULL - virtual status_t GetTypeForContentType(const char* contentType, - BString* type); virtual status_t GetPartitioningInfo(BPartitioningInfo* info); Modified: haiku/trunk/headers/private/storage/Partition.h =================================================================== --- haiku/trunk/headers/private/storage/Partition.h 2007-10-17 00:03:23 UTC (rev 22591) +++ haiku/trunk/headers/private/storage/Partition.h 2007-10-17 01:01:49 UTC (rev 22592) @@ -128,6 +128,18 @@ BDiskDeviceParameterEditor** editor); status_t SetContentParameters(const char* parameters); + status_t GetNextSupportedType(int32 *cookie, + BString* type) const; + // Returns all partition types for this + // partition supported by the parent disk + // system. + status_t GetNextSupportedChildType(int32 *cookie, + BString* type) const; + // Returns all partition types for a child + // of this partition supported by its disk + // system. + bool IsSubSystem(const char* diskSystem) const; + bool CanInitialize(const char* diskSystem) const; status_t GetInitializationParameterEditor( const char* system, Modified: haiku/trunk/src/kits/storage/DiskSystem.cpp =================================================================== --- haiku/trunk/src/kits/storage/DiskSystem.cpp 2007-10-17 00:03:23 UTC (rev 22591) +++ haiku/trunk/src/kits/storage/DiskSystem.cpp 2007-10-17 01:01:49 UTC (rev 22592) @@ -4,12 +4,16 @@ */ #include + +#include #include -#include #include +#include +#include "DiskSystemAddOnManager.h" + // constructor BDiskSystem::BDiskSystem() : fID(B_NO_INIT), @@ -277,37 +281,28 @@ } -// GetNextSupportedType +// GetTypeForContentType status_t -BDiskSystem::GetNextSupportedType(BPartition* partition, int32* cookie, - char* type) const +BDiskSystem::GetTypeForContentType(const char* contentType, BString* type) const { -// TODO: We probably need a second method for and modify the partitioning -// system module hook a little. This method takes the parent partition of -// a partition to be created for which we want to get supported types. It -// should also be possible to invoke it for the partition whose type to change -// though. if (InitCheck() != B_OK) return InitCheck(); - if (!cookie || !type || !partition || !partition->_IsShadow() - || partition->_DiskSystem() != fID || !IsPartitioningSystem()) { + + if (!contentType || !type || !IsPartitioningSystem()) return B_BAD_VALUE; - } - return _kern_get_next_supported_partition_type(partition->_ShadowID(), - partition->_ChangeCounter(), cookie, type); -} + // get the disk system add-on + DiskSystemAddOnManager* manager = DiskSystemAddOnManager::Default(); + BDiskSystemAddOn* addOn = manager->GetAddOn(fName.String()); + if (!addOn) + return B_ENTRY_NOT_FOUND; + status_t result = addOn->GetTypeForContentType(contentType, type); -// GetTypeForContentType -status_t -BDiskSystem::GetTypeForContentType(const char* contentType, char* type) const -{ - if (InitCheck() != B_OK) - return InitCheck(); - if (!contentType || !type || !IsPartitioningSystem()) - return B_BAD_VALUE; - return _kern_get_partition_type_for_content_type(fID, contentType, type); + // put the add-on + manager->PutAddOn(addOn); + + return result; } @@ -327,17 +322,6 @@ } -// IsSubSystemFor -bool -BDiskSystem::IsSubSystemFor(BPartition* parent) const -{ - return (InitCheck() == B_OK - && parent && parent->_IsShadow() - && _kern_is_sub_disk_system_for(fID, parent->_ShadowID(), - parent->_ChangeCounter())); -} - - // = BDiskSystem& BDiskSystem::operator=(const BDiskSystem& other) @@ -371,7 +355,7 @@ // _SetTo status_t -BDiskSystem::_SetTo(user_disk_system_info* info) +BDiskSystem::_SetTo(const user_disk_system_info* info) { _Unset(); Modified: haiku/trunk/src/kits/storage/DiskSystemAddOn.cpp =================================================================== --- haiku/trunk/src/kits/storage/DiskSystemAddOn.cpp 2007-10-17 00:03:23 UTC (rev 22591) +++ haiku/trunk/src/kits/storage/DiskSystemAddOn.cpp 2007-10-17 01:01:49 UTC (rev 22592) @@ -76,6 +76,22 @@ } +// GetTypeForContentType +status_t +BDiskSystemAddOn::GetTypeForContentType(const char* contentType, BString* type) +{ + return B_NOT_SUPPORTED; +} + + +// IsSubSystemFor +bool +BDiskSystemAddOn::IsSubSystemFor(const BMutablePartition* child) +{ + return false; +} + + // #pragma mark - BPartitionHandle @@ -126,14 +142,6 @@ } -// IsSubSystemFor -bool -BPartitionHandle::IsSubSystemFor(const BMutablePartition* child) -{ - return false; -} - - // GetNextSupportedType status_t BPartitionHandle::GetNextSupportedType(const BMutablePartition* child, @@ -143,14 +151,6 @@ } -// GetTypeForContentType -status_t -BPartitionHandle::GetTypeForContentType(const char* contentType, BString* type) -{ - return B_NOT_SUPPORTED; -} - - // GetPartitioningInfo status_t BPartitionHandle::GetPartitioningInfo(BPartitioningInfo* info) Modified: haiku/trunk/src/kits/storage/Partition.cpp =================================================================== --- haiku/trunk/src/kits/storage/Partition.cpp 2007-10-17 00:03:23 UTC (rev 22591) +++ haiku/trunk/src/kits/storage/Partition.cpp 2007-10-17 01:01:49 UTC (rev 22592) @@ -1059,6 +1059,42 @@ } +// GetNextSupportedType +status_t +BPartition::GetNextSupportedType(int32 *cookie, BString* type) const +{ + BPartition* parent = Parent(); + if (!parent || !fDelegate) + return false; + + return parent->fDelegate->GetNextSupportedChildType(fDelegate, cookie, + type); +} + + +// GetNextSupportedChildType +status_t +BPartition::GetNextSupportedChildType(int32 *cookie, BString* type) const +{ + if (!fDelegate) + return B_BAD_VALUE; + + return fDelegate->GetNextSupportedChildType(NULL, cookie, type); +} + + +// IsSubSystem +bool +BPartition::BPartition::IsSubSystem(const char* diskSystem) const +{ + BPartition* parent = Parent(); + if (!parent || !fDelegate) + return false; + + return parent->fDelegate->IsSubSystem(fDelegate, diskSystem); +} + + // CanInitialize bool BPartition::CanInitialize(const char* diskSystem) const Modified: haiku/trunk/src/kits/storage/PartitionDelegate.cpp =================================================================== --- haiku/trunk/src/kits/storage/PartitionDelegate.cpp 2007-10-17 00:03:23 UTC (rev 22591) +++ haiku/trunk/src/kits/storage/PartitionDelegate.cpp 2007-10-17 01:01:49 UTC (rev 22592) @@ -353,6 +353,38 @@ } +// GetNextSupportedChildType +status_t +BPartition::Delegate::GetNextSupportedChildType(Delegate* child, int32 *cookie, + BString* type) const +{ + if (!fPartitionHandle) + return B_NO_INIT; + + return fPartitionHandle->GetNextSupportedType( + child ? &child->fMutablePartition : NULL, cookie, type); +} + + +// IsSubSystem +bool +BPartition::Delegate::IsSubSystem(Delegate* child, const char* diskSystem) const +{ + // get the disk system add-on + DiskSystemAddOnManager* manager = DiskSystemAddOnManager::Default(); + BDiskSystemAddOn* addOn = manager->GetAddOn(diskSystem); + if (!addOn) + return false; + + bool result = addOn->IsSubSystemFor(&child->fMutablePartition); + + // put the add-on + manager->PutAddOn(addOn); + + return result; +} + + // CanInitialize bool BPartition::Delegate::CanInitialize(const char* diskSystem) const Modified: haiku/trunk/src/kits/storage/PartitionDelegate.h =================================================================== --- haiku/trunk/src/kits/storage/PartitionDelegate.h 2007-10-17 00:03:23 UTC (rev 22591) +++ haiku/trunk/src/kits/storage/PartitionDelegate.h 2007-10-17 01:01:49 UTC (rev 22592) @@ -72,6 +72,11 @@ status_t SetParameters(Delegate* child, const char* parameters); + status_t GetNextSupportedChildType(Delegate* child, + int32 *cookie, BString* type) const; + bool IsSubSystem(Delegate* child, + const char* diskSystem) const; + bool CanInitialize(const char* diskSystem) const; status_t GetInitializationParameterEditor( const char* system, From bonefish at mail.berlios.de Wed Oct 17 03:04:55 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 17 Oct 2007 03:04:55 +0200 Subject: [Haiku-commits] r22593 - in haiku/trunk: headers/private/storage src/kits/storage Message-ID: <200710170104.l9H14t5E016302@sheep.berlios.de> Author: bonefish Date: 2007-10-17 03:04:53 +0200 (Wed, 17 Oct 2007) New Revision: 22593 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22593&view=rev Modified: haiku/trunk/headers/private/storage/Partition.h haiku/trunk/src/kits/storage/Partition.cpp Log: Removed some now obsolete methods. Modified: haiku/trunk/headers/private/storage/Partition.h =================================================================== --- haiku/trunk/headers/private/storage/Partition.h 2007-10-17 01:01:49 UTC (rev 22592) +++ haiku/trunk/headers/private/storage/Partition.h 2007-10-17 01:04:53 UTC (rev 22593) @@ -186,9 +186,6 @@ void _RemoveChild(int32 index); bool _IsShadow() const; - partition_id _ShadowID() const; - disk_system_id _DiskSystem() const; - int32 _ChangeCounter() const; int32 _CountDescendants() const; int32 _Level() const; Modified: haiku/trunk/src/kits/storage/Partition.cpp =================================================================== --- haiku/trunk/src/kits/storage/Partition.cpp 2007-10-17 01:01:49 UTC (rev 22592) +++ haiku/trunk/src/kits/storage/Partition.cpp 2007-10-17 01:04:53 UTC (rev 22593) @@ -1405,30 +1405,6 @@ } -// _ShadowID -partition_id -BPartition::_ShadowID() const -{ - return (fPartitionData ? fPartitionData->shadow_id : -1); -} - - -// _DiskSystem -disk_system_id -BPartition::_DiskSystem() const -{ - return (fPartitionData ? fPartitionData->disk_system : -1); -} - - -// _ChangeCounter -int32 -BPartition::_ChangeCounter() const -{ - return (fPartitionData ? fPartitionData->change_counter : -1); -} - - // _CountDescendants int32 BPartition::_CountDescendants() const From stippi at mail.berlios.de Wed Oct 17 12:29:17 2007 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Wed, 17 Oct 2007 12:29:17 +0200 Subject: [Haiku-commits] r22594 - haiku/trunk/src/apps/mediaplayer Message-ID: <200710171029.l9HATHUe032500@sheep.berlios.de> Author: stippi Date: 2007-10-17 12:29:16 +0200 (Wed, 17 Oct 2007) New Revision: 22594 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22594&view=rev Modified: haiku/trunk/src/apps/mediaplayer/Controller.cpp haiku/trunk/src/apps/mediaplayer/Controller.h haiku/trunk/src/apps/mediaplayer/ControllerObserver.cpp haiku/trunk/src/apps/mediaplayer/ControllerObserver.h haiku/trunk/src/apps/mediaplayer/ControllerView.cpp haiku/trunk/src/apps/mediaplayer/ControllerView.h haiku/trunk/src/apps/mediaplayer/MainWin.cpp haiku/trunk/src/apps/mediaplayer/MainWin.h haiku/trunk/src/apps/mediaplayer/TransportControlGroup.cpp haiku/trunk/src/apps/mediaplayer/VolumeSlider.cpp haiku/trunk/src/apps/mediaplayer/VolumeSlider.h Log: patch by Fredrik Mod?\195?\169en with changes by myself * toggle the "marked" state of the settings menu items correctly * implement muting/unmuting the volume * implement volume up/down triggered by keyboard events * forward the skip next/previous events to the controller (various kinds of keyboard navigation or mouse wheel) * establish the notification link for volume and muted changes Modified: haiku/trunk/src/apps/mediaplayer/Controller.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/Controller.cpp 2007-10-17 01:04:53 UTC (rev 22593) +++ haiku/trunk/src/apps/mediaplayer/Controller.cpp 2007-10-17 10:29:16 UTC (rev 22594) @@ -76,6 +76,7 @@ void Controller::Listener::PlaybackStateChanged(uint32) {} void Controller::Listener::PositionChanged(float) {} void Controller::Listener::VolumeChanged(float) {} +void Controller::Listener::MutedChanged(bool) {} // #pragma mark - @@ -86,6 +87,7 @@ , fPaused(false) , fStopped(true) , fVolume(1.0) + , fMuted(false) , fRef() , fMediaFile(0) @@ -494,15 +496,60 @@ Controller::SetVolume(float value) { printf("Controller::SetVolume %.4f\n", value); - if (Lock()) { + if (!Lock()) + return; + + value = max_c(0.0, min_c(2.0, value)); + + if (fVolume != value) { + if (fMuted) + ToggleMute(); + fVolume = value; if (fSoundOutput) fSoundOutput->SetVolume(fVolume); - Unlock(); + + _NotifyVolumeChanged(fVolume); } + + Unlock(); } +void +Controller::VolumeUp() +{ + // TODO: linear <-> exponential + SetVolume(Volume() + 0.05); +} +void +Controller::VolumeDown() +{ + // TODO: linear <-> exponential + SetVolume(Volume() - 0.05); +} + +void +Controller::ToggleMute() +{ + if (!Lock()) + return; + + fMuted = !fMuted; + + if (fSoundOutput) { + if (fMuted) + fSoundOutput->SetVolume(0.0); + else + fSoundOutput->SetVolume(fVolume); + } + + _NotifyMutedChanged(fMuted); + + Unlock(); +} + + float Controller::Volume() const { @@ -1330,3 +1377,14 @@ } } + +void +Controller::_NotifyMutedChanged(bool muted) +{ + BList listeners(fListeners); + int32 count = listeners.CountItems(); + for (int32 i = 0; i < count; i++) { + Listener* listener = (Listener*)listeners.ItemAtFast(i); + listener->MutedChanged(muted); + } +} Modified: haiku/trunk/src/apps/mediaplayer/Controller.h =================================================================== --- haiku/trunk/src/apps/mediaplayer/Controller.h 2007-10-17 01:04:53 UTC (rev 22593) +++ haiku/trunk/src/apps/mediaplayer/Controller.h 2007-10-17 10:29:16 UTC (rev 22594) @@ -57,6 +57,7 @@ virtual void PlaybackStateChanged(uint32 state); virtual void PositionChanged(float position); virtual void VolumeChanged(float volume); + virtual void MutedChanged(bool muted); }; Controller(); @@ -89,6 +90,9 @@ void SetVolume(float value); float Volume() const; + void VolumeUp(); + void VolumeDown(); + void ToggleMute(); void SetPosition(float value); bool HasFile(); @@ -146,6 +150,7 @@ void _NotifyPlaybackStateChanged(); void _NotifyPositionChanged(float position); void _NotifyVolumeChanged(float volume); + void _NotifyMutedChanged(bool muted); friend class InfoWin; @@ -169,6 +174,7 @@ volatile bool fPaused; volatile bool fStopped; float fVolume; + bool fMuted; entry_ref fRef; BMediaFile * fMediaFile; Modified: haiku/trunk/src/apps/mediaplayer/ControllerObserver.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/ControllerObserver.cpp 2007-10-17 01:04:53 UTC (rev 22593) +++ haiku/trunk/src/apps/mediaplayer/ControllerObserver.cpp 2007-10-17 10:29:16 UTC (rev 22594) @@ -137,3 +137,16 @@ } +void +ControllerObserver::MutedChanged(bool muted) +{ + if (!(fObserveFlags & OBSERVE_VOLUME_CHANGES)) + return; + + BMessage message(MSG_CONTROLLER_MUTED_CHANGED); + message.AddBool("muted", muted); + + DeliverMessage(message); +} + + Modified: haiku/trunk/src/apps/mediaplayer/ControllerObserver.h =================================================================== --- haiku/trunk/src/apps/mediaplayer/ControllerObserver.h 2007-10-17 01:04:53 UTC (rev 22593) +++ haiku/trunk/src/apps/mediaplayer/ControllerObserver.h 2007-10-17 10:29:16 UTC (rev 22594) @@ -23,7 +23,8 @@ MSG_CONTROLLER_PLAYBACK_STATE_CHANGED = 'cnps', MSG_CONTROLLER_POSITION_CHANGED = 'cnpc', - MSG_CONTROLLER_VOLUME_CHANGED = 'cnvc' + MSG_CONTROLLER_VOLUME_CHANGED = 'cnvc', + MSG_CONTROLLER_MUTED_CHANGED = 'cnmc' }; enum { @@ -57,6 +58,7 @@ virtual void PlaybackStateChanged(uint32 state); virtual void PositionChanged(float position); virtual void VolumeChanged(float volume); + virtual void MutedChanged(bool muted); private: uint32 fObserveFlags; Modified: haiku/trunk/src/apps/mediaplayer/ControllerView.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/ControllerView.cpp 2007-10-17 01:04:53 UTC (rev 22593) +++ haiku/trunk/src/apps/mediaplayer/ControllerView.cpp 2007-10-17 10:29:16 UTC (rev 22594) @@ -145,7 +145,7 @@ void ControllerView::ToggleMute() { - printf("ControllerView::ToggleMute()\n"); + fController->ToggleMute(); } Modified: haiku/trunk/src/apps/mediaplayer/ControllerView.h =================================================================== --- haiku/trunk/src/apps/mediaplayer/ControllerView.h 2007-10-17 01:04:53 UTC (rev 22593) +++ haiku/trunk/src/apps/mediaplayer/ControllerView.h 2007-10-17 10:29:16 UTC (rev 22594) @@ -36,11 +36,6 @@ Playlist* playlist); ~ControllerView(); -private: - void AttachedToWindow(); - void MessageReceived(BMessage *msg); - void Draw(BRect updateRect); - // TransportControlGroup interface virtual uint32 EnabledButtons(); virtual void TogglePlaying(); @@ -53,6 +48,11 @@ virtual void ToggleMute(); virtual void PositionChanged(float value); +private: + void AttachedToWindow(); + void MessageReceived(BMessage* message); + void Draw(BRect updateRect); + // ControllerView void CheckSkippable(); Modified: haiku/trunk/src/apps/mediaplayer/MainWin.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/MainWin.cpp 2007-10-17 01:04:53 UTC (rev 22593) +++ haiku/trunk/src/apps/mediaplayer/MainWin.cpp 2007-10-17 10:29:16 UTC (rev 22594) @@ -72,8 +72,8 @@ M_PREFERENCES, M_VOLUME_UP, M_VOLUME_DOWN, - M_CHANNEL_NEXT, - M_CHANNEL_PREV, + M_SKIP_NEXT, + M_SKIP_PREV, M_ASPECT_100000_1, M_ASPECT_106666_1, M_ASPECT_109091_1, @@ -105,7 +105,8 @@ , fController(new Controller) , fControllerObserver(new ControllerObserver(this, OBSERVE_FILE_CHANGES | OBSERVE_TRACK_CHANGES - | OBSERVE_PLAYBACK_STATE_CHANGES | OBSERVE_POSITION_CHANGES)) + | OBSERVE_PLAYBACK_STATE_CHANGES | OBSERVE_POSITION_CHANGES + | OBSERVE_VOLUME_CHANGES)) , fIsFullscreen(false) , fKeepAspectRatio(true) , fAlwaysOnTop(false) @@ -168,8 +169,7 @@ // setup the playlist window now, we need to have it // running for the undo/redo playlist editing - fPlaylistWindow = new PlaylistWindow(BRect(150, 150, 400, 500), - fPlaylist, fController); + fPlaylistWindow = new PlaylistWindow(BRect(150, 150, 400, 500), fPlaylist, fController); fPlaylistWindow->Hide(); fPlaylistWindow->Show(); // this makes sure the window thread is running without @@ -315,6 +315,7 @@ void MainWin::MessageReceived(BMessage *msg) { +// msg->PrintToStream(); switch (msg->what) { case B_REFS_RECEIVED: printf("MainWin::MessageReceived: B_REFS_RECEIVED\n"); @@ -397,6 +398,18 @@ fControls->SetPosition(position); break; } + case MSG_CONTROLLER_VOLUME_CHANGED: { + float volume; + if (msg->FindFloat("volume", &volume) == B_OK) + fControls->SetVolume(volume); + break; + } + case MSG_CONTROLLER_MUTED_CHANGED: { + bool muted; + if (msg->FindBool("muted", &muted) == B_OK) + fControls->SetMuted(muted); + break; + } // menu item messages case M_FILE_NEWPLAYER: @@ -437,32 +450,26 @@ case M_TOGGLE_FULLSCREEN: _ToggleFullscreen(); -// fSettingsMenu->ItemAt(1)->SetMarked(fIsFullscreen); break; case M_TOGGLE_NO_MENU: _ToggleNoMenu(); -// fSettingsMenu->ItemAt(3)->SetMarked(fNoMenu); break; case M_TOGGLE_NO_CONTROLS: _ToggleNoControls(); -// fSettingsMenu->ItemAt(3)->SetMarked(fNoControls); break; case M_TOGGLE_NO_BORDER: _ToggleNoBorder(); -// fSettingsMenu->ItemAt(4)->SetMarked(fNoBorder); break; case M_TOGGLE_ALWAYS_ON_TOP: _ToggleAlwaysOnTop(); -// fSettingsMenu->ItemAt(5)->SetMarked(fAlwaysOnTop); break; case M_TOGGLE_KEEP_ASPECT_RATIO: _ToggleKeepAspectRatio(); -// fSettingsMenu->ItemAt(6)->SetMarked(fKeepAspectRatio); break; case M_TOGGLE_NO_BORDER_NO_MENU_NO_CONTROLS: @@ -527,47 +534,28 @@ float dx = msg->FindFloat("be:wheel_delta_x"); float dy = msg->FindFloat("be:wheel_delta_y"); bool inv = modifiers() & B_COMMAND_KEY; - if (dx > 0.1) PostMessage(inv ? M_VOLUME_DOWN : M_CHANNEL_PREV); - if (dx < -0.1) PostMessage(inv ? M_VOLUME_UP : M_CHANNEL_NEXT); - if (dy > 0.1) PostMessage(inv ? M_CHANNEL_PREV : M_VOLUME_DOWN); - if (dy < -0.1) PostMessage(inv ? M_CHANNEL_NEXT : M_VOLUME_UP); + if (dx > 0.1) PostMessage(inv ? M_VOLUME_DOWN : M_SKIP_PREV); + if (dx < -0.1) PostMessage(inv ? M_VOLUME_UP : M_SKIP_NEXT); + if (dy > 0.1) PostMessage(inv ? M_SKIP_PREV : M_VOLUME_DOWN); + if (dy < -0.1) PostMessage(inv ? M_SKIP_NEXT : M_VOLUME_UP); break; } - - case M_CHANNEL_NEXT: - { - printf("M_CHANNEL_NEXT\n"); - int chan = fController->CurrentChannel(); - if (chan != -1) { - chan++; - if (chan < fController->ChannelCount()) - SelectChannel(chan); - } +*/ + case M_SKIP_NEXT: + fControls->SkipForward(); break; - } - case M_CHANNEL_PREV: - { - printf("M_CHANNEL_PREV\n"); - int chan = fController->CurrentChannel(); - if (chan != -1) { - chan--; - if (chan >= 0) - SelectChannel(chan); - } + case M_SKIP_PREV: + fControls->SkipBackward(); break; - } case M_VOLUME_UP: - printf("M_VOLUME_UP\n"); fController->VolumeUp(); break; case M_VOLUME_DOWN: - printf("M_VOLUME_DOWN\n"); fController->VolumeDown(); break; -*/ case M_ASPECT_100000_1: VideoFormatChange(fSourceWidth, fSourceHeight, 1.0, 1.0); @@ -1145,7 +1133,7 @@ case B_UP_ARROW: if (modifiers & B_COMMAND_KEY) { - PostMessage(M_CHANNEL_NEXT); + PostMessage(M_SKIP_NEXT); } else { PostMessage(M_VOLUME_UP); } @@ -1153,7 +1141,7 @@ case B_DOWN_ARROW: if (modifiers & B_COMMAND_KEY) { - PostMessage(M_CHANNEL_PREV); + PostMessage(M_SKIP_PREV); } else { PostMessage(M_VOLUME_DOWN); } @@ -1163,7 +1151,7 @@ if (modifiers & B_COMMAND_KEY) { PostMessage(M_VOLUME_UP); } else { - PostMessage(M_CHANNEL_NEXT); + PostMessage(M_SKIP_NEXT); } return B_OK; @@ -1171,16 +1159,16 @@ if (modifiers & B_COMMAND_KEY) { PostMessage(M_VOLUME_DOWN); } else { - PostMessage(M_CHANNEL_PREV); + PostMessage(M_SKIP_PREV); } return B_OK; case B_PAGE_UP: - PostMessage(M_CHANNEL_NEXT); + PostMessage(M_SKIP_NEXT); return B_OK; case B_PAGE_DOWN: - PostMessage(M_CHANNEL_PREV); + PostMessage(M_SKIP_PREV); return B_OK; } @@ -1213,12 +1201,12 @@ case 0x39: // numeric keypad page up case 0x4a: // numeric keypad right arrow - PostMessage(M_CHANNEL_NEXT); + PostMessage(M_SKIP_NEXT); return B_OK; case 0x5a: // numeric keypad page down case 0x48: // numeric keypad left arrow - PostMessage(M_CHANNEL_PREV); + PostMessage(M_SKIP_PREV); return B_OK; } @@ -1281,6 +1269,8 @@ Show(); } + _MarkSettingsItem(M_TOGGLE_FULLSCREEN, fIsFullscreen); + printf("_ToggleFullscreen leave\n"); } @@ -1304,6 +1294,8 @@ ResizeBy(0, fControlsHeight); } + _MarkSettingsItem(M_TOGGLE_NO_CONTROLS, fNoControls); + printf("_ToggleNoControls leave\n"); } @@ -1329,6 +1321,8 @@ ResizeBy(0, fMenuBarHeight); } + _MarkSettingsItem(M_TOGGLE_NO_MENU, fNoMenu); + printf("_ToggleNoMenu leave\n"); } @@ -1336,30 +1330,30 @@ void MainWin::_ToggleNoBorder() { - printf("_ToggleNoBorder enter\n"); fNoBorder = !fNoBorder; SetLook(fNoBorder ? B_BORDERED_WINDOW_LOOK : B_TITLED_WINDOW_LOOK); - printf("_ToggleNoBorder leave\n"); + + _MarkSettingsItem(M_TOGGLE_NO_BORDER, fNoBorder); } void MainWin::_ToggleAlwaysOnTop() { - printf("_ToggleAlwaysOnTop enter\n"); fAlwaysOnTop = !fAlwaysOnTop; SetFeel(fAlwaysOnTop ? B_FLOATING_ALL_WINDOW_FEEL : B_NORMAL_WINDOW_FEEL); - printf("_ToggleAlwaysOnTop leave\n"); + + _MarkSettingsItem(M_TOGGLE_ALWAYS_ON_TOP, fAlwaysOnTop); } void MainWin::_ToggleKeepAspectRatio() { - printf("_ToggleKeepAspectRatio enter\n"); fKeepAspectRatio = !fKeepAspectRatio; FrameResized(Bounds().Width(), Bounds().Height()); - printf("_ToggleKeepAspectRatio leave\n"); + + _MarkSettingsItem(M_TOGGLE_KEEP_ASPECT_RATIO, fKeepAspectRatio); } @@ -1442,3 +1436,11 @@ } +void +MainWin::_MarkSettingsItem(uint32 command, bool mark) +{ + if (BMenuItem* item = fSettingsMenu->FindItem(command)) + item->SetMarked(mark); +} + + Modified: haiku/trunk/src/apps/mediaplayer/MainWin.h =================================================================== --- haiku/trunk/src/apps/mediaplayer/MainWin.h 2007-10-17 01:04:53 UTC (rev 22593) +++ haiku/trunk/src/apps/mediaplayer/MainWin.h 2007-10-17 10:29:16 UTC (rev 22594) @@ -91,6 +91,7 @@ int32 index); void _RemovePlaylistItem(int32 index); void _MarkPlaylistItem(int32 index); + void _MarkSettingsItem(uint32 command, bool mark); BMenuBar* fMenuBar; BView* fBackground; Modified: haiku/trunk/src/apps/mediaplayer/TransportControlGroup.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/TransportControlGroup.cpp 2007-10-17 01:04:53 UTC (rev 22593) +++ haiku/trunk/src/apps/mediaplayer/TransportControlGroup.cpp 2007-10-17 10:29:16 UTC (rev 22594) @@ -429,13 +429,12 @@ void TransportControlGroup::SetVolume(float value) { - if (B_OK != LockLooperWithTimeout(50000)) - return; + float db = _GainToDb(value); + float exponential = _LinearToExponential(db); + float gain = _DbToGain(exponential); + int32 pos = (int32)(floorf(gain * kVolumeFactor + 0.5)); - fVolumeSlider->SetValue(_DbToGain(_ExponentialToLinear( - _GainToDb(value))) * kVolumeFactor); - - UnlockLooper(); + fVolumeSlider->SetValueNoInvoke(pos); } Modified: haiku/trunk/src/apps/mediaplayer/VolumeSlider.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/VolumeSlider.cpp 2007-10-17 01:04:53 UTC (rev 22593) +++ haiku/trunk/src/apps/mediaplayer/VolumeSlider.cpp 2007-10-17 10:29:16 UTC (rev 22594) @@ -90,6 +90,16 @@ Invoke(); } +// SetValueNoInvoke +void +VolumeSlider::SetValueNoInvoke(int32 value) +{ + if (value == Value()) + return; + + BControl::SetValue(value); +} + // SetEnabled void VolumeSlider::SetEnabled(bool enable) Modified: haiku/trunk/src/apps/mediaplayer/VolumeSlider.h =================================================================== --- haiku/trunk/src/apps/mediaplayer/VolumeSlider.h 2007-10-17 01:04:53 UTC (rev 22593) +++ haiku/trunk/src/apps/mediaplayer/VolumeSlider.h 2007-10-17 10:29:16 UTC (rev 22594) @@ -25,6 +25,7 @@ // BControl virtual void AttachedToWindow(); virtual void SetValue(int32 value); + void SetValueNoInvoke(int32 value); virtual void SetEnabled(bool enable); virtual void Draw(BRect updateRect); virtual void MouseDown(BPoint where); From axeld at mail.berlios.de Wed Oct 17 16:20:58 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 17 Oct 2007 16:20:58 +0200 Subject: [Haiku-commits] r22595 - haiku/trunk/src/servers/app/drawing Message-ID: <200710171420.l9HEKwcm001796@sheep.berlios.de> Author: axeld Date: 2007-10-17 16:20:58 +0200 (Wed, 17 Oct 2007) New Revision: 22595 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22595&view=rev Modified: haiku/trunk/src/servers/app/drawing/AccelerantHWInterface.cpp Log: AccelerantHWInterface should no longer rely on GetModeList() being called before working with it. The app_server would have crashed before if a graphics driver could directly return a preferred display mode. Modified: haiku/trunk/src/servers/app/drawing/AccelerantHWInterface.cpp =================================================================== --- haiku/trunk/src/servers/app/drawing/AccelerantHWInterface.cpp 2007-10-17 10:29:16 UTC (rev 22594) +++ haiku/trunk/src/servers/app/drawing/AccelerantHWInterface.cpp 2007-10-17 14:20:58 UTC (rev 22595) @@ -404,13 +404,11 @@ Basically we try to set all modes as found in the mode list the driver returned, but we start with the one that best fits the originally desired mode. + The mode list must have been retrieved already. */ status_t AccelerantHWInterface::_SetFallbackMode(display_mode& newMode) const { - if (fModeList == NULL) - return B_ERROR; - // At first, we search the closest display mode from the list of // supported modes - if that fails, we just take one @@ -485,6 +483,12 @@ if (!fInitialModeSwitch) return status; + if (fModeList == NULL) { + status = _UpdateModeList(); + if (status < B_OK) + return status; + } + // If this is the initial mode switch, we try a number of fallback // modes first, before we have to fail @@ -609,7 +613,7 @@ ATRACE(("unable to get mode list\n")); return B_ERROR; } - + return B_OK; } @@ -650,37 +654,41 @@ status_t -AccelerantHWInterface::GetModeList(display_mode** modes, uint32 *count) +AccelerantHWInterface::GetModeList(display_mode** _modes, uint32 *_count) { AutoReadLocker _(this); - if (!count || !modes) + if (_count == NULL || _modes == NULL) return B_BAD_VALUE; - status_t ret = fModeList ? B_OK : _UpdateModeList(); + status_t status = B_OK; - if (ret >= B_OK) { - *modes = new(nothrow) display_mode[fModeCount]; - if (*modes) { - *count = fModeCount; - memcpy(*modes, fModeList, sizeof(display_mode) * fModeCount); + if (fModeList == NULL) + status = _UpdateModeList(); + + if (status >= B_OK) { + *_modes = new(nothrow) display_mode[fModeCount]; + if (*_modes) { + *_count = fModeCount; + memcpy(*_modes, fModeList, sizeof(display_mode) * fModeCount); } else { - *count = 0; - ret = B_NO_MEMORY; + *_count = 0; + status = B_NO_MEMORY; } } - return ret; + return status; } status_t -AccelerantHWInterface::GetPixelClockLimits(display_mode *mode, uint32 *low, uint32 *high) +AccelerantHWInterface::GetPixelClockLimits(display_mode *mode, uint32 *low, + uint32 *high) { AutoReadLocker _(this); if (!mode || !low || !high) return B_BAD_VALUE; - + return fAccGetPixelClockLimits(mode, low, high); } @@ -692,10 +700,10 @@ if (!dtc) return B_BAD_VALUE; - + if (fAccGetTimingConstraints) return fAccGetTimingConstraints(dtc); - + return B_UNSUPPORTED; } @@ -740,14 +748,15 @@ if (version != EDID_VERSION_1) return B_NOT_SUPPORTED; - status = B_ERROR; + if (fModeList == NULL) + _UpdateModeList(); // find preferred mode from EDID info for (uint32 i = 0; i < EDID1_NUM_DETAILED_MONITOR_DESC; ++i) { if (info.detailed_monitor[i].monitor_desc_type != EDID1_IS_DETAILED_TIMING) continue; - // TODO: we could also just look for this mode in the most list + // TODO: we could also just look for this mode in the mode list // TODO: handle sync and flags correctly! const edid1_detailed_timing& timing = info.detailed_monitor[i].data.detailed_timing; mode->timing.pixel_clock = timing.pixel_clock * 10; @@ -1235,9 +1244,6 @@ RenderingBuffer * AccelerantHWInterface::FrontBuffer() const { - if (!fModeList) - return NULL; - return fFrontBuffer; } @@ -1245,9 +1251,6 @@ RenderingBuffer * AccelerantHWInterface::BackBuffer() const { - if (!fModeList) - return NULL; - return fBackBuffer; } From axeld at mail.berlios.de Wed Oct 17 17:33:38 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 17 Oct 2007 17:33:38 +0200 Subject: [Haiku-commits] r22596 - haiku/trunk/src/add-ons/accelerants/radeon Message-ID: <200710171533.l9HFXceS005795@sheep.berlios.de> Author: axeld Date: 2007-10-17 17:33:38 +0200 (Wed, 17 Oct 2007) New Revision: 22596 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22596&view=rev Modified: haiku/trunk/src/add-ons/accelerants/radeon/GetModeInfo.c Log: Preferred mode should be 32 bits. Modified: haiku/trunk/src/add-ons/accelerants/radeon/GetModeInfo.c =================================================================== --- haiku/trunk/src/add-ons/accelerants/radeon/GetModeInfo.c 2007-10-17 14:20:58 UTC (rev 22595) +++ haiku/trunk/src/add-ons/accelerants/radeon/GetModeInfo.c 2007-10-17 15:33:38 UTC (rev 22596) @@ -86,7 +86,8 @@ if (ai->mode_list[i].timing.h_display == fpInfo->panel_xres && ai->mode_list[i].timing.v_display == fpInfo->panel_yres && ai->mode_list[i].virtual_width == fpInfo->panel_xres - && ai->mode_list[i].virtual_height == fpInfo->panel_yres) { + && ai->mode_list[i].virtual_height == fpInfo->panel_yres + && ai->mode_list[i].space == B_RGB32_LITTLE) { memcpy(mode, &ai->mode_list[i], sizeof(display_mode)); return B_OK; } From axeld at mail.berlios.de Wed Oct 17 17:35:14 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 17 Oct 2007 17:35:14 +0200 Subject: [Haiku-commits] r22597 - haiku/trunk/src/kits/app Message-ID: <200710171535.l9HFZETM005924@sheep.berlios.de> Author: axeld Date: 2007-10-17 17:35:13 +0200 (Wed, 17 Oct 2007) New Revision: 22597 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22597&view=rev Modified: haiku/trunk/src/kits/app/Message.cpp Log: Added TODO. Modified: haiku/trunk/src/kits/app/Message.cpp =================================================================== --- haiku/trunk/src/kits/app/Message.cpp 2007-10-17 15:33:38 UTC (rev 22596) +++ haiku/trunk/src/kits/app/Message.cpp 2007-10-17 15:35:13 UTC (rev 22597) @@ -1867,6 +1867,8 @@ size = sizeof(message_header); #ifndef HAIKU_TARGET_PLATFORM_LIBBE_TEST + // TODO: this is not yet finished - the target needs to get the + // address (and ID) of the area port_info info; get_port_info(port, &info); void *address = NULL; From axeld at mail.berlios.de Wed Oct 17 19:05:49 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 17 Oct 2007 19:05:49 +0200 Subject: [Haiku-commits] r22598 - in haiku/trunk: headers/private/kernel/disk_device_manager src/system/kernel/disk_device_manager Message-ID: <200710171705.l9HH5nlG024708@sheep.berlios.de> Author: axeld Date: 2007-10-17 19:05:48 +0200 (Wed, 17 Oct 2007) New Revision: 22598 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22598&view=rev Modified: haiku/trunk/headers/private/kernel/disk_device_manager/KDiskDevice.h haiku/trunk/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h haiku/trunk/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp Log: The disk device manager now periodically checks for media changes - all it does is dump its findings, but it's an (untested) start. Modified: haiku/trunk/headers/private/kernel/disk_device_manager/KDiskDevice.h =================================================================== --- haiku/trunk/headers/private/kernel/disk_device_manager/KDiskDevice.h 2007-10-17 15:35:13 UTC (rev 22597) +++ haiku/trunk/headers/private/kernel/disk_device_manager/KDiskDevice.h 2007-10-17 17:05:48 UTC (rev 22598) @@ -1,5 +1,7 @@ -// KDiskDevice.h - +/* + * Copyright 2003-2007, Ingo Weinhold, bonefish at cs.tu-berlin.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef _K_DISK_DEVICE_H #define _K_DISK_DEVICE_H @@ -50,6 +52,8 @@ bool IsRemovable() const; bool HasMedia() const; + virtual status_t GetMediaStatus(status_t *mediaStatus); + status_t SetPath(const char *path); // TODO: Remove this method or make it private. Once initialized the // path must not be changed. @@ -77,7 +81,6 @@ virtual void Dump(bool deep = true, int32 level = 0); protected: - virtual status_t GetMediaStatus(status_t *mediaStatus); virtual status_t GetGeometry(device_geometry *geometry); private: Modified: haiku/trunk/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h =================================================================== --- haiku/trunk/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h 2007-10-17 15:35:13 UTC (rev 22597) +++ haiku/trunk/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h 2007-10-17 17:05:48 UTC (rev 22598) @@ -1,5 +1,5 @@ /* - * Copyright 2004-2006, Haiku, Inc. All rights reserved. + * Copyright 2004-2007, Haiku, Inc. All rights reserved. * Copyright 2003-2004, Ingo Weinhold, bonefish at cs.tu-berlin.de. All rights reserved. * * Distributed under the terms of the MIT License. @@ -8,8 +8,8 @@ #define _K_DISK_DEVICE_MANAGER_H -#include "disk_device_manager.h" -#include "Locker.h" +#include +#include namespace BPrivate { @@ -125,6 +125,9 @@ status_t RescanDiskSystems(); private: + static void _CheckMediaStatusDaemon(void* self, int iteration); + void _CheckMediaStatus(); + status_t _RescanDiskSystems(bool fileSystems); status_t _AddPartitioningSystem(const char *name); Modified: haiku/trunk/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp 2007-10-17 15:35:13 UTC (rev 22597) +++ haiku/trunk/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp 2007-10-17 17:05:48 UTC (rev 22598) @@ -1,5 +1,5 @@ /* - * Copyright 2004-2006, Haiku, Inc. All rights reserved. + * Copyright 2004-2007, Haiku, Inc. All rights reserved. * Copyright 2003-2004, Ingo Weinhold, bonefish at cs.tu-berlin.de. All rights reserved. * * Distributed under the terms of the MIT License. @@ -133,6 +133,9 @@ RescanDiskSystems(); + register_kernel_daemon(&_CheckMediaStatusDaemon, this, 10); + // once every second + DBG(OUT("number of disk systems: %ld\n", CountDiskSystems())); // TODO: Watch the disk systems and the relevant directories. } @@ -140,6 +143,8 @@ KDiskDeviceManager::~KDiskDeviceManager() { + unregister_kernel_daemon(&_CheckMediaStatusDaemon, this); + // TODO: terminate and remove all jobs // remove all devices for (int32 cookie = 0; KDiskDevice *device = NextDevice(&cookie);) { @@ -1243,3 +1248,51 @@ return status; } + +void +KDiskDeviceManager::_CheckMediaStatus() +{ + ManagerLocker locker(this); + if (!locker.IsLocked()) + return; + + int32 cookie = 0; + while (true) { + KDiskDevice* device = NextDevice(&cookie); + if (device == NULL) + break; + + status_t mediaStatus; + if (device->GetMediaStatus(&mediaStatus) == B_OK) { + bool removed = false; + bool changed = false; + + switch (mediaStatus) { + case B_DEV_MEDIA_CHANGED: + changed = true; + break; + case B_DEV_NO_MEDIA: + case B_DEV_DOOR_OPEN: + removed = true; + break; + case B_DEV_MEDIA_CHANGE_REQUESTED: + case B_DEV_NOT_READY: + case B_OK: + break; + } + + // TODO: propagate changes! + if (removed) + dprintf("Media removed from %s\n", device->Path()); + if (changed) + dprintf("Media changed from %s\n", device->Path()); + } + } +} + + +void +KDiskDeviceManager::_CheckMediaStatusDaemon(void* self, int iteration) +{ + ((KDiskDeviceManager*)self)->_CheckMediaStatus(); +} From stippi at mail.berlios.de Wed Oct 17 20:21:26 2007 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Wed, 17 Oct 2007 20:21:26 +0200 Subject: [Haiku-commits] r22599 - haiku/trunk/src/tests/kits/interface/flatten_picture Message-ID: <200710171821.l9HILQRB031335@sheep.berlios.de> Author: stippi Date: 2007-10-17 20:21:26 +0200 (Wed, 17 Oct 2007) New Revision: 22599 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22599&view=rev Modified: haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTestWindow.h Log: * fix the build of this test Modified: haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTestWindow.h =================================================================== --- haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTestWindow.h 2007-10-17 17:05:48 UTC (rev 22598) +++ haiku/trunk/src/tests/kits/interface/flatten_picture/PictureTestWindow.h 2007-10-17 18:21:26 UTC (rev 22599) @@ -11,8 +11,10 @@ #include -class PictureTestWindow : public BWindow -{ +class BListView; +class BStringView; + +class PictureTestWindow : public BWindow { typedef BWindow Inherited; public: From bonefish at mail.berlios.de Wed Oct 17 22:51:10 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 17 Oct 2007 22:51:10 +0200 Subject: [Haiku-commits] r22600 - in haiku/trunk: headers/private/storage src/kits/storage Message-ID: <200710172051.l9HKpATP007416@sheep.berlios.de> Author: bonefish Date: 2007-10-17 22:51:10 +0200 (Wed, 17 Oct 2007) New Revision: 22600 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22600&view=rev Modified: haiku/trunk/headers/private/storage/DiskDevice.h haiku/trunk/headers/private/storage/Partition.h haiku/trunk/src/kits/storage/DiskDevice.cpp haiku/trunk/src/kits/storage/Partition.cpp Log: Style cleanup. Modified: haiku/trunk/headers/private/storage/DiskDevice.h =================================================================== --- haiku/trunk/headers/private/storage/DiskDevice.h 2007-10-17 18:21:26 UTC (rev 22599) +++ haiku/trunk/headers/private/storage/DiskDevice.h 2007-10-17 20:51:10 UTC (rev 22600) @@ -1,62 +1,66 @@ -//---------------------------------------------------------------------- -// This software is part of the OpenBeOS distribution and is covered -// by the OpenBeOS license. -//--------------------------------------------------------------------- - +/* + * Copyright 2003-2007, Ingo Weinhold, ingo_weinhold at gmx.de. + * Copyright 2003, Tyler Akidau, haiku at akidau.net. + * Distributed under the terms of the MIT License. + */ #ifndef _DISK_DEVICE_H #define _DISK_DEVICE_H #include + struct user_disk_device_data; class BDiskDevice : public BPartition { public: - BDiskDevice(); - virtual ~BDiskDevice(); + BDiskDevice(); + virtual ~BDiskDevice(); - bool HasMedia() const; - bool IsRemovableMedia() const; - bool IsReadOnlyMedia() const; - bool IsWriteOnceMedia() const; + bool HasMedia() const; + bool IsRemovableMedia() const; + bool IsReadOnlyMedia() const; + bool IsWriteOnceMedia() const; - status_t Eject(bool update = false); + status_t Eject(bool update = false); - status_t SetTo(partition_id id); - status_t Update(bool *updated = NULL); - void Unset(); - status_t InitCheck() const; + status_t SetTo(partition_id id); + status_t Update(bool* updated = NULL); + void Unset(); + status_t InitCheck() const; - virtual status_t GetPath(BPath *path) const; + virtual status_t GetPath(BPath* path) const; - bool IsModified() const; - status_t PrepareModifications(); - status_t CommitModifications(bool synchronously = true, - BMessenger progressMessenger = BMessenger(), - bool receiveCompleteProgressUpdates = true); - status_t CancelModifications(); + bool IsModified() const; + status_t PrepareModifications(); + status_t CommitModifications(bool synchronously = true, + BMessenger progressMessenger = BMessenger(), + bool receiveCompleteProgressUpdates = true); + status_t CancelModifications(); private: - friend class BDiskDeviceList; - friend class BDiskDeviceRoster; + friend class BDiskDeviceList; + friend class BDiskDeviceRoster; - BDiskDevice(const BDiskDevice &); - BDiskDevice &operator=(const BDiskDevice &); + BDiskDevice(const BDiskDevice&); + BDiskDevice& operator=(const BDiskDevice&); - static status_t _GetData(partition_id id, bool deviceOnly, bool shadow, - size_t neededSize, user_disk_device_data **data); + static status_t _GetData(partition_id id, bool deviceOnly, + bool shadow, size_t neededSize, + user_disk_device_data** data); - status_t _SetTo(partition_id id, bool deviceOnly, bool shadow, - size_t neededSize); - status_t _SetTo(user_disk_device_data *data); - status_t _Update(bool shadow, bool *updated); - status_t _Update(user_disk_device_data *data, bool *updated); + status_t _SetTo(partition_id id, bool deviceOnly, + bool shadow, size_t neededSize); + status_t _SetTo(user_disk_device_data* data); + status_t _Update(bool shadow, bool* updated); + status_t _Update(user_disk_device_data* data, + bool* updated); - static void _ClearUserData(user_partition_data* data); + static void _ClearUserData(user_partition_data* data); - virtual bool _AcceptVisitor(BDiskDeviceVisitor *visitor, int32 level); + virtual bool _AcceptVisitor(BDiskDeviceVisitor* visitor, + int32 level); - user_disk_device_data *fDeviceData; + user_disk_device_data* fDeviceData; }; #endif // _DISK_DEVICE_H Modified: haiku/trunk/headers/private/storage/Partition.h =================================================================== --- haiku/trunk/headers/private/storage/Partition.h 2007-10-17 18:21:26 UTC (rev 22599) +++ haiku/trunk/headers/private/storage/Partition.h 2007-10-17 20:51:10 UTC (rev 22600) @@ -1,5 +1,6 @@ /* - * Copyright 2003-2007, Ingo Weinhold, bonefish at cs.tu-berlin.de. + * Copyright 2003-2007, Ingo Weinhold, ingo_weinhold at gmx.de. + * Copyright 2003, Tyler Akidau, haiku at akidau.net. * Distributed under the terms of the MIT License. */ #ifndef _PARTITION_H Modified: haiku/trunk/src/kits/storage/DiskDevice.cpp =================================================================== --- haiku/trunk/src/kits/storage/DiskDevice.cpp 2007-10-17 18:21:26 UTC (rev 22599) +++ haiku/trunk/src/kits/storage/DiskDevice.cpp 2007-10-17 20:51:10 UTC (rev 22600) @@ -1,7 +1,7 @@ -//---------------------------------------------------------------------- -// This software is part of the OpenBeOS distribution and is covered -// by the OpenBeOS license. -//--------------------------------------------------------------------- +/* + * Copyright 2003-2007, Ingo Weinhold, ingo_weinhold at gmx.de. + * Distributed under the terms of the MIT License. + */ #include @@ -28,6 +28,7 @@ \brief A BDiskDevice object represents a storage device. */ + // constructor /*! \brief Creates an uninitialized BDiskDevice object. */ @@ -36,6 +37,7 @@ { } + // destructor /*! \brief Frees all resources associated with this object. */ @@ -44,6 +46,7 @@ CancelModifications(); } + // HasMedia /*! \brief Returns whether the device contains a media. \return \c true, if the device contains a media, \c false otherwise. @@ -52,9 +55,10 @@ BDiskDevice::HasMedia() const { return (fDeviceData - && fDeviceData->device_flags & B_DISK_DEVICE_HAS_MEDIA); + && fDeviceData->device_flags & B_DISK_DEVICE_HAS_MEDIA); } + // IsRemovableMedia /*! \brief Returns whether the device media are removable. \return \c true, if the device media are removable, \c false otherwise. @@ -63,25 +67,28 @@ BDiskDevice::IsRemovableMedia() const { return (fDeviceData - && fDeviceData->device_flags & B_DISK_DEVICE_REMOVABLE); + && fDeviceData->device_flags & B_DISK_DEVICE_REMOVABLE); } + // IsReadOnlyMedia bool BDiskDevice::IsReadOnlyMedia() const { return (fDeviceData - && fDeviceData->device_flags & B_DISK_DEVICE_READ_ONLY); + && fDeviceData->device_flags & B_DISK_DEVICE_READ_ONLY); } + // IsWriteOnceMedia bool BDiskDevice::IsWriteOnceMedia() const { return (fDeviceData - && fDeviceData->device_flags & B_DISK_DEVICE_WRITE_ONCE); + && fDeviceData->device_flags & B_DISK_DEVICE_WRITE_ONCE); } + // Eject /*! \brief Eject the device's media. @@ -99,7 +106,7 @@ BDiskDevice::Eject(bool update) { /* // get path - const char *path = Path(); + const char* path = Path(); status_t error = (path ? B_OK : B_NO_INIT); // check whether the device media is removable if (error == B_OK && !IsRemovable()) @@ -120,6 +127,7 @@ return B_ERROR; } + // SetTo status_t BDiskDevice::SetTo(partition_id id) @@ -127,6 +135,7 @@ return _SetTo(id, true, false, 0); } + // Update /*! \brief Updates the object to reflect the latest changes to the device. @@ -141,11 +150,12 @@ \return \c B_OK, if the update went fine, another error code otherwise. */ status_t -BDiskDevice::Update(bool *updated) +BDiskDevice::Update(bool* updated) { return _Update(_IsShadow(), updated); } + // Unset void BDiskDevice::Unset() @@ -155,6 +165,7 @@ fDeviceData = NULL; } + // InitCheck status_t BDiskDevice::InitCheck() const @@ -162,23 +173,26 @@ return (fDeviceData ? B_OK : B_NO_INIT); } + // GetPath status_t -BDiskDevice::GetPath(BPath *path) const +BDiskDevice::GetPath(BPath* path) const { if (!path || !fDeviceData) return B_BAD_VALUE; return path->SetTo(fDeviceData->path); } + // IsModified bool BDiskDevice::IsModified() const { return (InitCheck() == B_OK && _IsShadow() - && _kern_is_disk_device_modified(ID())); + && _kern_is_disk_device_modified(ID())); } + // PrepareModifications /*! \brief Initializes the partition hierarchy for modifications. * @@ -197,19 +211,23 @@ return error; if (_IsShadow()) return B_ERROR; + // ask kernel to prepare for modifications error = _kern_prepare_disk_device_modifications(ID()); if (error != B_OK) return error; + // update error = _Update(true, NULL); if (error != B_OK) { // bad -- cancelling the modifications is all we can do _kern_cancel_disk_device_modifications(ID()); } + return error; } + // CommitModifications /*! \brief Commits modifications to device. * @@ -219,14 +237,14 @@ */ status_t BDiskDevice::CommitModifications(bool synchronously, - BMessenger progressMessenger, - bool receiveCompleteProgressUpdates) + BMessenger progressMessenger, bool receiveCompleteProgressUpdates) { status_t error = InitCheck(); if (error != B_OK) return error; if (!_IsShadow()) return B_BAD_VALUE; + // TODO: Get port and token from the progressMessenger // TODO: Respect "synchronously"! port_id port = -1; @@ -235,9 +253,11 @@ receiveCompleteProgressUpdates); if (error == B_OK) error = _SetTo(ID(), true, false, 0); + return error; } + // CancelModifications /*! \brief Cancels all modifications performed on the device. * @@ -251,35 +271,40 @@ return error; if (!_IsShadow()) return B_BAD_VALUE; + error = _kern_cancel_disk_device_modifications(ID()); if (error == B_OK) error = _SetTo(ID(), true, false, 0); + return error; } + // copy constructor /*! \brief Privatized copy constructor to avoid usage. */ -BDiskDevice::BDiskDevice(const BDiskDevice &) +BDiskDevice::BDiskDevice(const BDiskDevice&) { } + // = /*! \brief Privatized assignment operator to avoid usage. */ -BDiskDevice & -BDiskDevice::operator=(const BDiskDevice &) +BDiskDevice& +BDiskDevice::operator=(const BDiskDevice&) { return *this; } + // _GetData status_t BDiskDevice::_GetData(partition_id id, bool deviceOnly, bool shadow, - size_t neededSize, user_disk_device_data **data) + size_t neededSize, user_disk_device_data** data) { // get the device data - void *buffer = NULL; + void* buffer = NULL; size_t bufferSize = 0; if (neededSize > 0) { // allocate initial buffer @@ -288,6 +313,7 @@ return B_NO_MEMORY; bufferSize = neededSize; } + status_t error = B_OK; do { error = _kern_get_disk_device_data(id, deviceOnly, shadow, @@ -297,79 +323,99 @@ // buffer to small re-allocate it if (buffer) free(buffer); + buffer = malloc(neededSize); + if (buffer) bufferSize = neededSize; else error = B_NO_MEMORY; } } while (error == B_BUFFER_OVERFLOW); + // set result / cleanup on error if (error == B_OK) *data = (user_disk_device_data*)buffer; else if (buffer) free(buffer); + return error; } + // _SetTo status_t BDiskDevice::_SetTo(partition_id id, bool deviceOnly, bool shadow, size_t neededSize) { Unset(); + // get the device data - user_disk_device_data *data = NULL; + user_disk_device_data* data = NULL; status_t error = _GetData(id, deviceOnly, shadow, neededSize, &data); + // set the data if (error == B_OK) error = _SetTo(data); + // cleanup on error if (error != B_OK && data) free(data); + return error; } + // _SetTo status_t -BDiskDevice::_SetTo(user_disk_device_data *data) +BDiskDevice::_SetTo(user_disk_device_data* data) { Unset(); + if (!data) return B_BAD_VALUE; + fDeviceData = data; + status_t error = BPartition::_SetTo(this, NULL, - &fDeviceData->device_partition_data); + &fDeviceData->device_partition_data); if (error != B_OK) { // If _SetTo() fails, the caller retains ownership of the supplied // data. So, unset fDeviceData before calling Unset(). fDeviceData = NULL; Unset(); } + return error; } + // _Update status_t -BDiskDevice::_Update(bool shadow, bool *updated) +BDiskDevice::_Update(bool shadow, bool* updated) { if (InitCheck() != B_OK) return InitCheck(); + // get the device data - user_disk_device_data *data = NULL; + user_disk_device_data* data = NULL; status_t error = _GetData(ID(), true, shadow, 0, &data); + // set the data if (error == B_OK) error = _Update(data, updated); + // cleanup on error if (error != B_OK && data) free(data); + return error; } + // _Update status_t -BDiskDevice::_Update(user_disk_device_data *data, bool *updated) +BDiskDevice::_Update(user_disk_device_data* data, bool* updated) { if (!data || !fDeviceData || ID() != data->device_partition_data.id) return B_BAD_VALUE; @@ -390,7 +436,7 @@ // update existing partitions and add new ones error = BPartition::_Update(&data->device_partition_data, updated); if (error == B_OK) { - user_disk_device_data *oldData = fDeviceData; + user_disk_device_data* oldData = fDeviceData; fDeviceData = data; // check for changes if (data->device_flags != oldData->device_flags @@ -399,12 +445,14 @@ } free(oldData); } + return error; } + // _AcceptVisitor bool -BDiskDevice::_AcceptVisitor(BDiskDeviceVisitor *visitor, int32 level) +BDiskDevice::_AcceptVisitor(BDiskDeviceVisitor* visitor, int32 level) { return visitor->Visit(this); } Modified: haiku/trunk/src/kits/storage/Partition.cpp =================================================================== --- haiku/trunk/src/kits/storage/Partition.cpp 2007-10-17 18:21:26 UTC (rev 22599) +++ haiku/trunk/src/kits/storage/Partition.cpp 2007-10-17 20:51:10 UTC (rev 22600) @@ -1,5 +1,5 @@ /* - * Copyright 2003-2007, Ingo Weinhold, bonefish at cs.tu-berlin.de. + * Copyright 2003-2007, Ingo Weinhold, ingo_weinhold at gmx.de. * Distributed under the terms of the MIT License. */ From julun at mail.berlios.de Wed Oct 17 23:05:44 2007 From: julun at mail.berlios.de (julun at BerliOS) Date: Wed, 17 Oct 2007 23:05:44 +0200 Subject: [Haiku-commits] r22601 - haiku/trunk/src/preferences/time Message-ID: <200710172105.l9HL5iXT008331@sheep.berlios.de> Author: julun Date: 2007-10-17 23:05:44 +0200 (Wed, 17 Oct 2007) New Revision: 22601 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22601&view=rev Added: haiku/trunk/src/preferences/time/DateTimeView.cpp haiku/trunk/src/preferences/time/DateTimeView.h Removed: haiku/trunk/src/preferences/time/SettingsView.cpp haiku/trunk/src/preferences/time/SettingsView.h Modified: haiku/trunk/src/preferences/time/Jamfile haiku/trunk/src/preferences/time/TimeWindow.cpp haiku/trunk/src/preferences/time/TimeWindow.h Log: * rename this to better reflect it's usage and to be able to add a real settings view Copied: haiku/trunk/src/preferences/time/DateTimeView.cpp (from rev 22598, haiku/trunk/src/preferences/time/SettingsView.cpp) =================================================================== --- haiku/trunk/src/preferences/time/SettingsView.cpp 2007-10-17 17:05:48 UTC (rev 22598) +++ haiku/trunk/src/preferences/time/DateTimeView.cpp 2007-10-17 21:05:44 UTC (rev 22601) @@ -0,0 +1,320 @@ +/* + * Copyright 2004-2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Andrew McCall + * Mike Berg + * Julun + */ + +#include "DateTimeView.h" +#include "AnalogClock.h" +#include "CalendarView.h" +#include "DateTimeEdit.h" +#include "TimeMessages.h" + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include + + +#ifdef HAIKU_TARGET_PLATFORM_HAIKU +#include +#else +void _kset_tzfilename_(const char *name, size_t length, bool isGMT); +#define _kern_set_tzfilename _kset_tzfilename_ +#endif + + +DateTimeView::DateTimeView(BRect frame) + : BView(frame,"Settings", B_FOLLOW_ALL, + B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP), + fGmtTime(NULL), + fInitialized(false) +{ + _ReadRTCSettings(); +} + + +DateTimeView::~DateTimeView() +{ + _WriteRTCSettings(); +} + + +void +DateTimeView::AttachedToWindow() +{ + if (Parent()) + SetViewColor(Parent()->ViewColor()); + + if (!fInitialized) { + _InitView(); + fInitialized = true; + } +} + + +void +DateTimeView::Draw(BRect /*updateRect*/) +{ + rgb_color viewcolor = ViewColor(); + rgb_color dark = tint_color(viewcolor, B_DARKEN_4_TINT); + rgb_color light = tint_color(viewcolor, B_LIGHTEN_MAX_TINT); + + //draw a separator line + BRect bounds(Bounds()); + BPoint start(bounds.Width() / 2.0f + 2.0f, bounds.top + 2.0f); + BPoint end(bounds.Width() / 2.0 + 2.0f, bounds.bottom - 2.0f); + + BeginLineArray(2); + AddLine(start, end, dark); + start.x++; + end.x++; + AddLine(start, end, light); + EndLineArray(); + + fTimeEdit->Draw(bounds); + fDateEdit->Draw(bounds); +} + + +void +DateTimeView::MessageReceived(BMessage *message) +{ + int32 change; + switch(message->what) { + case B_OBSERVER_NOTICE_CHANGE: + message->FindInt32(B_OBSERVE_WHAT_CHANGE, &change); + switch(change) { + case H_TM_CHANGED: + _UpdateDateTime(message); + break; + + default: + BView::MessageReceived(message); + break; + } + break; + + case kDayChanged: + { + BMessage msg(*message); + msg.what = H_USER_CHANGE; + msg.AddBool("time", false); + Window()->PostMessage(&msg); + } break; + + case kRTCUpdate: + _UpdateGmtSettings(); + break; + + default: + BView::MessageReceived(message); + break; + } +} + + +void +DateTimeView::GetPreferredSize(float *width, float *height) +{ + // hardcode in TimeWindow ... + *width = 470.0f; + *height = 227.0f; + + if (fInitialized) { + // we are initialized + *width = Bounds().Width(); + *height = fGmtTime->Frame().bottom; + } +} + + +void +DateTimeView::_InitView() +{ + font_height fontHeight; + be_plain_font->GetHeight(&fontHeight); + float textHeight = fontHeight.descent + fontHeight.ascent + fontHeight.leading; + + // left side + BRect frameLeft(Bounds()); + frameLeft.right = frameLeft.Width() / 2.0; + frameLeft.InsetBy(10.0f, 10.0f); + frameLeft.bottom = frameLeft.top + textHeight + 6.0; + + fDateEdit = new TDateEdit(frameLeft, "date_edit", 3); + AddChild(fDateEdit); + + frameLeft.top = fDateEdit->Frame().bottom + 10; + frameLeft.bottom = Bounds().bottom - 10; + + fCalendarView = new BCalendarView(frameLeft, "calendar"); + fCalendarView->SetWeekNumberHeaderVisible(false); + AddChild(fCalendarView); + fCalendarView->SetSelectionMessage(new BMessage(kDayChanged)); + fCalendarView->SetInvocationMessage(new BMessage(kDayChanged)); + fCalendarView->SetTarget(this); + + // right side + BRect frameRight(Bounds()); + frameRight.left = frameRight.Width() / 2.0; + frameRight.InsetBy(10.0f, 10.0f); + frameRight.bottom = frameRight.top + textHeight + 6.0; + + fTimeEdit = new TTimeEdit(frameRight, "time_edit", 4); + AddChild(fTimeEdit); + + frameRight.top = fTimeEdit->Frame().bottom + 10.0; + frameRight.bottom = Bounds().bottom - 10.0; + + float left = fTimeEdit->Frame().left; + float tmp = MIN(frameRight.Width(), frameRight.Height()); + frameRight.left = left + (fTimeEdit->Bounds().Width() - tmp) / 2.0; + frameRight.bottom = frameRight.top + tmp; + frameRight.right = frameRight.left + tmp; + + fClock = new TAnalogClock(frameRight, "analog clock", B_FOLLOW_NONE, B_WILL_DRAW); + AddChild(fClock); + + // clock radio buttons + frameRight.left = left; + frameRight.top = fClock->Frame().bottom + 10.0; + BStringView *text = new BStringView(frameRight, "clockis", "Clock set to:"); + AddChild(text); + text->ResizeToPreferred(); + + frameRight.left += 10.0f; + frameRight.top = text->Frame().bottom + 5.0; + + fLocalTime = new BRadioButton(frameRight, "local", "Local time", + new BMessage(kRTCUpdate)); + AddChild(fLocalTime); + fLocalTime->ResizeToPreferred(); + fLocalTime->SetTarget(this); + + frameRight.left = fLocalTime->Frame().right +10.0f; + + fGmtTime = new BRadioButton(frameRight, "gmt", "GMT", new BMessage(kRTCUpdate)); + AddChild(fGmtTime); + fGmtTime->ResizeToPreferred(); + fGmtTime->SetTarget(this); + + if (fIsLocalTime) + fLocalTime->SetValue(B_CONTROL_ON); + else + fGmtTime->SetValue(B_CONTROL_ON); +} + + +void +DateTimeView::_ReadRTCSettings() +{ + BPath path; + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) + return; + + path.Append("RTC_time_settings"); + + BFile file; + BEntry entry(path.Path()); + if (entry.Exists()) { + file.SetTo(&entry, B_READ_ONLY); + if (file.InitCheck() == B_OK) { + char localTime[6]; + file.Read(localTime, 6); + BString text(localTime); + if (text.Compare("local", 4) == 0) + fIsLocalTime = true; + else + fIsLocalTime = false; + } + } else { + // create set to local + fIsLocalTime = true; + file.SetTo(&entry, B_CREATE_FILE | B_READ_WRITE); + file.Write("local", 5); + } +} + + +void +DateTimeView::_WriteRTCSettings() +{ + BPath path; + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) + return; + + path.Append("RTC_time_settings"); + + BFile file(path.Path(), B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY); + if (file.InitCheck() == B_OK) { + if (fLocalTime->Value() == B_CONTROL_ON) + file.Write("local", 5); + else + file.Write("gmt", 3); + } +} + + +void +DateTimeView::_UpdateGmtSettings() +{ + _WriteRTCSettings(); + + BPath path; + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) + return; + + path.Append("timezone"); + BEntry entry(path.Path(), true); + + if (!entry.Exists()) + return; + + entry.GetPath(&path); + + // take the existing timezone and set it's gmt use + _kern_set_tzfilename(path.Path(), B_PATH_NAME_LENGTH + , fGmtTime->Value() == B_CONTROL_ON); +} + + +void +DateTimeView::_UpdateDateTime(BMessage *message) +{ + int32 day; + int32 month; + int32 year; + if (message->FindInt32("month", &month) == B_OK + && message->FindInt32("day", &day) == B_OK + && message->FindInt32("year", &year) == B_OK) + { + fDateEdit->SetDate(year, month, day); + fCalendarView->SetDate(year, month, day); + } + + int32 hour; + int32 minute; + int32 second; + if (message->FindInt32("hour", &hour) == B_OK + && message->FindInt32("minute", &minute) == B_OK + && message->FindInt32("second", &second) == B_OK) + { + fTimeEdit->SetTime(hour, minute, second); + fClock->SetTime(hour, minute, second); + } +} Copied: haiku/trunk/src/preferences/time/DateTimeView.h (from rev 22598, haiku/trunk/src/preferences/time/SettingsView.h) =================================================================== --- haiku/trunk/src/preferences/time/SettingsView.h 2007-10-17 17:05:48 UTC (rev 22598) +++ haiku/trunk/src/preferences/time/DateTimeView.h 2007-10-17 21:05:44 UTC (rev 22601) @@ -0,0 +1,54 @@ +/* + * Copyright 2004-2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Andrew McCall + * Mike Berg + * Julun + */ +#ifndef DATE_TIME_VIEW_H +#define DATE_TIME_VIEW_H + + +#include + + +class TDateEdit; +class TTimeEdit; +class BCalendarView; +class BRadioButton; +class TAnalogClock; + + +class DateTimeView : public BView { + public: + DateTimeView(BRect frame); + virtual ~DateTimeView(); + + virtual void AttachedToWindow(); + virtual void Draw(BRect updaterect); + virtual void MessageReceived(BMessage *message); + virtual void GetPreferredSize(float *width, float *height); + + private: + void _InitView(); + void _ReadRTCSettings(); + void _WriteRTCSettings(); + void _UpdateGmtSettings(); + void _UpdateDateTime(BMessage *message); + + private: + BRadioButton *fLocalTime; + BRadioButton *fGmtTime; + TDateEdit *fDateEdit; + TTimeEdit *fTimeEdit; + BCalendarView *fCalendarView; + TAnalogClock *fClock; + + bool fIsLocalTime; + bool fInitialized; +}; + +#endif // DATE_TIME_VIEW_H + Modified: haiku/trunk/src/preferences/time/Jamfile =================================================================== --- haiku/trunk/src/preferences/time/Jamfile 2007-10-17 20:51:10 UTC (rev 22600) +++ haiku/trunk/src/preferences/time/Jamfile 2007-10-17 21:05:44 UTC (rev 22601) @@ -13,7 +13,7 @@ CalendarView.cpp DateTimeEdit.cpp SectionEdit.cpp - SettingsView.cpp + DateTimeView.cpp Time.cpp TimeSettings.cpp TimeWindow.cpp Deleted: haiku/trunk/src/preferences/time/SettingsView.cpp Deleted: haiku/trunk/src/preferences/time/SettingsView.h Modified: haiku/trunk/src/preferences/time/TimeWindow.cpp =================================================================== --- haiku/trunk/src/preferences/time/TimeWindow.cpp 2007-10-17 20:51:10 UTC (rev 22600) +++ haiku/trunk/src/preferences/time/TimeWindow.cpp 2007-10-17 21:05:44 UTC (rev 22601) @@ -10,7 +10,7 @@ #include "TimeWindow.h" #include "BaseView.h" -#include "SettingsView.h" +#include "DateTimeView.h" #include "TimeMessages.h" #include "ZoneView.h" @@ -27,7 +27,7 @@ TTimeWindow::TTimeWindow(const BPoint leftTop) : BWindow(BRect(leftTop, leftTop + BPoint(WINDOW_RIGHT, WINDOW_BOTTOM)), - "Time & Date", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE) + "Time", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE) { BRect frame = Frame(); BRect bounds = Bounds(); @@ -64,8 +64,8 @@ msg.AddPoint("LeftTop", Frame().LeftTop()); be_app->PostMessage(&msg); - fBaseView->StopWatchingAll(fTimeSettings); fBaseView->StopWatchingAll(fTimeZones); + fBaseView->StopWatchingAll(fDateTimeView); be_app->PostMessage(B_QUIT_REQUESTED); @@ -88,16 +88,16 @@ bounds.InsetBy(4, 6); bounds.bottom -= tabview->TabHeight(); - fTimeSettings = new TSettingsView(bounds); - fBaseView->StartWatchingAll(fTimeSettings); + fDateTimeView = new DateTimeView(bounds); + fBaseView->StartWatchingAll(fDateTimeView); fTimeZones = new TZoneView(bounds); fBaseView->StartWatchingAll(fTimeZones); // add tabs BTab *tab = new BTab(); - tabview->AddTab(fTimeSettings, tab); - tab->SetLabel("Settings"); + tabview->AddTab(fDateTimeView, tab); + tab->SetLabel("Date & Time"); tab = new BTab(); tabview->AddTab(fTimeZones, tab); @@ -107,8 +107,9 @@ float width; float height; - // width/ height from settingsview + all InsetBy etc.. - fTimeSettings->GetPreferredSize(&width, &height); + fDateTimeView->GetPreferredSize(&width, &height); + + // width/ height from DateTimeView + all InsetBy etc.. ResizeTo(width +10, height + tabview->TabHeight() +25); } Modified: haiku/trunk/src/preferences/time/TimeWindow.h =================================================================== --- haiku/trunk/src/preferences/time/TimeWindow.h 2007-10-17 20:51:10 UTC (rev 22600) +++ haiku/trunk/src/preferences/time/TimeWindow.h 2007-10-17 21:05:44 UTC (rev 22601) @@ -15,7 +15,7 @@ class BMessage; -class TSettingsView; +class DateTimeView; class TTimeBaseView; class TZoneView; @@ -32,7 +32,7 @@ void _InitWindow(); TTimeBaseView *fBaseView; - TSettingsView *fTimeSettings; + DateTimeView *fDateTimeView; TZoneView *fTimeZones; }; From bonefish at mail.berlios.de Wed Oct 17 23:50:20 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 17 Oct 2007 23:50:20 +0200 Subject: [Haiku-commits] r22602 - in haiku/trunk: headers/private/storage src/kits/storage Message-ID: <200710172150.l9HLoKWU010609@sheep.berlios.de> Author: bonefish Date: 2007-10-17 23:50:20 +0200 (Wed, 17 Oct 2007) New Revision: 22602 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22602&view=rev Modified: haiku/trunk/headers/private/storage/Partition.h haiku/trunk/src/kits/storage/DiskDevice.cpp haiku/trunk/src/kits/storage/Partition.cpp Log: * Reimplemented BDiskDevice::IsModified()/ {Prepare,Commit,Cancel}Modifications() using the userland add-on backend. IsModified() and CommitModifications() are little more than stubs ATM. * Made BPartition::VisitEachChild()/VisitEachDescendant() const. Modified: haiku/trunk/headers/private/storage/Partition.h =================================================================== --- haiku/trunk/headers/private/storage/Partition.h 2007-10-17 21:05:44 UTC (rev 22601) +++ haiku/trunk/headers/private/storage/Partition.h 2007-10-17 21:50:20 UTC (rev 22602) @@ -76,9 +76,10 @@ status_t GetPartitioningInfo( BPartitioningInfo* info) const; - BPartition* VisitEachChild(BDiskDeviceVisitor* visitor); + BPartition* VisitEachChild(BDiskDeviceVisitor* visitor) + const; virtual BPartition* VisitEachDescendant( - BDiskDeviceVisitor* visitor); + BDiskDeviceVisitor* visitor) const; // Self Modification @@ -205,6 +206,11 @@ bool _SupportsChildOperation(const BPartition* child, uint32 flag) const; + status_t _CreateDelegates(); + status_t _InitDelegates(); + void _DeleteDelegates(); + bool _IsModified() const; + friend class BDiskDevice; friend class BDiskSystem; friend class BMutablePartition; Modified: haiku/trunk/src/kits/storage/DiskDevice.cpp =================================================================== --- haiku/trunk/src/kits/storage/DiskDevice.cpp 2007-10-17 21:05:44 UTC (rev 22601) +++ haiku/trunk/src/kits/storage/DiskDevice.cpp 2007-10-17 21:50:20 UTC (rev 22602) @@ -188,8 +188,22 @@ bool BDiskDevice::IsModified() const { - return (InitCheck() == B_OK && _IsShadow() - && _kern_is_disk_device_modified(ID())); + if (InitCheck() != B_OK) + return false; + + struct IsModifiedVisitor : public BDiskDeviceVisitor { + virtual bool Visit(BDiskDevice *device) + { + return Visit(device, 0); + } + + virtual bool Visit(BPartition *partition, int32 level) + { + return partition->_IsModified(); + } + } visitor; + + return (VisitEachDescendant(&visitor) != NULL); } @@ -209,21 +223,20 @@ status_t error = InitCheck(); if (error != B_OK) return error; - if (_IsShadow()) - return B_ERROR; + if (fDelegate) + return B_BAD_VALUE; - // ask kernel to prepare for modifications - error = _kern_prepare_disk_device_modifications(ID()); + // recursively create the delegates + error = _CreateDelegates(); + + // init them + if (error == B_OK) + error = _InitDelegates(); + + // delete all of them, if something went wrong if (error != B_OK) - return error; + _DeleteDelegates(); - // update - error = _Update(true, NULL); - if (error != B_OK) { - // bad -- cancelling the modifications is all we can do - _kern_cancel_disk_device_modifications(ID()); - } - return error; } @@ -242,15 +255,14 @@ status_t error = InitCheck(); if (error != B_OK) return error; - if (!_IsShadow()) + + if (!fDelegate) return B_BAD_VALUE; - // TODO: Get port and token from the progressMessenger - // TODO: Respect "synchronously"! - port_id port = -1; - int32 token = -1; - error = _kern_commit_disk_device_modifications(ID(), port, token, - receiveCompleteProgressUpdates); + // TODO: Implement! + + _DeleteDelegates(); + if (error == B_OK) error = _SetTo(ID(), true, false, 0); @@ -269,10 +281,12 @@ status_t error = InitCheck(); if (error != B_OK) return error; - if (!_IsShadow()) + + if (!fDelegate) return B_BAD_VALUE; - error = _kern_cancel_disk_device_modifications(ID()); + _DeleteDelegates(); + if (error == B_OK) error = _SetTo(ID(), true, false, 0); @@ -317,8 +331,7 @@ status_t error = B_OK; do { error = _kern_get_disk_device_data(id, deviceOnly, shadow, - (user_disk_device_data*)buffer, - bufferSize, &neededSize); + (user_disk_device_data*)buffer, bufferSize, &neededSize); if (error == B_BUFFER_OVERFLOW) { // buffer to small re-allocate it if (buffer) @@ -346,7 +359,7 @@ // _SetTo status_t BDiskDevice::_SetTo(partition_id id, bool deviceOnly, bool shadow, - size_t neededSize) + size_t neededSize) { Unset(); Modified: haiku/trunk/src/kits/storage/Partition.cpp =================================================================== --- haiku/trunk/src/kits/storage/Partition.cpp 2007-10-17 21:05:44 UTC (rev 22601) +++ haiku/trunk/src/kits/storage/Partition.cpp 2007-10-17 21:50:20 UTC (rev 22602) @@ -641,7 +641,7 @@ // VisitEachChild BPartition* -BPartition::VisitEachChild(BDiskDeviceVisitor* visitor) +BPartition::VisitEachChild(BDiskDeviceVisitor* visitor) const { if (visitor) { int32 level = _Level(); @@ -656,10 +656,10 @@ // VisitEachDescendant BPartition* -BPartition::VisitEachDescendant(BDiskDeviceVisitor* visitor) +BPartition::VisitEachDescendant(BDiskDeviceVisitor* visitor) const { if (visitor) - return _VisitEachDescendant(visitor); + return const_cast(this)->_VisitEachDescendant(visitor); return NULL; } @@ -1500,3 +1500,85 @@ return supported & flag; } + +// _CreateDelegates +status_t +BPartition::_CreateDelegates() +{ + if (fDelegate || !fPartitionData) + return B_BAD_VALUE; + + // create and init delegate + fDelegate = new(nothrow) Delegate(this); + if (!fDelegate) + return B_NO_MEMORY; + + status_t error = fDelegate->InitHierarchy(fPartitionData, + fParent ? fParent->fDelegate : NULL); + if (error != B_OK) + return error; + + // create child delegates + int32 count = fPartitionData->child_count; + for (int32 i = 0; i < count; i++) { + BPartition* child = (BPartition*)fPartitionData->children[i]->user_data; + error = child->_CreateDelegates(); + if (error != B_OK) + return error; + } + + return B_OK; +} + + +// _InitDelegates +status_t +BPartition::_InitDelegates() +{ + // init delegate + status_t error = fDelegate->InitAfterHierarchy(); + if (error != B_OK) + return error; + + // recursively init child delegates + int32 count = CountChildren(); + for (int32 i = 0; i < count; i++) { + error = ChildAt(i)->_InitDelegates(); + if (error != B_OK) + return error; + } + + return B_OK; +} + + +// _DeleteDelegates +void +BPartition::_DeleteDelegates() +{ + // recursively delete child delegates + int32 count = CountChildren(); + for (int32 i = count - 1; i >= 0; i--) + ChildAt(i)->_DeleteDelegates(); + + // delete delegate + delete fDelegate; + fDelegate = NULL; + + // Commit suicide, if the delegate was our only link to reality (i.e. + // there's no physically existing partition we represent). + if (fPartitionData == NULL) + delete this; +} + + +// _IsModified +bool +BPartition::_IsModified() const +{ + if (!fDelegate) + return false; + + // TODO: Implement! + return false; +} From bonefish at mail.berlios.de Thu Oct 18 00:25:49 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Thu, 18 Oct 2007 00:25:49 +0200 Subject: [Haiku-commits] r22603 - haiku/trunk/src/kits/storage Message-ID: <200710172225.l9HMPnvH012146@sheep.berlios.de> Author: bonefish Date: 2007-10-18 00:25:48 +0200 (Thu, 18 Oct 2007) New Revision: 22603 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22603&view=rev Modified: haiku/trunk/src/kits/storage/DiskDevice.cpp Log: Load the disk system add-ons in PrepareModifications(). Otherwise the delegates wouldn't be able to get them. Modified: haiku/trunk/src/kits/storage/DiskDevice.cpp =================================================================== --- haiku/trunk/src/kits/storage/DiskDevice.cpp 2007-10-17 21:50:20 UTC (rev 22602) +++ haiku/trunk/src/kits/storage/DiskDevice.cpp 2007-10-17 22:25:48 UTC (rev 22603) @@ -23,7 +23,9 @@ #include #include +#include "DiskSystemAddOnManager.h" + /*! \class BDiskDevice \brief A BDiskDevice object represents a storage device. */ @@ -226,6 +228,11 @@ if (fDelegate) return B_BAD_VALUE; + // make sure the disk system add-ons are loaded + error = DiskSystemAddOnManager::Default()->LoadDiskSystems(); + if (error != B_OK) + return error; + // recursively create the delegates error = _CreateDelegates(); @@ -234,8 +241,10 @@ error = _InitDelegates(); // delete all of them, if something went wrong - if (error != B_OK) + if (error != B_OK) { _DeleteDelegates(); + DiskSystemAddOnManager::Default()->UnloadDiskSystems(); + } return error; } @@ -262,6 +271,7 @@ // TODO: Implement! _DeleteDelegates(); + DiskSystemAddOnManager::Default()->UnloadDiskSystems(); if (error == B_OK) error = _SetTo(ID(), true, false, 0); @@ -286,6 +296,7 @@ return B_BAD_VALUE; _DeleteDelegates(); + DiskSystemAddOnManager::Default()->UnloadDiskSystems(); if (error == B_OK) error = _SetTo(ID(), true, false, 0); From bonefish at mail.berlios.de Thu Oct 18 00:27:23 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Thu, 18 Oct 2007 00:27:23 +0200 Subject: [Haiku-commits] r22604 - haiku/trunk/src/kits/storage Message-ID: <200710172227.l9HMRN76012230@sheep.berlios.de> Author: bonefish Date: 2007-10-18 00:27:23 +0200 (Thu, 18 Oct 2007) New Revision: 22604 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22604&view=rev Modified: haiku/trunk/src/kits/storage/DiskSystemAddOnManager.cpp haiku/trunk/src/kits/storage/PartitionDelegate.cpp Log: Added some debug output. Modified: haiku/trunk/src/kits/storage/DiskSystemAddOnManager.cpp =================================================================== --- haiku/trunk/src/kits/storage/DiskSystemAddOnManager.cpp 2007-10-17 22:25:48 UTC (rev 22603) +++ haiku/trunk/src/kits/storage/DiskSystemAddOnManager.cpp 2007-10-17 22:27:23 UTC (rev 22604) @@ -10,6 +10,8 @@ #include #include +#include + #include #include #include @@ -22,6 +24,11 @@ #include +#undef TRACE +//#define TRACE(format...) +#define TRACE(format...) printf(format) + + using std::nothrow; @@ -267,6 +274,8 @@ if (error != B_OK) return error; + TRACE("DiskSystemAddOnManager::_LoadAddOns(): %s\n", path.Path()); + error = path.Append("disk_systems"); if (error != B_OK) return error; @@ -283,8 +292,10 @@ entry_ref ref; while (directory.GetNextRef(&ref) == B_OK) { // skip, if already loaded - if (alreadyLoaded.find(ref.name) != alreadyLoaded.end()) + if (alreadyLoaded.find(ref.name) != alreadyLoaded.end()) { + TRACE(" skipping \"%s\" -- already loaded\n", ref.name); continue; + } // get the entry path BPath entryPath; @@ -292,13 +303,16 @@ if (error != B_OK) { if (error == B_NO_MEMORY) return error; + TRACE(" skipping \"%s\" -- failed to get path\n", ref.name); continue; } // load the add-on image_id image = load_add_on(entryPath.Path()); - if (image < 0) + if (image < 0) { + TRACE(" skipping \"%s\" -- failed to load add-on\n", ref.name); continue; + } AddOnImage* addOnImage = new(nothrow) AddOnImage(image); if (!addOnImage) { @@ -311,13 +325,17 @@ status_t (*getAddOns)(BList*); error = get_image_symbol(image, "get_disk_system_add_ons", B_SYMBOL_TYPE_TEXT, (void**)&getAddOns); - if (error != B_OK) + if (error != B_OK) { + TRACE(" skipping \"%s\" -- function symbol not found\n", ref.name); continue; + } BList addOns; error = getAddOns(&addOns); - if (error != B_OK || addOns.IsEmpty()) + if (error != B_OK || addOns.IsEmpty()) { + TRACE(" skipping \"%s\" -- getting add-ons failed\n", ref.name); continue; + } // create and add AddOn objects int32 count = addOns.CountItems(); @@ -337,6 +355,9 @@ } } + TRACE(" got %ld BDiskSystemAddOn(s) from add-on \"%s\"\n", count, + ref.name); + // add the add-on name to the set of already loaded add-ons try { alreadyLoaded.insert(ref.name); Modified: haiku/trunk/src/kits/storage/PartitionDelegate.cpp =================================================================== --- haiku/trunk/src/kits/storage/PartitionDelegate.cpp 2007-10-17 22:25:48 UTC (rev 22603) +++ haiku/trunk/src/kits/storage/PartitionDelegate.cpp 2007-10-17 22:27:23 UTC (rev 22604) @@ -10,6 +10,11 @@ #include "DiskSystemAddOnManager.h" +#undef TRACE +//#define TRACE(format...) +#define TRACE(format...) printf(format) + + // constructor BPartition::Delegate::Delegate(BPartition* partition) : fPartition(partition), @@ -63,12 +68,18 @@ DiskSystemAddOnManager* manager = DiskSystemAddOnManager::Default(); BDiskSystemAddOn* addOn = manager->GetAddOn( fMutablePartition.ContentType()); - if (!addOn) + if (!addOn) { + TRACE("BPartition::Delegate::InitAfterHierarchy(): add-on for disk " + "system \"%s\" not found\n", fMutablePartition.ContentType()); return B_ENTRY_NOT_FOUND; + } BPartitionHandle* handle; status_t error = addOn->CreatePartitionHandle(&fMutablePartition, &handle); if (error != B_OK) { + TRACE("BPartition::Delegate::InitAfterHierarchy(): Failed to create " + "partition handle for partition %ld, disk system: \"%s\": %s\n", + Partition()->ID(), addOn->Name(), strerror(error)); manager->PutAddOn(addOn); return error; } From bonefish at mail.berlios.de Thu Oct 18 00:28:23 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Thu, 18 Oct 2007 00:28:23 +0200 Subject: [Haiku-commits] r22605 - haiku/trunk/src/tests/apps/partitioner Message-ID: <200710172228.l9HMSNgI012270@sheep.berlios.de> Author: bonefish Date: 2007-10-18 00:28:22 +0200 (Thu, 18 Oct 2007) New Revision: 22605 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22605&view=rev Modified: haiku/trunk/src/tests/apps/partitioner/Partitioner.cpp Log: Adjusted to yesterday's API changes. Modified: haiku/trunk/src/tests/apps/partitioner/Partitioner.cpp =================================================================== --- haiku/trunk/src/tests/apps/partitioner/Partitioner.cpp 2007-10-17 22:27:23 UTC (rev 22604) +++ haiku/trunk/src/tests/apps/partitioner/Partitioner.cpp 2007-10-17 22:28:22 UTC (rev 22605) @@ -459,20 +459,11 @@ return; } - // get the disk system - BDiskSystem diskSystem; - status_t error = partition->GetDiskSystem(&diskSystem); - if (error != B_OK) { - printf("Failed to get disk system for partition: %s\n", - strerror(error)); - return; - } - // get supported types BObjectList supportedTypes(20, true); - char typeBuffer[B_DISK_DEVICE_TYPE_LENGTH]; + BString typeBuffer; int32 cookie = 0; - while (diskSystem.GetNextSupportedType(partition, &cookie, typeBuffer) + while (partition->GetNextSupportedChildType(&cookie, &typeBuffer) == B_OK) { supportedTypes.AddItem(new BString(typeBuffer)); } @@ -485,7 +476,7 @@ // get partitioning info BPartitioningInfo partitioningInfo; - error = partition->GetPartitioningInfo(&partitioningInfo); + status_t error = partition->GetPartitioningInfo(&partitioningInfo); if (error != B_OK) { printf("Failed to get partitioning info for partition: %s\n", strerror(error)); From bonefish at mail.berlios.de Thu Oct 18 00:56:24 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Thu, 18 Oct 2007 00:56:24 +0200 Subject: [Haiku-commits] r22606 - in haiku/trunk: headers/private/storage src/kits/storage Message-ID: <200710172256.l9HMuOZl021839@sheep.berlios.de> Author: bonefish Date: 2007-10-18 00:56:23 +0200 (Thu, 18 Oct 2007) New Revision: 22606 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22606&view=rev Removed: haiku/trunk/headers/private/storage/DiskDeviceJob.h haiku/trunk/src/kits/storage/DiskDeviceJob.cpp Modified: haiku/trunk/headers/private/storage/DiskDevice.h haiku/trunk/headers/private/storage/DiskDeviceRoster.h haiku/trunk/headers/private/storage/Partition.h haiku/trunk/src/kits/storage/DiskDevice.cpp haiku/trunk/src/kits/storage/DiskDeviceRoster.cpp haiku/trunk/src/kits/storage/Jamfile haiku/trunk/src/kits/storage/Partition.cpp Log: * Removed the BDiskDeviceJob class. Jobs won't be generated and executed in the kernel anymore. The respective functionality will be moved into the userland. Depending on how we want the API user to interface with it, we may want to reintroduce a similar class later. * Cleared remaining references to shadow partitions. Modified: haiku/trunk/headers/private/storage/DiskDevice.h =================================================================== --- haiku/trunk/headers/private/storage/DiskDevice.h 2007-10-17 22:28:22 UTC (rev 22605) +++ haiku/trunk/headers/private/storage/DiskDevice.h 2007-10-17 22:56:23 UTC (rev 22606) @@ -45,13 +45,13 @@ BDiskDevice& operator=(const BDiskDevice&); static status_t _GetData(partition_id id, bool deviceOnly, - bool shadow, size_t neededSize, + size_t neededSize, user_disk_device_data** data); status_t _SetTo(partition_id id, bool deviceOnly, - bool shadow, size_t neededSize); + size_t neededSize); status_t _SetTo(user_disk_device_data* data); - status_t _Update(bool shadow, bool* updated); + status_t _Update(bool* updated); status_t _Update(user_disk_device_data* data, bool* updated); Deleted: haiku/trunk/headers/private/storage/DiskDeviceJob.h Modified: haiku/trunk/headers/private/storage/DiskDeviceRoster.h =================================================================== --- haiku/trunk/headers/private/storage/DiskDeviceRoster.h 2007-10-17 22:28:22 UTC (rev 22605) +++ haiku/trunk/headers/private/storage/DiskDeviceRoster.h 2007-10-17 22:56:23 UTC (rev 22606) @@ -14,7 +14,6 @@ class BDirectory; class BDiskDevice; -class BDiskDeviceJob; class BDiskDeviceVisiting; class BDiskDeviceVisitor; class BDiskScannerPartitionAddOn; @@ -95,10 +94,6 @@ status_t GetNextDiskSystem(BDiskSystem *system); status_t RewindDiskSystems(); - // Active jobs are those that are scheduled or in-progress - status_t GetNextActiveJob(BDiskDeviceJob *job); - status_t RewindActiveJobs(); - partition_id RegisterFileDevice(const char *filename); // publishes: /dev/disk/virtual/files//raw status_t UnregisterFileDevice(const char *filename); @@ -127,9 +122,6 @@ status_t StartWatching(BMessenger target, uint32 eventMask = B_DEVICE_REQUEST_ALL); - status_t StartWatchingJob(BDiskDeviceJob *job, BMessenger target, - uint32 eventMask = B_DEVICE_REQUEST_JOB_COMPLETE_PROGRESS); - // TODO: Maybe better a BDiskDeviceJob::{Start,Stop}Watching()? status_t StopWatching(BMessenger target); private: Modified: haiku/trunk/headers/private/storage/Partition.h =================================================================== --- haiku/trunk/headers/private/storage/Partition.h 2007-10-17 22:28:22 UTC (rev 22605) +++ haiku/trunk/headers/private/storage/Partition.h 2007-10-17 22:56:23 UTC (rev 22606) @@ -187,8 +187,6 @@ bool* updated); void _RemoveChild(int32 index); - bool _IsShadow() const; - int32 _CountDescendants() const; int32 _Level() const; virtual bool _AcceptVisitor(BDiskDeviceVisitor* visitor, Modified: haiku/trunk/src/kits/storage/DiskDevice.cpp =================================================================== --- haiku/trunk/src/kits/storage/DiskDevice.cpp 2007-10-17 22:28:22 UTC (rev 22605) +++ haiku/trunk/src/kits/storage/DiskDevice.cpp 2007-10-17 22:56:23 UTC (rev 22606) @@ -134,7 +134,7 @@ status_t BDiskDevice::SetTo(partition_id id) { - return _SetTo(id, true, false, 0); + return _SetTo(id, true, 0); } @@ -154,7 +154,22 @@ status_t BDiskDevice::Update(bool* updated) { - return _Update(_IsShadow(), updated); + if (InitCheck() != B_OK) + return InitCheck(); + + // get the device data + user_disk_device_data* data = NULL; + status_t error = _GetData(ID(), true, 0, &data); + + // set the data + if (error == B_OK) + error = _Update(data, updated); + + // cleanup on error + if (error != B_OK && data) + free(data); + + return error; } @@ -274,7 +289,7 @@ DiskSystemAddOnManager::Default()->UnloadDiskSystems(); if (error == B_OK) - error = _SetTo(ID(), true, false, 0); + error = _SetTo(ID(), true, 0); return error; } @@ -299,7 +314,7 @@ DiskSystemAddOnManager::Default()->UnloadDiskSystems(); if (error == B_OK) - error = _SetTo(ID(), true, false, 0); + error = _SetTo(ID(), true, 0); return error; } @@ -325,8 +340,8 @@ // _GetData status_t -BDiskDevice::_GetData(partition_id id, bool deviceOnly, bool shadow, - size_t neededSize, user_disk_device_data** data) +BDiskDevice::_GetData(partition_id id, bool deviceOnly, size_t neededSize, + user_disk_device_data** data) { // get the device data void* buffer = NULL; @@ -341,7 +356,7 @@ status_t error = B_OK; do { - error = _kern_get_disk_device_data(id, deviceOnly, shadow, + error = _kern_get_disk_device_data(id, deviceOnly, false, (user_disk_device_data*)buffer, bufferSize, &neededSize); if (error == B_BUFFER_OVERFLOW) { // buffer to small re-allocate it @@ -369,14 +384,13 @@ // _SetTo status_t -BDiskDevice::_SetTo(partition_id id, bool deviceOnly, bool shadow, - size_t neededSize) +BDiskDevice::_SetTo(partition_id id, bool deviceOnly, size_t neededSize) { Unset(); // get the device data user_disk_device_data* data = NULL; - status_t error = _GetData(id, deviceOnly, shadow, neededSize, &data); + status_t error = _GetData(id, deviceOnly, neededSize, &data); // set the data if (error == B_OK) @@ -416,29 +430,6 @@ // _Update status_t -BDiskDevice::_Update(bool shadow, bool* updated) -{ - if (InitCheck() != B_OK) - return InitCheck(); - - // get the device data - user_disk_device_data* data = NULL; - status_t error = _GetData(ID(), true, shadow, 0, &data); - - // set the data - if (error == B_OK) - error = _Update(data, updated); - - // cleanup on error - if (error != B_OK && data) - free(data); - - return error; -} - - -// _Update -status_t BDiskDevice::_Update(user_disk_device_data* data, bool* updated) { if (!data || !fDeviceData || ID() != data->device_partition_data.id) Deleted: haiku/trunk/src/kits/storage/DiskDeviceJob.cpp Modified: haiku/trunk/src/kits/storage/DiskDeviceRoster.cpp =================================================================== --- haiku/trunk/src/kits/storage/DiskDeviceRoster.cpp 2007-10-17 22:28:22 UTC (rev 22605) +++ haiku/trunk/src/kits/storage/DiskDeviceRoster.cpp 2007-10-17 22:56:23 UTC (rev 22606) @@ -7,7 +7,6 @@ #include #include -#include #include #include #include @@ -86,7 +85,7 @@ &neededSize); if (id < 0) return id; - return device->_SetTo(id, true, false, neededSize); + return device->_SetTo(id, true, neededSize); } // RewindDevices @@ -122,27 +121,7 @@ return B_OK; } -// GetNextActiveJob -status_t -BDiskDeviceRoster::GetNextActiveJob(BDiskDeviceJob *job) -{ - if (!job) - return B_BAD_VALUE; - user_disk_device_job_info info; - status_t error = _kern_get_next_disk_device_job_info(&fJobCookie, &info); - if (error == B_OK) - error = job->_SetTo(&info); - return error; -} -// RewindActiveJobs -status_t -BDiskDeviceRoster::RewindActiveJobs() -{ - fJobCookie = 0; - return B_OK; -} - // RegisterFileDevice partition_id BDiskDeviceRoster::RegisterFileDevice(const char *filename) @@ -334,7 +313,7 @@ { if (!device) return B_BAD_VALUE; - return device->_SetTo(id, true, false, 0); + return device->_SetTo(id, true, 0); } // GetPartitionWithID @@ -361,7 +340,7 @@ if (!device || !partition) return B_BAD_VALUE; // download the device data - status_t error = device->_SetTo(id, false, false, 0); + status_t error = device->_SetTo(id, false, 0); if (error != B_OK) return error; // find the partition object @@ -383,7 +362,7 @@ if (id < 0) return id; // download the device data - return device->_SetTo(id, true, false, neededSize); + return device->_SetTo(id, true, neededSize); } // GetPartitionForPath @@ -400,7 +379,7 @@ if (id < 0) return id; // download the device data - status_t error = device->_SetTo(id, false, false, neededSize); + status_t error = device->_SetTo(id, false, neededSize); if (error != B_OK) return error; // find the partition object @@ -454,14 +433,6 @@ return B_ERROR; } -// StartWatchingJob -status_t -BDiskDeviceRoster::StartWatchingJob(BDiskDeviceJob *job, BMessenger target, - uint32 eventMask) -{ - // not implemented - return B_ERROR; -} // StopWatching /*! \brief Remove a target from the list of targets to be notified on disk Modified: haiku/trunk/src/kits/storage/Jamfile =================================================================== --- haiku/trunk/src/kits/storage/Jamfile 2007-10-17 22:28:22 UTC (rev 22605) +++ haiku/trunk/src/kits/storage/Jamfile 2007-10-17 22:56:23 UTC (rev 22606) @@ -71,7 +71,6 @@ # disk device API DiskDevice.cpp - DiskDeviceJob.cpp DiskDeviceList.cpp DiskDevicePrivate.cpp DiskDeviceRoster.cpp Modified: haiku/trunk/src/kits/storage/Partition.cpp =================================================================== --- haiku/trunk/src/kits/storage/Partition.cpp 2007-10-17 22:28:22 UTC (rev 22605) +++ haiku/trunk/src/kits/storage/Partition.cpp 2007-10-17 22:56:23 UTC (rev 22606) @@ -1397,14 +1397,6 @@ } -// _IsShadow -bool -BPartition::_IsShadow() const -{ - return (fPartitionData && fPartitionData->shadow_id >= 0); -} - - // _CountDescendants int32 BPartition::_CountDescendants() const From bonefish at mail.berlios.de Thu Oct 18 01:12:37 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Thu, 18 Oct 2007 01:12:37 +0200 Subject: [Haiku-commits] r22607 - in haiku/trunk/src/kits/storage: . disk_device Message-ID: <200710172312.l9HNCbWZ005194@sheep.berlios.de> Author: bonefish Date: 2007-10-18 01:12:36 +0200 (Thu, 18 Oct 2007) New Revision: 22607 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22607&view=rev Added: haiku/trunk/src/kits/storage/disk_device/ haiku/trunk/src/kits/storage/disk_device/DiskDevice.cpp haiku/trunk/src/kits/storage/disk_device/DiskDeviceList.cpp haiku/trunk/src/kits/storage/disk_device/DiskDevicePrivate.cpp haiku/trunk/src/kits/storage/disk_device/DiskDeviceRoster.cpp haiku/trunk/src/kits/storage/disk_device/DiskDeviceTypes.cpp haiku/trunk/src/kits/storage/disk_device/DiskDeviceVisitor.cpp haiku/trunk/src/kits/storage/disk_device/DiskScannerAddOn.cpp haiku/trunk/src/kits/storage/disk_device/DiskSystem.cpp haiku/trunk/src/kits/storage/disk_device/DiskSystemAddOn.cpp haiku/trunk/src/kits/storage/disk_device/DiskSystemAddOnManager.cpp haiku/trunk/src/kits/storage/disk_device/DiskSystemAddOnManager.h haiku/trunk/src/kits/storage/disk_device/MutablePartition.cpp haiku/trunk/src/kits/storage/disk_device/Partition.cpp haiku/trunk/src/kits/storage/disk_device/PartitionDelegate.cpp haiku/trunk/src/kits/storage/disk_device/PartitionDelegate.h haiku/trunk/src/kits/storage/disk_device/PartitioningDialog.cpp haiku/trunk/src/kits/storage/disk_device/PartitioningDialog.h haiku/trunk/src/kits/storage/disk_device/PartitioningInfo.cpp Removed: haiku/trunk/src/kits/storage/DiskDevice.cpp haiku/trunk/src/kits/storage/DiskDeviceList.cpp haiku/trunk/src/kits/storage/DiskDevicePrivate.cpp haiku/trunk/src/kits/storage/DiskDeviceRoster.cpp haiku/trunk/src/kits/storage/DiskDeviceTypes.cpp haiku/trunk/src/kits/storage/DiskDeviceVisitor.cpp haiku/trunk/src/kits/storage/DiskScannerAddOn.cpp haiku/trunk/src/kits/storage/DiskSystem.cpp haiku/trunk/src/kits/storage/DiskSystemAddOn.cpp haiku/trunk/src/kits/storage/DiskSystemAddOnManager.cpp haiku/trunk/src/kits/storage/DiskSystemAddOnManager.h haiku/trunk/src/kits/storage/MutablePartition.cpp haiku/trunk/src/kits/storage/Partition.cpp haiku/trunk/src/kits/storage/PartitionDelegate.cpp haiku/trunk/src/kits/storage/PartitionDelegate.h haiku/trunk/src/kits/storage/PartitioningDialog.cpp haiku/trunk/src/kits/storage/PartitioningDialog.h haiku/trunk/src/kits/storage/PartitioningInfo.cpp Modified: haiku/trunk/src/kits/storage/Jamfile Log: Moved disk device API into subdirectory disk_device. Deleted: haiku/trunk/src/kits/storage/DiskDevice.cpp Deleted: haiku/trunk/src/kits/storage/DiskDeviceList.cpp Deleted: haiku/trunk/src/kits/storage/DiskDevicePrivate.cpp Deleted: haiku/trunk/src/kits/storage/DiskDeviceRoster.cpp Deleted: haiku/trunk/src/kits/storage/DiskDeviceTypes.cpp Deleted: haiku/trunk/src/kits/storage/DiskDeviceVisitor.cpp Deleted: haiku/trunk/src/kits/storage/DiskScannerAddOn.cpp Deleted: haiku/trunk/src/kits/storage/DiskSystem.cpp Deleted: haiku/trunk/src/kits/storage/DiskSystemAddOn.cpp Deleted: haiku/trunk/src/kits/storage/DiskSystemAddOnManager.cpp Deleted: haiku/trunk/src/kits/storage/DiskSystemAddOnManager.h Modified: haiku/trunk/src/kits/storage/Jamfile =================================================================== --- haiku/trunk/src/kits/storage/Jamfile 2007-10-17 22:56:23 UTC (rev 22606) +++ haiku/trunk/src/kits/storage/Jamfile 2007-10-17 23:12:36 UTC (rev 22607) @@ -11,6 +11,7 @@ # for libbe_test UsePublicHeaders [ FDirName add-ons registrar ] ; +SEARCH_SOURCE += [ FDirName $(SUBDIR) disk_device ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) mime ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) sniffer ] ; Deleted: haiku/trunk/src/kits/storage/MutablePartition.cpp Deleted: haiku/trunk/src/kits/storage/Partition.cpp Deleted: haiku/trunk/src/kits/storage/PartitionDelegate.cpp Deleted: haiku/trunk/src/kits/storage/PartitionDelegate.h Deleted: haiku/trunk/src/kits/storage/PartitioningDialog.cpp Deleted: haiku/trunk/src/kits/storage/PartitioningDialog.h Deleted: haiku/trunk/src/kits/storage/PartitioningInfo.cpp Copied: haiku/trunk/src/kits/storage/disk_device/DiskDevice.cpp (from rev 22606, haiku/trunk/src/kits/storage/DiskDevice.cpp) Copied: haiku/trunk/src/kits/storage/disk_device/DiskDeviceList.cpp (from rev 22606, haiku/trunk/src/kits/storage/DiskDeviceList.cpp) Copied: haiku/trunk/src/kits/storage/disk_device/DiskDevicePrivate.cpp (from rev 22606, haiku/trunk/src/kits/storage/DiskDevicePrivate.cpp) Copied: haiku/trunk/src/kits/storage/disk_device/DiskDeviceRoster.cpp (from rev 22606, haiku/trunk/src/kits/storage/DiskDeviceRoster.cpp) Copied: haiku/trunk/src/kits/storage/disk_device/DiskDeviceTypes.cpp (from rev 22606, haiku/trunk/src/kits/storage/DiskDeviceTypes.cpp) Copied: haiku/trunk/src/kits/storage/disk_device/DiskDeviceVisitor.cpp (from rev 22606, haiku/trunk/src/kits/storage/DiskDeviceVisitor.cpp) Copied: haiku/trunk/src/kits/storage/disk_device/DiskScannerAddOn.cpp (from rev 22606, haiku/trunk/src/kits/storage/DiskScannerAddOn.cpp) Copied: haiku/trunk/src/kits/storage/disk_device/DiskSystem.cpp (from rev 22606, haiku/trunk/src/kits/storage/DiskSystem.cpp) Copied: haiku/trunk/src/kits/storage/disk_device/DiskSystemAddOn.cpp (from rev 22606, haiku/trunk/src/kits/storage/DiskSystemAddOn.cpp) Copied: haiku/trunk/src/kits/storage/disk_device/DiskSystemAddOnManager.cpp (from rev 22606, haiku/trunk/src/kits/storage/DiskSystemAddOnManager.cpp) Copied: haiku/trunk/src/kits/storage/disk_device/DiskSystemAddOnManager.h (from rev 22606, haiku/trunk/src/kits/storage/DiskSystemAddOnManager.h) Copied: haiku/trunk/src/kits/storage/disk_device/MutablePartition.cpp (from rev 22606, haiku/trunk/src/kits/storage/MutablePartition.cpp) Copied: haiku/trunk/src/kits/storage/disk_device/Partition.cpp (from rev 22606, haiku/trunk/src/kits/storage/Partition.cpp) Copied: haiku/trunk/src/kits/storage/disk_device/PartitionDelegate.cpp (from rev 22606, haiku/trunk/src/kits/storage/PartitionDelegate.cpp) Copied: haiku/trunk/src/kits/storage/disk_device/PartitionDelegate.h (from rev 22606, haiku/trunk/src/kits/storage/PartitionDelegate.h) Copied: haiku/trunk/src/kits/storage/disk_device/PartitioningDialog.cpp (from rev 22606, haiku/trunk/src/kits/storage/PartitioningDialog.cpp) Copied: haiku/trunk/src/kits/storage/disk_device/PartitioningDialog.h (from rev 22606, haiku/trunk/src/kits/storage/PartitioningDialog.h) Copied: haiku/trunk/src/kits/storage/disk_device/PartitioningInfo.cpp (from rev 22606, haiku/trunk/src/kits/storage/PartitioningInfo.cpp) From julun at mail.berlios.de Thu Oct 18 01:28:44 2007 From: julun at mail.berlios.de (julun at BerliOS) Date: Thu, 18 Oct 2007 01:28:44 +0200 Subject: [Haiku-commits] r22608 - haiku/trunk/src/preferences/time Message-ID: <200710172328.l9HNSi81001936@sheep.berlios.de> Author: julun Date: 2007-10-18 01:28:43 +0200 (Thu, 18 Oct 2007) New Revision: 22608 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22608&view=rev Added: haiku/trunk/src/preferences/time/SettingsView.cpp haiku/trunk/src/preferences/time/SettingsView.h Modified: haiku/trunk/src/preferences/time/Jamfile haiku/trunk/src/preferences/time/TimeWindow.cpp haiku/trunk/src/preferences/time/TimeWindow.h Log: * basic settings view, not functional atm... Modified: haiku/trunk/src/preferences/time/Jamfile =================================================================== --- haiku/trunk/src/preferences/time/Jamfile 2007-10-17 23:12:36 UTC (rev 22607) +++ haiku/trunk/src/preferences/time/Jamfile 2007-10-17 23:28:43 UTC (rev 22608) @@ -20,6 +20,7 @@ TZDisplay.cpp ZoneView.cpp DateTime.cpp + SettingsView.cpp : be : Time.rdef ; Added: haiku/trunk/src/preferences/time/SettingsView.cpp =================================================================== --- haiku/trunk/src/preferences/time/SettingsView.cpp 2007-10-17 23:12:36 UTC (rev 22607) +++ haiku/trunk/src/preferences/time/SettingsView.cpp 2007-10-17 23:28:43 UTC (rev 22608) @@ -0,0 +1,152 @@ +/* + * Copyright 2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Julun + */ + +#include "SettingsView.h" +#include "TimeMessages.h" + + +#include +#include +#include +#include +#include +#include + + +const uint32 kMsgMilTime = 'MilT'; +const uint32 kMsgEuroDate = 'EDat'; +const uint32 kMsgShowSeconds = 'ShSc'; + +const uint32 kYearMonthDay = '_ymd'; +const uint32 kDayMonthYear = '_dmy'; +const uint32 kMonthDayYear = '_mdy'; +const uint32 kSeparatorChanged = '_tsc'; +const uint32 kTrackerDateFormatChanged = 'TDFC'; + + +SettingsView::SettingsView(BRect frame) + : BView(frame,"Settings", B_FOLLOW_ALL, + B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP), + fInitialized(false) +{ +} + + +SettingsView::~SettingsView() +{ +} + + +void +SettingsView::AttachedToWindow() +{ + if (Parent()) + SetViewColor(Parent()->ViewColor()); + + if (!fInitialized) { + _InitView(); + fInitialized = true; + } +} + + +void +SettingsView::MessageReceived(BMessage *message) +{ + BView::MessageReceived(message); +} + + +void +SettingsView::_InitView() +{ + BRect bounds(Bounds()); + bounds.InsetBy(10.0, 10.0); + + BRect frameLeft(Bounds()); + frameLeft.right = frameLeft.Width() / 2; + frameLeft.InsetBy(10.0f, 10.0f); + + BStringView *timeSettings = new BStringView(frameLeft, "time", "Time:"); + AddChild(timeSettings); + timeSettings->ResizeToPreferred(); + + frameLeft.OffsetBy(10.0, timeSettings->Bounds().Height() + 5.0); + fShow24Hours = new BCheckBox(frameLeft, "show24Hours", "24 Hour Clock" + , new BMessage(kMsgMilTime)); + AddChild(fShow24Hours); + fShow24Hours->ResizeToPreferred(); + + frameLeft.OffsetBy(0.0, fShow24Hours->Bounds().Height() + 5.0); + fShowSeconds = new BCheckBox(frameLeft, "showSeconds", "Show Seconds" + , new BMessage(kMsgShowSeconds)); + AddChild(fShowSeconds); + fShowSeconds->ResizeToPreferred(); + + frameLeft.OffsetBy(0.0, 2 * fShowSeconds->Bounds().Height() + 5.0); + fGmtTime = new BRadioButton(frameLeft, "gmtTime", "Set clock to GMT" + , new BMessage(kRTCUpdate)); + AddChild(fGmtTime); + fGmtTime->ResizeToPreferred(); + + frameLeft.OffsetBy(0.0, fGmtTime->Bounds().Height() + 5.0); + fLocalTime = new BRadioButton(frameLeft, "local", "Set clock to local time", + new BMessage(kRTCUpdate)); + AddChild(fLocalTime); + fLocalTime->ResizeToPreferred(); + fLocalTime->SetValue(B_CONTROL_ON); + + BRect frameRight(Bounds()); + frameRight.left = frameRight.Width() / 2; + frameRight.InsetBy(10.0f, 10.0f); + + BStringView *dateSettings = new BStringView(frameRight, "date", "Date:"); + AddChild(dateSettings); + dateSettings->ResizeToPreferred(); + + frameRight.OffsetBy(10.0, dateSettings->Bounds().Height() + 5.0); + fYearMonthDay = new BCheckBox(frameRight, "yearMonthDay", "Year-Month-Day" + , new BMessage(kYearMonthDay)); + AddChild(fYearMonthDay); + fYearMonthDay->ResizeToPreferred(); + + frameRight.OffsetBy(0.0, fYearMonthDay->Bounds().Height() + 5.0); + fDayMonthYear = new BCheckBox(frameRight, "dayMonthYear", "Day-Month-Year" + , new BMessage(kDayMonthYear)); + AddChild(fDayMonthYear); + fDayMonthYear->ResizeToPreferred(); + + frameRight.OffsetBy(0.0, fDayMonthYear->Bounds().Height() + 5.0); + fMonthDayYear = new BCheckBox(frameRight, "monthDayYear", "Month-Day-Year" + , new BMessage(kMonthDayYear)); + AddChild(fMonthDayYear); + fMonthDayYear->ResizeToPreferred(); + fMonthDayYear->SetValue(B_CONTROL_ON); + + frameRight.OffsetBy(0.0, fMonthDayYear->Bounds().Height() + 5.0); + fStartWeekMonday = new BCheckBox(frameRight, "startWeekMonday" + , "Start week with Monday", new BMessage(kWeekStart)); + AddChild(fStartWeekMonday); + fStartWeekMonday->ResizeToPreferred(); + + fDateSeparator = new BPopUpMenu("Separator"); + fDateSeparator->AddItem(new BMenuItem("-", new BMessage(kSeparatorChanged))); + BMenuItem *item = new BMenuItem("/", new BMessage(kSeparatorChanged)); + fDateSeparator->AddItem(item); + item->SetMarked(true); + fDateSeparator->AddItem(new BMenuItem("\\", new BMessage(kSeparatorChanged))); + fDateSeparator->AddItem(new BMenuItem(".", new BMessage(kSeparatorChanged))); + fDateSeparator->AddItem(new BMenuItem("None", new BMessage(kSeparatorChanged))); + fDateSeparator->AddItem(new BMenuItem("Space", new BMessage(kSeparatorChanged))); + + frameRight.OffsetBy(0.0, fStartWeekMonday->Bounds().Height() + 5.0); + BMenuField *menuField = new BMenuField(frameRight, "regions", "Date separator:" + , fDateSeparator, false); + AddChild(menuField); + menuField->ResizeToPreferred(); +} Added: haiku/trunk/src/preferences/time/SettingsView.h =================================================================== --- haiku/trunk/src/preferences/time/SettingsView.h 2007-10-17 23:12:36 UTC (rev 22607) +++ haiku/trunk/src/preferences/time/SettingsView.h 2007-10-17 23:28:43 UTC (rev 22608) @@ -0,0 +1,48 @@ +/* + * Copyright 2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Julun + */ +#ifndef SETTINGS_VIEW_H +#define SETTINGS_VIEW_H + + +#include + + +class BCheckBox; +class BMessage; +class BPopUpMenu; +class BRadioButton; + + +class SettingsView : public BView { + public: + SettingsView(BRect frame); + virtual ~SettingsView(); + + virtual void AttachedToWindow(); + virtual void MessageReceived(BMessage *message); + + private: + void _InitView(); + + private: + BCheckBox *fShow24Hours; + BCheckBox *fShowSeconds; + BRadioButton *fGmtTime; + BRadioButton *fLocalTime; + + BCheckBox *fYearMonthDay; + BCheckBox *fDayMonthYear; + BCheckBox *fMonthDayYear; + BCheckBox *fStartWeekMonday; + + BPopUpMenu *fDateSeparator; + + bool fInitialized; +}; + +#endif // SETTINGS_VIEW_H Modified: haiku/trunk/src/preferences/time/TimeWindow.cpp =================================================================== --- haiku/trunk/src/preferences/time/TimeWindow.cpp 2007-10-17 23:12:36 UTC (rev 22607) +++ haiku/trunk/src/preferences/time/TimeWindow.cpp 2007-10-17 23:28:43 UTC (rev 22608) @@ -13,6 +13,7 @@ #include "DateTimeView.h" #include "TimeMessages.h" #include "ZoneView.h" +#include "SettingsView.h" #include @@ -91,18 +92,23 @@ fDateTimeView = new DateTimeView(bounds); fBaseView->StartWatchingAll(fDateTimeView); + BTab *tab = new BTab(); + tabview->AddTab(fDateTimeView, tab); + tab->SetLabel("Date & Time"); + fTimeZones = new TZoneView(bounds); fBaseView->StartWatchingAll(fTimeZones); - // add tabs - BTab *tab = new BTab(); - tabview->AddTab(fDateTimeView, tab); - tab->SetLabel("Date & Time"); - tab = new BTab(); tabview->AddTab(fTimeZones, tab); tab->SetLabel("Time Zone"); - + + fSettingsView = new SettingsView(bounds); + + tab = new BTab(); + tabview->AddTab(fSettingsView, tab); + tab->SetLabel("Settings"); + fBaseView->AddChild(tabview); float width; Modified: haiku/trunk/src/preferences/time/TimeWindow.h =================================================================== --- haiku/trunk/src/preferences/time/TimeWindow.h 2007-10-17 23:12:36 UTC (rev 22607) +++ haiku/trunk/src/preferences/time/TimeWindow.h 2007-10-17 23:28:43 UTC (rev 22608) @@ -18,6 +18,7 @@ class DateTimeView; class TTimeBaseView; class TZoneView; +class SettingsView; class TTimeWindow : public BWindow { @@ -34,6 +35,7 @@ TTimeBaseView *fBaseView; DateTimeView *fDateTimeView; TZoneView *fTimeZones; + SettingsView *fSettingsView; }; #endif // TIME_WINDOW_H From bonefish at mail.berlios.de Thu Oct 18 05:39:51 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Thu, 18 Oct 2007 05:39:51 +0200 Subject: [Haiku-commits] r22609 - in haiku/trunk: headers/private/storage src/kits/storage/disk_device Message-ID: <200710180339.l9I3dpCJ014604@sheep.berlios.de> Author: bonefish Date: 2007-10-18 05:39:50 +0200 (Thu, 18 Oct 2007) New Revision: 22609 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22609&view=rev Modified: haiku/trunk/headers/private/storage/MutablePartition.h haiku/trunk/src/kits/storage/disk_device/MutablePartition.cpp Log: We need flags to track what properties of the partition change. Modified: haiku/trunk/headers/private/storage/MutablePartition.h =================================================================== --- haiku/trunk/headers/private/storage/MutablePartition.h 2007-10-17 23:28:43 UTC (rev 22608) +++ haiku/trunk/headers/private/storage/MutablePartition.h 2007-10-18 03:39:50 UTC (rev 22609) @@ -66,6 +66,9 @@ int32 CountChildren() const; int32 IndexOfChild(BMutablePartition* child) const; + void SetChangeFlags(uint32 flags); + uint32 ChangeFlags() const; + // for the partitioning system managing the parent void* ChildCookie() const; void SetChildCookie(void* cookie); @@ -89,6 +92,7 @@ user_partition_data* fData; BMutablePartition* fParent; BList fChildren; + uint32 fChangeFlags; void* fChildCookie; }; Modified: haiku/trunk/src/kits/storage/disk_device/MutablePartition.cpp =================================================================== --- haiku/trunk/src/kits/storage/disk_device/MutablePartition.cpp 2007-10-17 23:28:43 UTC (rev 22608) +++ haiku/trunk/src/kits/storage/disk_device/MutablePartition.cpp 2007-10-18 03:39:50 UTC (rev 22609) @@ -321,7 +321,10 @@ if (!child) return B_BAD_VALUE; - delete child->fDelegate->Partition(); + // This will delete not only all delegates in the child's hierarchy, but + // also the respective partitions themselves, if they are no longer + // referenced. + child->fDelegate->Partition()->_DeleteDelegates(); return B_OK; } @@ -369,6 +372,22 @@ } +// SetChangeFlags +void +BMutablePartition::SetChangeFlags(uint32 flags) +{ + fChangeFlags = flags; +} + + +// ChangeFlags +uint32 +BMutablePartition::ChangeFlags() const +{ + return fChangeFlags; +} + + // ChildCookie void* BMutablePartition::ChildCookie() const @@ -390,6 +409,7 @@ : fDelegate(delegate), fData(NULL), fParent(NULL), + fChangeFlags(0), fChildCookie(NULL) { } From bonefish at mail.berlios.de Thu Oct 18 05:42:31 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Thu, 18 Oct 2007 05:42:31 +0200 Subject: [Haiku-commits] r22610 - in haiku/trunk: headers/private/storage src/kits/storage/disk_device Message-ID: <200710180342.l9I3gVfL014733@sheep.berlios.de> Author: bonefish Date: 2007-10-18 05:42:30 +0200 (Thu, 18 Oct 2007) New Revision: 22610 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22610&view=rev Modified: haiku/trunk/headers/private/storage/Partition.h haiku/trunk/src/kits/storage/disk_device/Partition.cpp Log: * Made _CountDescendants() public. * Added private _ChildAt() and _CountChildren(), which don't ask the delegate, thus reflecting the hierarchy as it was before changes. Modified: haiku/trunk/headers/private/storage/Partition.h =================================================================== --- haiku/trunk/headers/private/storage/Partition.h 2007-10-18 03:39:50 UTC (rev 22609) +++ haiku/trunk/headers/private/storage/Partition.h 2007-10-18 03:42:30 UTC (rev 22610) @@ -24,6 +24,10 @@ struct user_partition_data; +namespace BPrivate { + class DiskDeviceJobGenerator; +} + class BPartition { public: // Partition Info @@ -71,6 +75,7 @@ BPartition* Parent() const; BPartition* ChildAt(int32 index) const; int32 CountChildren() const; + int32 CountDescendants() const; BPartition* FindDescendant(partition_id id) const; status_t GetPartitioningInfo( @@ -187,7 +192,9 @@ bool* updated); void _RemoveChild(int32 index); - int32 _CountDescendants() const; + BPartition* _ChildAt(int32 index) const; + int32 _CountChildren() const; + int32 _Level() const; virtual bool _AcceptVisitor(BDiskDeviceVisitor* visitor, int32 level); @@ -212,6 +219,7 @@ friend class BDiskDevice; friend class BDiskSystem; friend class BMutablePartition; + friend class BPrivate::DiskDeviceJobGenerator; BDiskDevice* fDevice; BPartition* fParent; Modified: haiku/trunk/src/kits/storage/disk_device/Partition.cpp =================================================================== --- haiku/trunk/src/kits/storage/disk_device/Partition.cpp 2007-10-18 03:39:50 UTC (rev 22609) +++ haiku/trunk/src/kits/storage/disk_device/Partition.cpp 2007-10-18 03:42:30 UTC (rev 22610) @@ -602,9 +602,7 @@ return child ? child->Partition() : NULL; } - if (index < 0 || index >= fPartitionData->child_count) - return NULL; - return (BPartition*)fPartitionData->children[index]->user_data; + return _ChildAt(index); } @@ -615,16 +613,27 @@ if (fDelegate) return fDelegate->CountChildren(); - return fPartitionData->child_count; + return _CountChildren(); } +// CountDescendants +int32 +BPartition::CountDescendants() const +{ + int32 count = 1; + for (int32 i = 0; BPartition* child = ChildAt(i); i++) + count += child->CountDescendants(); + return count; +} + + // FindDescendant BPartition* BPartition::FindDescendant(partition_id id) const { IDFinderVisitor visitor(id); - return const_cast(this)->VisitEachDescendant(&visitor); + return VisitEachDescendant(&visitor); } @@ -1283,6 +1292,7 @@ fDevice = NULL; fParent = NULL; fPartitionData = NULL; + fDelegate = NULL; } @@ -1397,14 +1407,21 @@ } -// _CountDescendants +// _ChildAt +BPartition* +BPartition::_ChildAt(int32 index) const +{ + if (index < 0 || index >= fPartitionData->child_count) + return NULL; + return (BPartition*)fPartitionData->children[index]->user_data; +} + + +// _CountChildren int32 -BPartition::_CountDescendants() const +BPartition::_CountChildren() const { - int32 count = 1; - for (int32 i = 0; BPartition* child = ChildAt(i); i++) - count += child->_CountDescendants(); - return count; + return fPartitionData->child_count; } @@ -1511,9 +1528,9 @@ return error; // create child delegates - int32 count = fPartitionData->child_count; + int32 count = _CountChildren(); for (int32 i = 0; i < count; i++) { - BPartition* child = (BPartition*)fPartitionData->children[i]->user_data; + BPartition* child = _ChildAt(i); error = child->_CreateDelegates(); if (error != B_OK) return error; From bonefish at mail.berlios.de Thu Oct 18 05:49:51 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Thu, 18 Oct 2007 05:49:51 +0200 Subject: [Haiku-commits] r22611 - haiku/trunk/src/kits/storage/disk_device Message-ID: <200710180349.l9I3npaS015233@sheep.berlios.de> Author: bonefish Date: 2007-10-18 05:49:50 +0200 (Thu, 18 Oct 2007) New Revision: 22611 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22611&view=rev Added: haiku/trunk/src/kits/storage/disk_device/DiskDeviceJobGenerator.cpp haiku/trunk/src/kits/storage/disk_device/DiskDeviceJobGenerator.h Log: Beginnings of the class that analyzes the changes done to a BDiskDevice and generates jobs that perform the individual actions transforming the current state of the disk device into the desired one. Most code was taken and adapted from the soon to be gone kernel class KDiskDeviceJobGenerator. The methods creating the job objects are only stubs ATM. Added: haiku/trunk/src/kits/storage/disk_device/DiskDeviceJobGenerator.cpp =================================================================== --- haiku/trunk/src/kits/storage/disk_device/DiskDeviceJobGenerator.cpp 2007-10-18 03:42:30 UTC (rev 22610) +++ haiku/trunk/src/kits/storage/disk_device/DiskDeviceJobGenerator.cpp 2007-10-18 03:49:50 UTC (rev 22611) @@ -0,0 +1,571 @@ +/* + * Copyright 2003-2007, Ingo Weinhold, ingo_weinhold at gmx.de. + * Distributed under the terms of the MIT License. + */ + +#include "DiskDeviceJobGenerator.h" + +#include + +#include + +#include +#include + +#include + +#include "PartitionDelegate.h" + + +using std::nothrow; + + +// compare_string +/*! \brief \c NULL aware strcmp(). + + \c NULL is considered the least of all strings. \c NULL equals \c NULL. + + \param str1 First string. + \param str2 Second string. + \return A value less than 0, if \a str1 is less than \a str2, + 0, if they are equal, or a value greater than 0, if + \a str1 is greater \a str2. +*/ +static inline int +compare_string(const char* str1, const char* str2) +{ + if (str1 == NULL) { + if (str2 == NULL) + return 0; + return 1; + } else if (str2 == NULL) + return -1; + + return strcmp(str1, str2); +} + + +// move_info +struct DiskDeviceJobGenerator::move_info { + BPartition* partition; + off_t position; + off_t target_position; + off_t size; +}; + + +// constructor +DiskDeviceJobGenerator::DiskDeviceJobGenerator(BDiskDevice* device, + DiskDeviceJobQueue* jobQueue) + : fDevice(device), + fJobQueue(jobQueue), + fMoveInfos(NULL) +{ + fMoveInfoCount = fDevice->CountDescendants(); + + fMoveInfos = new(nothrow) move_info[fMoveInfoCount]; +// fPartitionIDs = new(nothrow) partition_id[fMoveInfoCount]; +} + + +// destructor +DiskDeviceJobGenerator::~DiskDeviceJobGenerator() +{ + delete[] fMoveInfos; +// delete[] fPartitionIDs; +} + + +// GenerateJobs +status_t +DiskDeviceJobGenerator::GenerateJobs() +{ + // check parameters + if (!fDevice || !fJobQueue /*|| !fMoveInfos || !fPartitionIDs + || fJobQueue->Device() != fDevice || !fDevice->ShadowPartition()*/) { + return B_BAD_VALUE; + } + + // 1) Generate jobs for all physical partitions that don't have an + // associated shadow partition, i.e. those that shall be deleted. + // 2) Generate uninitialize jobs for all partition whose initialization + // changes, also those that shall be initialized with a disk system. + // This simplifies moving and resizing. + status_t error = _GenerateCleanupJobs(fDevice); + if (error != B_OK) + return error; + + // Generate jobs that move and resize the remaining physical partitions + // to their final position/size. + error = _GeneratePlacementJobs(fDevice); + if (error != B_OK) + return error; + + // Generate the remaining jobs in one run: initialization, creation of + // partitions, and changing of name, content name, type, parameters, and + // content parameters. + error = _GenerateRemainingJobs(NULL, fDevice); + if (error != B_OK) + return error; + + return B_OK; +} + + +// _AddJob +status_t +DiskDeviceJobGenerator::_AddJob(DiskDeviceJob* job) +{ +// TODO: Implement! + return B_BAD_VALUE; +} + + +// _GenerateCleanupJobs +status_t +DiskDeviceJobGenerator::_GenerateCleanupJobs(BPartition* partition) +{ +// TODO: Depending on how this shall be handled, we might want to unmount +// all descendants of a partition to be uninitialized or removed. + if (BMutablePartition* shadow = _GetMutablePartition(partition)) { + if (shadow->ChangeFlags() & B_PARTITION_CHANGED_INITIALIZATION) { + // partition changes initialization + status_t error = _GenerateUninitializeJob(partition); + if (error != B_OK) + return error; + } else { + // recurse + for (int32 i = 0; BPartition* child = partition->_ChildAt(i); i++) { + status_t error = _GenerateCleanupJobs(child); + if (error != B_OK) + return error; + } + } + } else if (BPartition* parent = partition->Parent()) { + // create job and add it to the queue + status_t error = _GenerateDeleteChildJob(parent, partition); + if (error != B_OK) + return error; + } + return B_OK; +} + + +// _GeneratePlacementJobs +status_t +DiskDeviceJobGenerator::_GeneratePlacementJobs(BPartition* partition) +{ + if (BMutablePartition* shadow = _GetMutablePartition(partition)) { + // Don't resize/move partitions that have an unrecognized contents. + // They must have been uninitialized before. + if (shadow->Status() == B_PARTITION_UNRECOGNIZED + && (shadow->Size() != partition->Size() + || shadow->Offset() != partition->Offset())) { + return B_ERROR; + } + + if (shadow->Size() > partition->Size()) { + // size grows: resize first + status_t error = _GenerateResizeJob(partition); + if (error != B_OK) + return error; + } + + // place the children + status_t error = _GenerateChildPlacementJobs(partition); + if (error != B_OK) + return error; + + if (shadow->Size() < partition->Size()) { + // size shrinks: resize now + status_t error = _GenerateResizeJob(partition); + if (error != B_OK) + return error; + } + } + + return B_OK; +} + + +// _GenerateChildPlacementJobs +status_t +DiskDeviceJobGenerator::_GenerateChildPlacementJobs(BPartition* partition) +{ + BMutablePartition* shadow = _GetMutablePartition(partition); + + // nothing to do, if the partition contains no partitioning system or + // shall be re-initialized + if (!shadow->ContentType() + || (shadow->ChangeFlags() & B_PARTITION_CHANGED_INITIALIZATION)) { + return B_OK; + } + + // first resize all children that shall shrink and place their descendants + int32 childCount = 0; + int32 moveForth = 0; + int32 moveBack = 0; + + for (int32 i = 0; BPartition* child = partition->_ChildAt(i); i++) { + if (BMutablePartition* childShadow = _GetMutablePartition(child)) { + // add a move_info for the child + move_info& info = fMoveInfos[childCount]; + childCount++; + info.partition = child; + info.position = child->Offset(); + info.target_position = childShadow->Offset(); + info.size = child->Size(); + + if (info.position < info.target_position) + moveForth++; + else if (info.position > info.target_position) + moveBack++; + + // resize the child, if it shall shrink + if (childShadow->Size() < child->Size()) { + status_t error = _GeneratePlacementJobs(child); + if (error != B_OK) + return error; + info.size = childShadow->Size(); + } + } + } + + // sort the move infos + if (childCount > 0 && moveForth + moveBack > 0) { + qsort(fMoveInfos, childCount, sizeof(move_info), + _CompareMoveInfoPosition); + } + + // move the children to their final positions + while (moveForth + moveBack > 0) { + int32 moved = 0; + if (moveForth < moveBack) { + // move children back + for (int32 i = 0; i < childCount; i++) { + move_info &info = fMoveInfos[i]; + if (info.position > info.target_position) { + if (i == 0 + || info.target_position >= fMoveInfos[i - 1].position + + fMoveInfos[i - 1].size) { + // check OK -- the partition wouldn't be moved before + // the end of the preceding one + status_t error = _GenerateMoveJob(info.partition); + if (error != B_OK) + return error; + info.position = info.target_position; + moved++; + moveBack--; + } + } + } + } else { + // move children forth + for (int32 i = childCount - 1; i >= 0; i--) { + move_info &info = fMoveInfos[i]; + if (info.position > info.target_position) { + if (i == childCount - 1 + || info.target_position + info.size + <= fMoveInfos[i - 1].position) { + // check OK -- the partition wouldn't be moved before + // the end of the preceding one + status_t error = _GenerateMoveJob(info.partition); + if (error != B_OK) + return error; + info.position = info.target_position; + moved++; + moveForth--; + } + } + } + } + + // terminate, if no partition could be moved + if (moved == 0) + return B_ERROR; + } + + // now resize all children that shall grow/keep their size and place + // their descendants + for (int32 i = 0; BPartition* child = partition->_ChildAt(i); i++) { + if (BMutablePartition* childShadow = _GetMutablePartition(child)) { + if (childShadow->Size() >= child->Size()) { + status_t error = _GeneratePlacementJobs(child); + if (error != B_OK) + return error; + } + } + } + + return B_OK; +} + + +// _GenerateRemainingJobs +status_t +DiskDeviceJobGenerator::_GenerateRemainingJobs(BPartition* parent, + BPartition* partition) +{ + user_partition_data* partitionData = partition->fPartitionData; + + uint32 changeFlags + = partition->fDelegate->MutablePartition()->ChangeFlags(); + + // create the partition, if not existing yet + if (!partitionData) { + if (!parent) + return B_BAD_VALUE; + + status_t error = _GenerateCreateChildJob(parent, partition); + if (error != B_OK) + return error; + } else { + // partition already exists: set non-content properties + + + // name + if ((changeFlags & B_PARTITION_CHANGED_NAME) + || compare_string(partition->Name(), partitionData->name)) { + if (!parent) + return B_BAD_VALUE; + + status_t error = _GenerateSetNameJob(parent, partition); + if (error != B_OK) + return error; + } + + // type + if ((changeFlags & B_PARTITION_CHANGED_TYPE) + || compare_string(partition->Type(), partitionData->type)) { + if (!parent) + return B_BAD_VALUE; + + status_t error = _GenerateSetTypeJob(parent, partition); + if (error != B_OK) + return error; + } + + // parameters + if ((changeFlags & B_PARTITION_CHANGED_PARAMETERS) + || compare_string(partition->Parameters(), + partitionData->parameters)) { + if (!parent) + return B_BAD_VALUE; + + status_t error = _GenerateSetParametersJob(parent, partition); + if (error != B_OK) + return error; + } + } + + if (partition->ContentType()) { + // initialize the partition, if required + if (changeFlags & B_PARTITION_CHANGED_INITIALIZATION) { + status_t error = _GenerateInitializeJob(partition); + if (error != B_OK) + return error; + } else { + // partition not (re-)initialized, set content properties + + // content name + if ((changeFlags & B_PARTITION_CHANGED_NAME) + || compare_string(partition->ContentName(), + partitionData->content_name)) { + status_t error = _GenerateSetContentNameJob(partition); + if (error != B_OK) + return error; + } + + // content parameters + if ((changeFlags & B_PARTITION_CHANGED_PARAMETERS) + || compare_string(partition->ContentParameters(), + partitionData->content_parameters)) { + status_t error = _GenerateSetContentParametersJob(partition); + if (error != B_OK) + return error; + } + + // defragment + if (changeFlags & B_PARTITION_CHANGED_DEFRAGMENTATION) { + status_t error = _GenerateDefragmentJob(partition); + if (error != B_OK) + return error; + } + + // check / repair + bool repair = (changeFlags & B_PARTITION_CHANGED_REPAIR); + if ((changeFlags & B_PARTITION_CHANGED_CHECK) + || repair) { + status_t error = _GenerateRepairJob(partition, repair); + if (error != B_OK) + return error; + } + } + } + + // recurse + for (int32 i = 0; BPartition* child = partition->ChildAt(i); i++) { + status_t error = _GenerateRemainingJobs(partition, child); + if (error != B_OK) + return error; + } + + return B_OK; +} + + +// _GetMutablePartition +BMutablePartition* +DiskDeviceJobGenerator::_GetMutablePartition(BPartition* partition) +{ + if (!partition) + return NULL; + + return partition->fDelegate + ? partition->fDelegate->MutablePartition() : NULL; +} + + +// _GenerateInitializeJob +status_t +DiskDeviceJobGenerator::_GenerateInitializeJob(BPartition* partition) +{ +// TODO: Implement! + return B_BAD_VALUE; +} + + +// _GenerateUninitializeJob +status_t +DiskDeviceJobGenerator::_GenerateUninitializeJob(BPartition* partition) +{ +// TODO: Implement! + return B_BAD_VALUE; +} + + +// _GenerateSetContentNameJob +status_t +DiskDeviceJobGenerator::_GenerateSetContentNameJob(BPartition* partition) +{ +// TODO: Implement! + return B_BAD_VALUE; +} + + +// _GenerateSetContentParametersJob +status_t +DiskDeviceJobGenerator::_GenerateSetContentParametersJob(BPartition* partition) +{ +// TODO: Implement! + return B_BAD_VALUE; +} + + +// _GenerateDefragmentJob +status_t +DiskDeviceJobGenerator::_GenerateDefragmentJob(BPartition* partition) +{ +// TODO: Implement! + return B_BAD_VALUE; +} + + +// _GenerateRepairJob +status_t +DiskDeviceJobGenerator::_GenerateRepairJob(BPartition* partition, bool repair) +{ +// TODO: Implement! + return B_BAD_VALUE; +} + + +// _GenerateCreateChildJob +status_t +DiskDeviceJobGenerator::_GenerateCreateChildJob(BPartition* parent, + BPartition* partition) +{ +// TODO: Implement! + return B_BAD_VALUE; +} + + +// _GenerateDeleteChildJob +status_t +DiskDeviceJobGenerator::_GenerateDeleteChildJob(BPartition* parent, + BPartition* child) +{ +// TODO: Implement! + return B_BAD_VALUE; +} + + +// _GenerateResizeJob +status_t +DiskDeviceJobGenerator::_GenerateResizeJob(BPartition* partition) +{ +// TODO: Implement! + return B_BAD_VALUE; +} + + +// _GenerateMoveJob +status_t +DiskDeviceJobGenerator::_GenerateMoveJob(BPartition* partition) +{ +// TODO: Implement! + return B_BAD_VALUE; +} + + +// _GenerateSetNameJob +status_t +DiskDeviceJobGenerator::_GenerateSetNameJob(BPartition* parent, + BPartition* partition) +{ +// TODO: Implement! + return B_BAD_VALUE; +} + + +// _GenerateSetTypeJob +status_t +DiskDeviceJobGenerator::_GenerateSetTypeJob(BPartition* parent, + BPartition* partition) +{ +// TODO: Implement! + return B_BAD_VALUE; +} + + +// _GenerateSetParametersJob +status_t +DiskDeviceJobGenerator::_GenerateSetParametersJob(BPartition* parent, + BPartition* partition) +{ +// TODO: Implement! + return B_BAD_VALUE; +} + + +// _CollectContentsToMove +status_t +DiskDeviceJobGenerator::_CollectContentsToMove(BPartition* partition) +{ +// TODO: Implement! + return B_BAD_VALUE; +} + + +// _CompareMoveInfoOffset +int +DiskDeviceJobGenerator::_CompareMoveInfoPosition(const void* _a, const void* _b) +{ + const move_info* a = static_cast(_a); + const move_info* b = static_cast(_b); + if (a->position < b->position) + return -1; + if (a->position > b->position) + return 1; + return 0; +} Added: haiku/trunk/src/kits/storage/disk_device/DiskDeviceJobGenerator.h =================================================================== --- haiku/trunk/src/kits/storage/disk_device/DiskDeviceJobGenerator.h 2007-10-18 03:42:30 UTC (rev 22610) +++ haiku/trunk/src/kits/storage/disk_device/DiskDeviceJobGenerator.h 2007-10-18 03:49:50 UTC (rev 22611) @@ -0,0 +1,85 @@ +/* + * Copyright 2003-2007, Ingo Weinhold, ingo_weinhold at gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _DISK_DEVICE_JOB_GENERATOR_H +#define _DISK_DEVICE_JOB_GENERATOR_H + +#include + + +class BDiskDevice; +class BMutablePartition; +class BPartition; + + +namespace BPrivate { + + +class DiskDeviceJob; +class DiskDeviceJobQueue; + + +class DiskDeviceJobGenerator { +public: + DiskDeviceJobGenerator(BDiskDevice* device, + DiskDeviceJobQueue* jobQueue); + ~DiskDeviceJobGenerator(); + + status_t GenerateJobs(); + +private: + status_t _AddJob(DiskDeviceJob* job); + + status_t _GenerateCleanupJobs(BPartition* partition); + status_t _GeneratePlacementJobs(BPartition* partition); + status_t _GenerateChildPlacementJobs( + BPartition* partition); + status_t _GenerateRemainingJobs(BPartition* parent, + BPartition* partition); + + BMutablePartition* _GetMutablePartition(BPartition* partition); + + status_t _GenerateInitializeJob(BPartition* partition); + status_t _GenerateUninitializeJob(BPartition* partition); + status_t _GenerateSetContentNameJob( + BPartition* partition); + status_t _GenerateSetContentParametersJob( + BPartition* partition); + status_t _GenerateDefragmentJob(BPartition* partition); + status_t _GenerateRepairJob(BPartition* partition, + bool repair); + + status_t _GenerateCreateChildJob(BPartition* parent, + BPartition* partition); + status_t _GenerateDeleteChildJob(BPartition* parent, + BPartition* child); + status_t _GenerateResizeJob(BPartition* partition); + status_t _GenerateMoveJob(BPartition* partition); + status_t _GenerateSetNameJob(BPartition* parent, + BPartition* partition); + status_t _GenerateSetTypeJob(BPartition* parent, + BPartition* partition); + status_t _GenerateSetParametersJob(BPartition* parent, + BPartition* partition); + + status_t _CollectContentsToMove(BPartition* partition); + + static int _CompareMoveInfoPosition(const void* _a, + const void* _b); + +private: + struct move_info; + + BDiskDevice* fDevice; + DiskDeviceJobQueue* fJobQueue; + move_info* fMoveInfos; + int32 fMoveInfoCount; +}; + + +} // namespace BPrivate + +using BPrivate::DiskDeviceJobGenerator; + +#endif // _DISK_DEVICE_JOB_GENERATOR_H From axeld at mail.berlios.de Thu Oct 18 11:57:15 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 18 Oct 2007 11:57:15 +0200 Subject: [Haiku-commits] r22612 - haiku/trunk/src/system/kernel/disk_device_manager Message-ID: <200710180957.l9I9vFNH017992@sheep.berlios.de> Author: axeld Date: 2007-10-18 11:57:15 +0200 (Thu, 18 Oct 2007) New Revision: 22612 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22612&view=rev Modified: haiku/trunk/src/system/kernel/disk_device_manager/Jamfile Log: Fixed build. Modified: haiku/trunk/src/system/kernel/disk_device_manager/Jamfile =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/Jamfile 2007-10-18 03:49:50 UTC (rev 22611) +++ haiku/trunk/src/system/kernel/disk_device_manager/Jamfile 2007-10-18 09:57:15 UTC (rev 22612) @@ -1,7 +1,7 @@ SubDir HAIKU_TOP src system kernel disk_device_manager ; SEARCH_SOURCE += [ FDirName $(SUBDIR) jobs ] ; -SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits storage ] ; +SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits storage disk_device ] ; # DiskDeviceTypes.cpp UsePrivateHeaders [ FDirName kernel boot platform $(TARGET_BOOT_PLATFORM) ] ; From axeld at mail.berlios.de Thu Oct 18 15:41:18 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 18 Oct 2007 15:41:18 +0200 Subject: [Haiku-commits] r22613 - haiku/trunk/src/servers/app Message-ID: <200710181341.l9IDfIp2023772@sheep.berlios.de> Author: axeld Date: 2007-10-18 15:41:18 +0200 (Thu, 18 Oct 2007) New Revision: 22613 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22613&view=rev Modified: haiku/trunk/src/servers/app/ServerScreen.cpp Log: As the commit says, don't do this at this place. Modified: haiku/trunk/src/servers/app/ServerScreen.cpp =================================================================== --- haiku/trunk/src/servers/app/ServerScreen.cpp 2007-10-18 09:57:15 UTC (rev 22612) +++ haiku/trunk/src/servers/app/ServerScreen.cpp 2007-10-18 13:41:18 UTC (rev 22613) @@ -109,12 +109,8 @@ // search for a matching mode display_mode mode; status_t status = _FindMode(width, height, colorspace, frequency, &mode); - if (status < B_OK) { - // TODO: Move fallback elsewhere, this function should simply - // fail if requested to set unsupported mode. - // Ups. Not good. Ignore the requested mode and use fallback params. - status = _FindMode(640, 480, B_CMAP8, 60.0, &mode); - } + if (status < B_OK) + return status; if (status >= B_OK) { float modeFrequency = get_mode_frequency(mode); From axeld at mail.berlios.de Thu Oct 18 15:49:37 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 18 Oct 2007 15:49:37 +0200 Subject: [Haiku-commits] r22614 - haiku/trunk/src/servers/app Message-ID: <200710181349.l9IDnbBu024201@sheep.berlios.de> Author: axeld Date: 2007-10-18 15:49:36 +0200 (Thu, 18 Oct 2007) New Revision: 22614 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22614&view=rev Modified: haiku/trunk/src/servers/app/Desktop.cpp haiku/trunk/src/servers/app/ServerWindow.cpp haiku/trunk/src/servers/app/WorkspacesLayer.cpp Log: Fixed a few potential deadlocks: * in r22410 the unlock/relock was removed accidently from ServerWindow::_Hide() before calling a desktop method. * Desktop::ActivateWindow() no longer calls SetWorkspace() with the window lock held. * WorkspacesLayer::MouseUp() now uses the asynchronous version of SetWorkspace(). * AFAICT AS_HIDE_WINDOW, AS_SHOW_WINDOW, and AS_MINIMIZE_WINDOW don't need the all window lock, reverted to standard single window lock. Modified: haiku/trunk/src/servers/app/Desktop.cpp =================================================================== --- haiku/trunk/src/servers/app/Desktop.cpp 2007-10-18 13:41:18 UTC (rev 22613) +++ haiku/trunk/src/servers/app/Desktop.cpp 2007-10-18 13:49:36 UTC (rev 22614) @@ -618,7 +618,8 @@ PostMessage(kMsgQuitLooper); break; - case AS_ACTIVATE_WORKSPACE: { + case AS_ACTIVATE_WORKSPACE: + { int32 index; link.Read(&index); @@ -814,7 +815,6 @@ /*! Changes the current workspace to the one specified by \a index. - You must not hold any window lock when calling this method. */ void Desktop::SetWorkspaceAsync(int32 index) @@ -836,7 +836,8 @@ LockAllWindows(); DesktopSettings settings(this); - if (index < 0 || index >= settings.WorkspacesCount() || index == fCurrentWorkspace) { + if (index < 0 || index >= settings.WorkspacesCount() + || index == fCurrentWorkspace) { UnlockAllWindows(); return; } @@ -1390,29 +1391,15 @@ fFront = NULL; return; } - - bool windowOnOtherWorkspace = !window->InWorkspace(fCurrentWorkspace); - - if (windowOnOtherWorkspace - && (window->Flags() & B_NO_WORKSPACE_ACTIVATION) - && !(window->Flags() & B_NOT_ANCHORED_ON_ACTIVATE)) + if (window->Workspaces() == 0) return; // TODO: take care about floating windows - if (!LockAllWindows()) - return; - + bool windowOnOtherWorkspace = !window->InWorkspace(fCurrentWorkspace); if (windowOnOtherWorkspace) { - // if the window wants to come to the current workspace, - // do so here - else activate the workspace on which this - // window is - if (window->Flags() & B_NOT_ANCHORED_ON_ACTIVATE) { - // bring the window to the current workspace - // TODO: what if this window is on multiple workspaces?!? - uint32 workspaces = workspace_to_workspaces(fCurrentWorkspace); - SetWindowWorkspaces(window, workspaces); - } else { + if ((window->Flags() & B_NO_WORKSPACE_ACTIVATION) == 0 + && (window->Flags() & B_NOT_ANCHORED_ON_ACTIVATE) == 0) { // switch to the workspace on which this window is // (we'll take the first one that the window is on) uint32 workspaces = window->Workspaces(); @@ -1420,12 +1407,25 @@ uint32 workspace = workspace_to_workspaces(i); if (workspaces & workspace) { SetWorkspace(i); + windowOnOtherWorkspace = false; break; } } - } + } else if ((window->Flags() & B_NOT_ANCHORED_ON_ACTIVATE) == 0) + return; } + if (!LockAllWindows()) + return; + + if (windowOnOtherWorkspace + && (window->Flags() & B_NOT_ANCHORED_ON_ACTIVATE) != 0) { + // bring the window to the current workspace + // TODO: what if this window is on multiple workspaces?!? + uint32 workspaces = workspace_to_workspaces(fCurrentWorkspace); + SetWindowWorkspaces(window, workspaces); + } + if (window == FrontWindow()) { // see if there is a normal B_AVOID_FRONT window still in front of us WindowLayer* avoidsFront = window->NextWindow(fCurrentWorkspace); Modified: haiku/trunk/src/servers/app/ServerWindow.cpp =================================================================== --- haiku/trunk/src/servers/app/ServerWindow.cpp 2007-10-18 13:41:18 UTC (rev 22613) +++ haiku/trunk/src/servers/app/ServerWindow.cpp 2007-10-18 13:49:36 UTC (rev 22614) @@ -368,16 +368,11 @@ if (fQuitting || !fWindowLayer->IsHidden() || fWindowLayer->IsOffscreenWindow()) return; -// TODO: deadlock. Desktop::ShowWindow() will eventually lock the event thread, -// which might be blocking on the all window lock with it's own lock already -// head. -// Maybe we need to dispatch a message to the desktop to show/hide us -// instead of doing it from this thread. -//fDesktop->UnlockSingleWindow(); -fDesktop->UnlockAllWindows(); + // TODO: Maybe we need to dispatch a message to the desktop to show/hide us + // instead of doing it from this thread. + fDesktop->UnlockSingleWindow(); fDesktop->ShowWindow(fWindowLayer); -fDesktop->LockAllWindows(); -//fDesktop->LockSingleWindow(); + fDesktop->LockSingleWindow(); if (fDirectWindowData != NULL) HandleDirectConnection(B_DIRECT_START | B_BUFFER_RESET); @@ -397,9 +392,9 @@ if (fDirectWindowData != NULL) HandleDirectConnection(B_DIRECT_STOP); -// TODO: race condition? maybe we need to dispatch a message to the desktop to show/hide us -// instead of doing it from this thread. + fDesktop->UnlockSingleWindow(); fDesktop->HideWindow(fWindowLayer); + fDesktop->LockSingleWindow(); } @@ -3195,9 +3190,6 @@ ServerWindow::_MessageNeedsAllWindowsLocked(uint32 code) const { switch (code) { - case AS_SHOW_WINDOW: - case AS_HIDE_WINDOW: - case AS_MINIMIZE_WINDOW: case AS_ACTIVATE_WINDOW: case AS_SET_WINDOW_TITLE: case AS_ADD_TO_SUBSET: Modified: haiku/trunk/src/servers/app/WorkspacesLayer.cpp =================================================================== --- haiku/trunk/src/servers/app/WorkspacesLayer.cpp 2007-10-18 13:41:18 UTC (rev 22613) +++ haiku/trunk/src/servers/app/WorkspacesLayer.cpp 2007-10-18 13:49:36 UTC (rev 22614) @@ -432,7 +432,7 @@ int32 index; _WorkspaceAt(where, index); if (index >= 0) - Window()->Desktop()->SetWorkspace(index); + Window()->Desktop()->SetWorkspaceAsync(index); } if (fSelectedWindow != NULL) { From axeld at mail.berlios.de Thu Oct 18 19:23:15 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 18 Oct 2007 19:23:15 +0200 Subject: [Haiku-commits] r22615 - haiku/trunk/headers/private/kernel/fs Message-ID: <200710181723.l9IHNF2Z020728@sheep.berlios.de> Author: axeld Date: 2007-10-18 19:23:14 +0200 (Thu, 18 Oct 2007) New Revision: 22615 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22615&view=rev Modified: haiku/trunk/headers/private/kernel/fs/devfs.h Log: Fixed warning when compiling the PS/2 bus manager. Modified: haiku/trunk/headers/private/kernel/fs/devfs.h =================================================================== --- haiku/trunk/headers/private/kernel/fs/devfs.h 2007-10-18 13:49:36 UTC (rev 22614) +++ haiku/trunk/headers/private/kernel/fs/devfs.h 2007-10-18 17:23:14 UTC (rev 22615) @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Copyright 2002-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. * Distributed under the terms of the MIT License. * * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. @@ -11,7 +11,9 @@ #include +struct kernel_args; + #ifdef __cplusplus extern "C" { #endif From axeld at mail.berlios.de Thu Oct 18 19:24:07 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 18 Oct 2007 19:24:07 +0200 Subject: [Haiku-commits] r22616 - haiku/trunk/src/add-ons/kernel/bus_managers/ps2 Message-ID: <200710181724.l9IHO7k4020774@sheep.berlios.de> Author: axeld Date: 2007-10-18 19:24:07 +0200 (Thu, 18 Oct 2007) New Revision: 22616 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22616&view=rev Modified: haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_common.c haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_common.h Log: Minor cleanup. Modified: haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_common.c =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_common.c 2007-10-18 17:23:14 UTC (rev 22615) +++ haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_common.c 2007-10-18 17:24:07 UTC (rev 22616) @@ -1,6 +1,6 @@ /* * Copyright 2004-2007 Haiku, Inc. - * Distributed under the terms of the Haiku License. + * Distributed under the terms of the MIT License. * * Authors (in chronological order): * Stefano Ceccherini (burton666 at libero.it) @@ -16,14 +16,14 @@ #include "ps2_service.h" #include "ps2_dev.h" + isa_module_info *gIsa = NULL; +bool gActiveMultiplexingEnabled = false; +sem_id gControllerSem; static int32 sIgnoreInterrupts = 0; -bool gActiveMultiplexingEnabled = false; -sem_id gControllerSem; - uint8 ps2_read_ctrl(void) { @@ -84,6 +84,7 @@ // #pragma mark - + void ps2_flush(void) { @@ -133,7 +134,8 @@ if (res != B_OK) cmdbyte = 0x47; - cmdbyte |= PS2_BITS_TRANSLATE_SCANCODES | PS2_BITS_KEYBOARD_INTERRUPT | PS2_BITS_AUX_INTERRUPT; + cmdbyte |= PS2_BITS_TRANSLATE_SCANCODES | PS2_BITS_KEYBOARD_INTERRUPT + | PS2_BITS_AUX_INTERRUPT; cmdbyte &= ~(PS2_BITS_KEYBOARD_DISABLED | PS2_BITS_MOUSE_DISABLED); res = ps2_command(PS2_CTRL_WRITE_CMD, &cmdbyte, 1, NULL, 0); @@ -192,8 +194,9 @@ *enabled = false; done: - // Some controllers get upset by the d3 command and will continue data loopback, - // thus we need to send a harmless command (enable keyboard interface) next + // Some controllers get upset by the d3 command and will continue data + // loopback, thus we need to send a harmless command (enable keyboard + // interface) next. // This fixes bug report #1175 res = ps2_command(0xae, NULL, 0, NULL, 0); if (res != B_OK) { @@ -206,17 +209,12 @@ *enabled = false; // this should revert the controller into legacy mode, // just in case it has switched to multiplexed mode - res = ps2_command(PS2_CTRL_SELF_TEST, NULL, 0, &in, 1); - if (res != B_OK || in != 0x55) { - INFO("ps2: controller self test failed, status 0x%08lx, data 0x%02x\n", res, in); - return B_ERROR; - } - return B_OK; + return ps2_selftest(); } status_t -ps2_command(uint8 cmd, const uint8 *out, int out_count, uint8 *in, int in_count) +ps2_command(uint8 cmd, const uint8 *out, int outCount, uint8 *in, int inCount) { status_t res; int i; @@ -224,15 +222,17 @@ acquire_sem(gControllerSem); atomic_add(&sIgnoreInterrupts, 1); - TRACE("ps2: ps2_command cmd 0x%02x, out %d, in %d\n", cmd, out_count, in_count); - for (i = 0; i < out_count; i++) +#ifdef TRACE_PS2 + TRACE("ps2: ps2_command cmd 0x%02x, out %d, in %d\n", cmd, outCount, inCount); + for (i = 0; i < outCount; i++) TRACE("ps2: ps2_command out 0x%02x\n", out[i]); +#endif res = ps2_wait_write(); if (res == B_OK) ps2_write_ctrl(cmd); - for (i = 0; res == B_OK && i < out_count; i++) { + for (i = 0; res == B_OK && i < outCount; i++) { res = ps2_wait_write(); if (res == B_OK) ps2_write_data(out[i]); @@ -240,7 +240,7 @@ TRACE("ps2: ps2_command out byte %d failed\n", i); } - for (i = 0; res == B_OK && i < in_count; i++) { + for (i = 0; res == B_OK && i < inCount; i++) { res = ps2_wait_read(); if (res == B_OK) in[i] = ps2_read_data(); @@ -248,9 +248,11 @@ TRACE("ps2: ps2_command in byte %d failed\n", i); } - for (i = 0; i < in_count; i++) +#ifdef TRACE_PS2 + for (i = 0; i < inCount; i++) TRACE("ps2: ps2_command in 0x%02x\n", in[i]); TRACE("ps2: ps2_command result 0x%08lx\n", res); +#endif atomic_add(&sIgnoreInterrupts, -1); release_sem(gControllerSem); @@ -338,16 +340,18 @@ if (status < B_OK) goto err2; - status = install_io_interrupt_handler(INT_PS2_KEYBOARD, &ps2_interrupt, NULL, 0); + status = install_io_interrupt_handler(INT_PS2_KEYBOARD, &ps2_interrupt, + NULL, 0); if (status) goto err3; - status = install_io_interrupt_handler(INT_PS2_MOUSE, &ps2_interrupt, NULL, 0); + status = install_io_interrupt_handler(INT_PS2_MOUSE, &ps2_interrupt, NULL, + 0); if (status) goto err4; ps2_selftest(); - + status = ps2_setup_command_byte(); if (status) { INFO("ps2: setting up command byte failed\n"); @@ -361,7 +365,8 @@ } if (gActiveMultiplexingEnabled) { - if (B_TIMED_OUT == ps2_dev_command_timeout(&ps2_device[PS2_DEVICE_MOUSE], 0xe6, NULL, 0, NULL, 0, 100000)) { + if (ps2_dev_command_timeout(&ps2_device[PS2_DEVICE_MOUSE], 0xe6, + NULL, 0, NULL, 0, 100000) == B_TIMED_OUT) { INFO("ps2: accessing multiplexed mouse port 0 timed out, ignoring it!\n"); } else { ps2_service_notify_device_added(&ps2_device[PS2_DEVICE_MOUSE]); @@ -374,13 +379,12 @@ ps2_service_notify_device_added(&ps2_device[PS2_DEVICE_MOUSE]); ps2_service_notify_device_added(&ps2_device[PS2_DEVICE_KEYB]); } - + TRACE("ps2: init done!\n"); - return B_OK; err5: - remove_io_interrupt_handler(INT_PS2_MOUSE, &ps2_interrupt, NULL); + remove_io_interrupt_handler(INT_PS2_MOUSE, &ps2_interrupt, NULL); err4: remove_io_interrupt_handler(INT_PS2_KEYBOARD, &ps2_interrupt, NULL); err3: Modified: haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_common.h =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_common.h 2007-10-18 17:23:14 UTC (rev 22615) +++ haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_common.h 2007-10-18 17:24:07 UTC (rev 22616) @@ -29,7 +29,8 @@ # define INFO(x...) #endif -#if 0 +//#define TRACE_PS2 +#ifdef TRACE_PS2 # define TRACE(x...) dprintf(x) #else # define TRACE(x...) From axeld at mail.berlios.de Thu Oct 18 19:27:40 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 18 Oct 2007 19:27:40 +0200 Subject: [Haiku-commits] r22617 - haiku/trunk/src/add-ons/kernel/bus_managers/ps2 Message-ID: <200710181727.l9IHReI1021056@sheep.berlios.de> Author: axeld Date: 2007-10-18 19:27:39 +0200 (Thu, 18 Oct 2007) New Revision: 22617 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22617&view=rev Modified: haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_common.c Log: Found and fixed the reboot problem of most of my systems: by binary searching through our revisions, I found r20883 to be the cause of this problem. This one obviously fixed bug #1185, but I'm afraid there has to be another solution for this problem. Modified: haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_common.c =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_common.c 2007-10-18 17:24:07 UTC (rev 22616) +++ haiku/trunk/src/add-ons/kernel/bus_managers/ps2/ps2_common.c 2007-10-18 17:27:39 UTC (rev 22617) @@ -350,7 +350,10 @@ if (status) goto err4; - ps2_selftest(); + // While this might have fixed bug #1185, we can't do this unconditionally + // as it obviously messes up many controllers which couldn't reboot anymore + // after that + //ps2_selftest(); status = ps2_setup_command_byte(); if (status) { From korli at mail.berlios.de Thu Oct 18 22:44:21 2007 From: korli at mail.berlios.de (korli at BerliOS) Date: Thu, 18 Oct 2007 22:44:21 +0200 Subject: [Haiku-commits] r22618 - haiku/trunk/src/servers/media_addon Message-ID: <200710182044.l9IKiL7A032581@sheep.berlios.de> Author: korli Date: 2007-10-18 22:44:20 +0200 (Thu, 18 Oct 2007) New Revision: 22618 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22618&view=rev Modified: haiku/trunk/src/servers/media_addon/main.cpp Log: clean up Modified: haiku/trunk/src/servers/media_addon/main.cpp =================================================================== --- haiku/trunk/src/servers/media_addon/main.cpp 2007-10-18 17:27:39 UTC (rev 22617) +++ haiku/trunk/src/servers/media_addon/main.cpp 2007-10-18 20:44:20 UTC (rev 22618) @@ -34,7 +34,6 @@ #include #include #include -#include #include "debug.h" #include "TMap.h" #include "ServerInterface.h" From julun at mail.berlios.de Fri Oct 19 00:36:31 2007 From: julun at mail.berlios.de (julun at BerliOS) Date: Fri, 19 Oct 2007 00:36:31 +0200 Subject: [Haiku-commits] r22619 - haiku/trunk/src/preferences/time Message-ID: <200710182236.l9IMaV0R028276@sheep.berlios.de> Author: julun Date: 2007-10-19 00:36:30 +0200 (Fri, 19 Oct 2007) New Revision: 22619 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22619&view=rev Modified: haiku/trunk/src/preferences/time/SettingsView.cpp haiku/trunk/src/preferences/time/SettingsView.h Log: * more work towards working central settings, only Deskbar for the moment settings are not saved atm... Modified: haiku/trunk/src/preferences/time/SettingsView.cpp =================================================================== --- haiku/trunk/src/preferences/time/SettingsView.cpp 2007-10-18 20:44:20 UTC (rev 22618) +++ haiku/trunk/src/preferences/time/SettingsView.cpp 2007-10-18 22:36:30 UTC (rev 22619) @@ -19,20 +19,25 @@ const uint32 kMsgMilTime = 'MilT'; -const uint32 kMsgEuroDate = 'EDat'; const uint32 kMsgShowSeconds = 'ShSc'; -const uint32 kYearMonthDay = '_ymd'; -const uint32 kDayMonthYear = '_dmy'; + +const uint32 kMsgIsoDate = 'IDat'; +const uint32 kMsgEuroDate = 'EDat'; const uint32 kMonthDayYear = '_mdy'; const uint32 kSeparatorChanged = '_tsc'; const uint32 kTrackerDateFormatChanged = 'TDFC'; +const char* kDeskbarSignature = "application/x-vnd.Be-TSKB"; +const char* kTrackerSignature = "application/x-vnd.Be-TRAK"; + + SettingsView::SettingsView(BRect frame) - : BView(frame,"Settings", B_FOLLOW_ALL, + : BView(frame, "Settings", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP), - fInitialized(false) + fInitialized(false), + fRecentDateWhat(kMonthDayYear) { } @@ -58,7 +63,22 @@ void SettingsView::MessageReceived(BMessage *message) { - BView::MessageReceived(message); + switch (message->what) { + case kMsgMilTime: + case kMsgIsoDate: + _UpdateTimeSettings(message->what); + break; + + case kMsgEuroDate: + case kMonthDayYear: + case kMsgShowSeconds: + _UpdateDateSettings(message->what); + break; + + default: + BView::MessageReceived(message); + break; + } } @@ -80,12 +100,14 @@ fShow24Hours = new BCheckBox(frameLeft, "show24Hours", "24 Hour Clock" , new BMessage(kMsgMilTime)); AddChild(fShow24Hours); + fShow24Hours->SetTarget(this); fShow24Hours->ResizeToPreferred(); frameLeft.OffsetBy(0.0, fShow24Hours->Bounds().Height() + 5.0); fShowSeconds = new BCheckBox(frameLeft, "showSeconds", "Show Seconds" , new BMessage(kMsgShowSeconds)); AddChild(fShowSeconds); + fShowSeconds->SetTarget(this); fShowSeconds->ResizeToPreferred(); frameLeft.OffsetBy(0.0, 2 * fShowSeconds->Bounds().Height() + 5.0); @@ -105,33 +127,44 @@ frameRight.left = frameRight.Width() / 2; frameRight.InsetBy(10.0f, 10.0f); + BView *dateView = new BView(frameRight, "dateView", B_FOLLOW_ALL, + B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP); + AddChild(dateView); + if (Parent()) + dateView->SetViewColor(Parent()->ViewColor()); + + frameRight.OffsetTo(B_ORIGIN); BStringView *dateSettings = new BStringView(frameRight, "date", "Date:"); - AddChild(dateSettings); + dateView->AddChild(dateSettings); dateSettings->ResizeToPreferred(); frameRight.OffsetBy(10.0, dateSettings->Bounds().Height() + 5.0); - fYearMonthDay = new BCheckBox(frameRight, "yearMonthDay", "Year-Month-Day" - , new BMessage(kYearMonthDay)); - AddChild(fYearMonthDay); + fYearMonthDay = new BRadioButton(frameRight, "yearMonthDay", "Year-Month-Day" + , new BMessage(kMsgIsoDate)); + dateView->AddChild(fYearMonthDay); + fYearMonthDay->SetTarget(this); fYearMonthDay->ResizeToPreferred(); frameRight.OffsetBy(0.0, fYearMonthDay->Bounds().Height() + 5.0); - fDayMonthYear = new BCheckBox(frameRight, "dayMonthYear", "Day-Month-Year" - , new BMessage(kDayMonthYear)); - AddChild(fDayMonthYear); + fDayMonthYear = new BRadioButton(frameRight, "dayMonthYear", "Day-Month-Year" + , new BMessage(kMsgEuroDate)); + dateView->AddChild(fDayMonthYear); + fDayMonthYear->SetTarget(this); fDayMonthYear->ResizeToPreferred(); frameRight.OffsetBy(0.0, fDayMonthYear->Bounds().Height() + 5.0); - fMonthDayYear = new BCheckBox(frameRight, "monthDayYear", "Month-Day-Year" + fMonthDayYear = new BRadioButton(frameRight, "monthDayYear", "Month-Day-Year" , new BMessage(kMonthDayYear)); - AddChild(fMonthDayYear); + dateView->AddChild(fMonthDayYear); + fMonthDayYear->SetTarget(this); fMonthDayYear->ResizeToPreferred(); fMonthDayYear->SetValue(B_CONTROL_ON); frameRight.OffsetBy(0.0, fMonthDayYear->Bounds().Height() + 5.0); fStartWeekMonday = new BCheckBox(frameRight, "startWeekMonday" , "Start week with Monday", new BMessage(kWeekStart)); - AddChild(fStartWeekMonday); + dateView->AddChild(fStartWeekMonday); + fStartWeekMonday->SetTarget(this); fStartWeekMonday->ResizeToPreferred(); fDateSeparator = new BPopUpMenu("Separator"); @@ -147,6 +180,28 @@ frameRight.OffsetBy(0.0, fStartWeekMonday->Bounds().Height() + 5.0); BMenuField *menuField = new BMenuField(frameRight, "regions", "Date separator:" , fDateSeparator, false); - AddChild(menuField); + dateView->AddChild(menuField); menuField->ResizeToPreferred(); } + + +void +SettingsView::_UpdateDateSettings(const uint32 _what) +{ + uint32 what = _what; + if (_what == kMonthDayYear) + what = fRecentDateWhat; + + fRecentDateWhat = _what; + + BMessenger messenger(kDeskbarSignature); + messenger.SendMessage(what); +} + + +void +SettingsView::_UpdateTimeSettings(const uint32 what) const +{ + BMessenger messenger(kDeskbarSignature); + messenger.SendMessage(what); +} Modified: haiku/trunk/src/preferences/time/SettingsView.h =================================================================== --- haiku/trunk/src/preferences/time/SettingsView.h 2007-10-18 20:44:20 UTC (rev 22618) +++ haiku/trunk/src/preferences/time/SettingsView.h 2007-10-18 22:36:30 UTC (rev 22619) @@ -28,6 +28,8 @@ private: void _InitView(); + void _UpdateDateSettings(const uint32 what); + void _UpdateTimeSettings(const uint32 what) const; private: BCheckBox *fShow24Hours; @@ -35,14 +37,15 @@ BRadioButton *fGmtTime; BRadioButton *fLocalTime; - BCheckBox *fYearMonthDay; - BCheckBox *fDayMonthYear; - BCheckBox *fMonthDayYear; + BRadioButton *fYearMonthDay; + BRadioButton *fDayMonthYear; + BRadioButton *fMonthDayYear; BCheckBox *fStartWeekMonday; BPopUpMenu *fDateSeparator; bool fInitialized; + uint32 fRecentDateWhat; }; #endif // SETTINGS_VIEW_H From bonefish at mail.berlios.de Fri Oct 19 05:18:31 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Fri, 19 Oct 2007 05:18:31 +0200 Subject: [Haiku-commits] r22620 - in haiku/trunk/src/kits/storage: . disk_device disk_device/jobs Message-ID: <200710190318.l9J3IVpD010092@sheep.berlios.de> Author: bonefish Date: 2007-10-19 05:18:28 +0200 (Fri, 19 Oct 2007) New Revision: 22620 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22620&view=rev Added: haiku/trunk/src/kits/storage/disk_device/DiskDeviceJob.cpp haiku/trunk/src/kits/storage/disk_device/DiskDeviceJob.h haiku/trunk/src/kits/storage/disk_device/DiskDeviceJobQueue.cpp haiku/trunk/src/kits/storage/disk_device/DiskDeviceJobQueue.h haiku/trunk/src/kits/storage/disk_device/DiskDeviceUtils.h haiku/trunk/src/kits/storage/disk_device/PartitionReference.cpp haiku/trunk/src/kits/storage/disk_device/PartitionReference.h haiku/trunk/src/kits/storage/disk_device/jobs/ haiku/trunk/src/kits/storage/disk_device/jobs/InitializeJob.cpp haiku/trunk/src/kits/storage/disk_device/jobs/InitializeJob.h Modified: haiku/trunk/src/kits/storage/Jamfile haiku/trunk/src/kits/storage/disk_device/DiskDevice.cpp haiku/trunk/src/kits/storage/disk_device/DiskDeviceJobGenerator.cpp haiku/trunk/src/kits/storage/disk_device/DiskDeviceJobGenerator.h haiku/trunk/src/kits/storage/disk_device/MutablePartition.cpp Log: * Added base class of job classes DiskDeviceJob and job container class DiskDeviceJobQueue. * Basic synchronous implementation of BDiskDevice::CommitModifications(), ignoring the given parameters, though. * Some more work on DiskDeviceJobGenerator: Added class PartitionReference which will reference a partition while the jobs are executed. The generator manages the mapping of partitions to those references now. Also exemplarily implemented the generation of the InitializeJob. * Moved support functionality to private header DiskDeviceUtils.h. Modified: haiku/trunk/src/kits/storage/Jamfile =================================================================== --- haiku/trunk/src/kits/storage/Jamfile 2007-10-18 22:36:30 UTC (rev 22619) +++ haiku/trunk/src/kits/storage/Jamfile 2007-10-19 03:18:28 UTC (rev 22620) @@ -12,6 +12,7 @@ UsePublicHeaders [ FDirName add-ons registrar ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) disk_device ] ; +SEARCH_SOURCE += [ FDirName $(SUBDIR) disk_device jobs ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) mime ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) sniffer ] ; @@ -72,6 +73,9 @@ # disk device API DiskDevice.cpp + DiskDeviceJob.cpp + DiskDeviceJobGenerator.cpp + DiskDeviceJobQueue.cpp DiskDeviceList.cpp DiskDevicePrivate.cpp DiskDeviceRoster.cpp @@ -84,6 +88,9 @@ Partition.cpp PartitionDelegate.cpp PartitioningInfo.cpp + PartitionReference.cpp + + InitializeJob.cpp ; Modified: haiku/trunk/src/kits/storage/disk_device/DiskDevice.cpp =================================================================== --- haiku/trunk/src/kits/storage/disk_device/DiskDevice.cpp 2007-10-18 22:36:30 UTC (rev 22619) +++ haiku/trunk/src/kits/storage/disk_device/DiskDevice.cpp 2007-10-19 03:18:28 UTC (rev 22620) @@ -23,6 +23,9 @@ #include #include +#include "DiskDeviceJob.h" +#include "DiskDeviceJobGenerator.h" +#include "DiskDeviceJobQueue.h" #include "DiskSystemAddOnManager.h" @@ -276,6 +279,7 @@ BDiskDevice::CommitModifications(bool synchronously, BMessenger progressMessenger, bool receiveCompleteProgressUpdates) { +// TODO: Support parameters! status_t error = InitCheck(); if (error != B_OK) return error; @@ -283,8 +287,14 @@ if (!fDelegate) return B_BAD_VALUE; - // TODO: Implement! + // generate jobs + DiskDeviceJobQueue jobQueue; + error = DiskDeviceJobGenerator(this, &jobQueue).GenerateJobs(); + // do the jobs + if (error == B_OK) + error = jobQueue.Execute(); + _DeleteDelegates(); DiskSystemAddOnManager::Default()->UnloadDiskSystems(); Added: haiku/trunk/src/kits/storage/disk_device/DiskDeviceJob.cpp =================================================================== --- haiku/trunk/src/kits/storage/disk_device/DiskDeviceJob.cpp 2007-10-18 22:36:30 UTC (rev 22619) +++ haiku/trunk/src/kits/storage/disk_device/DiskDeviceJob.cpp 2007-10-19 03:18:28 UTC (rev 22620) @@ -0,0 +1,33 @@ +/* + * Copyright 2007, Ingo Weinhold, ingo_weinhold at gmx.de. + * Distributed under the terms of the MIT License. + */ + +#include "DiskDeviceJob.h" + +#include "PartitionReference.h" + + +// constructor +DiskDeviceJob::DiskDeviceJob(PartitionReference* partition, + PartitionReference* child) + : fPartition(partition), + fChild(child) +{ + if (fPartition) + fPartition->AddReference(); + + if (fChild) + fChild->AddReference(); +} + + +// destructor +DiskDeviceJob::~DiskDeviceJob() +{ + if (fPartition) + fPartition->RemoveReference(); + + if (fChild) + fChild->RemoveReference(); +} Added: haiku/trunk/src/kits/storage/disk_device/DiskDeviceJob.h =================================================================== --- haiku/trunk/src/kits/storage/disk_device/DiskDeviceJob.h 2007-10-18 22:36:30 UTC (rev 22619) +++ haiku/trunk/src/kits/storage/disk_device/DiskDeviceJob.h 2007-10-19 03:18:28 UTC (rev 22620) @@ -0,0 +1,35 @@ +/* + * Copyright 2007, Ingo Weinhold, ingo_weinhold at gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _DISK_DEVICE_JOB_H +#define _DISK_DEVICE_JOB_H + +#include + + +namespace BPrivate { + + +class PartitionReference; + + +class DiskDeviceJob { +public: + DiskDeviceJob(PartitionReference* partition, + PartitionReference* child = NULL); + virtual ~DiskDeviceJob(); + + virtual status_t Do() = 0; + +protected: + PartitionReference* fPartition; + PartitionReference* fChild; +}; + + +} // namespace BPrivate + +using BPrivate::DiskDeviceJob; + +#endif // _DISK_DEVICE_JOB_H Modified: haiku/trunk/src/kits/storage/disk_device/DiskDeviceJobGenerator.cpp =================================================================== --- haiku/trunk/src/kits/storage/disk_device/DiskDeviceJobGenerator.cpp 2007-10-18 22:36:30 UTC (rev 22619) +++ haiku/trunk/src/kits/storage/disk_device/DiskDeviceJobGenerator.cpp 2007-10-19 03:18:28 UTC (rev 22620) @@ -14,9 +14,14 @@ #include +#include "DiskDeviceJob.h" +#include "DiskDeviceJobQueue.h" #include "PartitionDelegate.h" +#include "PartitionReference.h" +#include "InitializeJob.h" + using std::nothrow; @@ -45,8 +50,8 @@ } -// move_info -struct DiskDeviceJobGenerator::move_info { +// MoveInfo +struct DiskDeviceJobGenerator::MoveInfo { BPartition* partition; off_t position; off_t target_position; @@ -54,17 +59,38 @@ }; +// PartitionRefInfo +struct DiskDeviceJobGenerator::PartitionRefInfo { + PartitionRefInfo() + : partition(NULL), + reference(NULL) + { + } + + ~PartitionRefInfo() + { + if (reference) + reference->RemoveReference(); + } + + BPartition* partition; + PartitionReference* reference; +}; + + // constructor DiskDeviceJobGenerator::DiskDeviceJobGenerator(BDiskDevice* device, DiskDeviceJobQueue* jobQueue) : fDevice(device), fJobQueue(jobQueue), - fMoveInfos(NULL) + fMoveInfos(NULL), + fPartitionRefs(NULL) { - fMoveInfoCount = fDevice->CountDescendants(); + fPartitionCount = fDevice->CountDescendants(); - fMoveInfos = new(nothrow) move_info[fMoveInfoCount]; -// fPartitionIDs = new(nothrow) partition_id[fMoveInfoCount]; + fMoveInfos = new(nothrow) MoveInfo[fPartitionCount]; +// fPartitionIDs = new(nothrow) partition_id[fPartitionCount]; + fPartitionRefs = new(nothrow) PartitionRefInfo[fPartitionCount]; } @@ -73,6 +99,7 @@ { delete[] fMoveInfos; // delete[] fPartitionIDs; + delete[] fPartitionRefs; } @@ -81,11 +108,12 @@ DiskDeviceJobGenerator::GenerateJobs() { // check parameters - if (!fDevice || !fJobQueue /*|| !fMoveInfos || !fPartitionIDs - || fJobQueue->Device() != fDevice || !fDevice->ShadowPartition()*/) { + if (!fDevice || !fJobQueue) return B_BAD_VALUE; - } + if (!fMoveInfos /*|| !fPartitionIDs*/ || !fPartitionRefs) + return B_NO_MEMORY; + // 1) Generate jobs for all physical partitions that don't have an // associated shadow partition, i.e. those that shall be deleted. // 2) Generate uninitialize jobs for all partition whose initialization @@ -116,8 +144,14 @@ status_t DiskDeviceJobGenerator::_AddJob(DiskDeviceJob* job) { -// TODO: Implement! - return B_BAD_VALUE; + if (!job) + return B_NO_MEMORY; + + status_t error = fJobQueue->AddJob(job); + if (error != B_OK) + delete job; + + return error; } @@ -208,8 +242,8 @@ for (int32 i = 0; BPartition* child = partition->_ChildAt(i); i++) { if (BMutablePartition* childShadow = _GetMutablePartition(child)) { - // add a move_info for the child - move_info& info = fMoveInfos[childCount]; + // add a MoveInfo for the child + MoveInfo& info = fMoveInfos[childCount]; childCount++; info.partition = child; info.position = child->Offset(); @@ -233,7 +267,7 @@ // sort the move infos if (childCount > 0 && moveForth + moveBack > 0) { - qsort(fMoveInfos, childCount, sizeof(move_info), + qsort(fMoveInfos, childCount, sizeof(MoveInfo), _CompareMoveInfoPosition); } @@ -243,7 +277,7 @@ if (moveForth < moveBack) { // move children back for (int32 i = 0; i < childCount; i++) { - move_info &info = fMoveInfos[i]; + MoveInfo &info = fMoveInfos[i]; if (info.position > info.target_position) { if (i == 0 || info.target_position >= fMoveInfos[i - 1].position @@ -262,7 +296,7 @@ } else { // move children forth for (int32 i = childCount - 1; i >= 0; i--) { - move_info &info = fMoveInfos[i]; + MoveInfo &info = fMoveInfos[i]; if (info.position > info.target_position) { if (i == childCount - 1 || info.target_position + info.size @@ -430,8 +464,23 @@ status_t DiskDeviceJobGenerator::_GenerateInitializeJob(BPartition* partition) { -// TODO: Implement! - return B_BAD_VALUE; + PartitionReference* reference; + status_t error = _GetPartitionReference(partition, reference); + if (error != B_OK) + return error; + + InitializeJob* job = new(nothrow) InitializeJob(reference); + if (!job) + return B_NO_MEMORY; + + error = job->Init(partition->ContentType(), + partition->ContentName(), partition->ContentParameters()); + if (error != B_OK) { + delete job; + return error; + } + + return _AddJob(job); } @@ -557,12 +606,52 @@ } +// _GetPartitionReference +status_t +DiskDeviceJobGenerator::_GetPartitionReference(BPartition* partition, + PartitionReference*& reference) +{ + if (!partition) + return B_BAD_VALUE; + + for (int32 i = 0; i < fPartitionCount; i++) { + PartitionRefInfo& info = fPartitionRefs[i]; + + if (info.partition == partition) { + reference = info.reference; + return B_OK; + } + + if (info.partition == NULL) { + // create partition reference + info.reference = new(nothrow) PartitionReference(); + if (!info.reference) + return B_NO_MEMORY; + + // set partition ID and change counter + user_partition_data* partitionData = partition->fPartitionData; + if (partitionData) { + info.reference->SetPartitionID(partitionData->id); + info.reference->SetChangeCounter(partitionData->change_counter); + } + + info.partition = partition; + reference = info.reference; + return B_OK; + } + } + + // Out of slots -- that can't happen. + return B_ERROR; +} + + // _CompareMoveInfoOffset int DiskDeviceJobGenerator::_CompareMoveInfoPosition(const void* _a, const void* _b) { - const move_info* a = static_cast(_a); - const move_info* b = static_cast(_b); + const MoveInfo* a = static_cast(_a); + const MoveInfo* b = static_cast(_b); if (a->position < b->position) return -1; if (a->position > b->position) Modified: haiku/trunk/src/kits/storage/disk_device/DiskDeviceJobGenerator.h =================================================================== --- haiku/trunk/src/kits/storage/disk_device/DiskDeviceJobGenerator.h 2007-10-18 22:36:30 UTC (rev 22619) +++ haiku/trunk/src/kits/storage/disk_device/DiskDeviceJobGenerator.h 2007-10-19 03:18:28 UTC (rev 22620) @@ -18,6 +18,7 @@ class DiskDeviceJob; class DiskDeviceJobQueue; +class PartitionReference; class DiskDeviceJobGenerator { @@ -65,16 +66,21 @@ status_t _CollectContentsToMove(BPartition* partition); + status_t _GetPartitionReference(BPartition* partition, + PartitionReference*& reference); + static int _CompareMoveInfoPosition(const void* _a, const void* _b); private: - struct move_info; + struct MoveInfo; + struct PartitionRefInfo; BDiskDevice* fDevice; DiskDeviceJobQueue* fJobQueue; - move_info* fMoveInfos; - int32 fMoveInfoCount; + MoveInfo* fMoveInfos; + int32 fPartitionCount; + PartitionRefInfo* fPartitionRefs; }; Added: haiku/trunk/src/kits/storage/disk_device/DiskDeviceJobQueue.cpp =================================================================== --- haiku/trunk/src/kits/storage/disk_device/DiskDeviceJobQueue.cpp 2007-10-18 22:36:30 UTC (rev 22619) +++ haiku/trunk/src/kits/storage/disk_device/DiskDeviceJobQueue.cpp 2007-10-19 03:18:28 UTC (rev 22620) @@ -0,0 +1,48 @@ +/* + * Copyright 2007, Ingo Weinhold, ingo_weinhold at gmx.de. + * Distributed under the terms of the MIT License. + */ + +#include "DiskDeviceJobQueue.h" + +#include "DiskDeviceJob.h" + + +// constructor +DiskDeviceJobQueue::DiskDeviceJobQueue() + : fJobs(20, true) +{ +} + + +// destructor +DiskDeviceJobQueue::~DiskDeviceJobQueue() +{ +} + + +// AddJob +status_t +DiskDeviceJobQueue::AddJob(DiskDeviceJob* job) +{ + if (!job) + return B_BAD_VALUE; + + return fJobs.AddItem(job) ? B_OK : B_NO_MEMORY; +} + + +// Execute +status_t +DiskDeviceJobQueue::Execute() +{ + int32 count = fJobs.CountItems(); + for (int32 i = 0; i < count; i++) { + DiskDeviceJob* job = fJobs.ItemAt(i); + status_t error = job->Do(); + if (error != B_OK) + return error; + } + + return B_OK; +} Added: haiku/trunk/src/kits/storage/disk_device/DiskDeviceJobQueue.h =================================================================== --- haiku/trunk/src/kits/storage/disk_device/DiskDeviceJobQueue.h 2007-10-18 22:36:30 UTC (rev 22619) +++ haiku/trunk/src/kits/storage/disk_device/DiskDeviceJobQueue.h 2007-10-19 03:18:28 UTC (rev 22620) @@ -0,0 +1,38 @@ +/* + * Copyright 2007, Ingo Weinhold, ingo_weinhold at gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _DISK_DEVICE_JOB_QUEUE_H +#define _DISK_DEVICE_JOB_QUEUE_H + +#include +#include + + +namespace BPrivate { + + +class DiskDeviceJob; + + +class DiskDeviceJobQueue { +public: + DiskDeviceJobQueue(); + ~DiskDeviceJobQueue(); + + status_t AddJob(DiskDeviceJob* job); + + status_t Execute(); + +private: + typedef BObjectList JobList; + + JobList fJobs; +}; + + +} // namespace BPrivate + +using BPrivate::DiskDeviceJobQueue; + +#endif // _DISK_DEVICE_JOB_QUEUE_H Added: haiku/trunk/src/kits/storage/disk_device/DiskDeviceUtils.h =================================================================== --- haiku/trunk/src/kits/storage/disk_device/DiskDeviceUtils.h 2007-10-18 22:36:30 UTC (rev 22619) +++ haiku/trunk/src/kits/storage/disk_device/DiskDeviceUtils.h 2007-10-19 03:18:28 UTC (rev 22620) @@ -0,0 +1,47 @@ +/* + * Copyright 2007, Ingo Weinhold, ingo_weinhold at gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _DISK_DEVICE_UTILS_H +#define _DISK_DEVICE_UTILS_H + +#include +#include + +#include + + +namespace BPrivate { + + +// set_string +static inline status_t +set_string(char*& location, const char* newString) +{ + char* string = NULL; + if (newString) { + string = strdup(newString); + if (!string) + return B_NO_MEMORY; + } + + free(location); + location = string; + + return B_OK; +} + + +#define SET_STRING_RETURN_ON_ERROR(location, string) \ +{ \ + status_t error = set_string(location, string); \ + if (error != B_OK) \ + return error; \ +} + + +} // namespace BPrivate + +using BPrivate::set_string; + +#endif // _DISK_DEVICE_UTILS_H Modified: haiku/trunk/src/kits/storage/disk_device/MutablePartition.cpp =================================================================== --- haiku/trunk/src/kits/storage/disk_device/MutablePartition.cpp 2007-10-18 22:36:30 UTC (rev 22619) +++ haiku/trunk/src/kits/storage/disk_device/MutablePartition.cpp 2007-10-19 03:18:28 UTC (rev 22620) @@ -14,38 +14,13 @@ #include +#include "DiskDeviceUtils.h" #include "PartitionDelegate.h" using std::nothrow; -// set_string -static status_t -set_string(char*& location, const char* newString) -{ - char* string = NULL; - if (newString) { - string = strdup(newString); - if (!string) - return B_NO_MEMORY; - } - - free(location); - location = string; - - return B_OK; -} - - -#define SET_STRING_RETURN_ON_ERROR(location, string) \ -{ \ - status_t error = set_string(location, string); \ - if (error != B_OK) \ - return error; \ -} - - // Offset off_t BMutablePartition::Offset() const Added: haiku/trunk/src/kits/storage/disk_device/PartitionReference.cpp =================================================================== --- haiku/trunk/src/kits/storage/disk_device/PartitionReference.cpp 2007-10-18 22:36:30 UTC (rev 22619) +++ haiku/trunk/src/kits/storage/disk_device/PartitionReference.cpp 2007-10-19 03:18:28 UTC (rev 22620) @@ -0,0 +1,53 @@ +/* + * Copyright 2007, Ingo Weinhold, ingo_weinhold at gmx.de. + * Distributed under the terms of the MIT License. + */ + +#include "PartitionReference.h" + + +// constructor +PartitionReference::PartitionReference(partition_id id, uint32 changeCounter) + : Referenceable(true), // delete when unreferenced + fID(id), + fChangeCounter(changeCounter) +{ +} + + +// destructor +PartitionReference::~PartitionReference() +{ +} + + +// PartitionID +partition_id +PartitionReference::PartitionID() const +{ + return fID; +} + + +// SetPartitionID +void +PartitionReference::SetPartitionID(partition_id id) +{ + fID = id; +} + + +// ChangeCounter +uint32 +PartitionReference::ChangeCounter() const +{ + return fChangeCounter; +} + + +// SetChangeCounter +void +PartitionReference::SetChangeCounter(uint32 counter) +{ + fChangeCounter = counter; +} Added: haiku/trunk/src/kits/storage/disk_device/PartitionReference.h =================================================================== --- haiku/trunk/src/kits/storage/disk_device/PartitionReference.h 2007-10-18 22:36:30 UTC (rev 22619) +++ haiku/trunk/src/kits/storage/disk_device/PartitionReference.h 2007-10-19 03:18:28 UTC (rev 22620) @@ -0,0 +1,38 @@ +/* + * Copyright 2007, Ingo Weinhold, ingo_weinhold at gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _PARTITION_REFERENCE_H +#define _PARTITION_REFERENCE_H + +#include + +#include + + +namespace BPrivate { + + +class PartitionReference : public Referenceable { +public: + PartitionReference(partition_id id = -1, + uint32 changeCounter = 0); + ~PartitionReference(); + + partition_id PartitionID() const; + void SetPartitionID(partition_id id); + + uint32 ChangeCounter() const; + void SetChangeCounter(uint32 counter); + +private: + partition_id fID; + uint32 fChangeCounter; +}; + + +} // namespace BPrivate + +using BPrivate::PartitionReference; + +#endif // _PARTITION_REFERENCE_H Added: haiku/trunk/src/kits/storage/disk_device/jobs/InitializeJob.cpp =================================================================== --- haiku/trunk/src/kits/storage/disk_device/jobs/InitializeJob.cpp 2007-10-18 22:36:30 UTC (rev 22619) +++ haiku/trunk/src/kits/storage/disk_device/jobs/InitializeJob.cpp 2007-10-19 03:18:28 UTC (rev 22620) @@ -0,0 +1,51 @@ +/* + * Copyright 2007, Ingo Weinhold, ingo_weinhold at gmx.de. + * Distributed under the terms of the MIT License. + */ + +#include "InitializeJob.h" + +#include "DiskDeviceUtils.h" +#include "PartitionReference.h" + + +// constructor +InitializeJob::InitializeJob(PartitionReference* partition) + : DiskDeviceJob(partition), + fDiskSystem(NULL), + fName(NULL), + fParameters(NULL) +{ +} + + +// destructor +InitializeJob::~InitializeJob() +{ + free(fDiskSystem); + free(fName); + free(fParameters); +} + + +// Init +status_t +InitializeJob::Init(const char* diskSystem, const char* name, + const char* parameters) +{ + SET_STRING_RETURN_ON_ERROR(fDiskSystem, diskSystem); + SET_STRING_RETURN_ON_ERROR(fName, name); + SET_STRING_RETURN_ON_ERROR(fParameters, parameters); + + return B_OK; +} + + +// Do +status_t +InitializeJob::Do() +{ +// Implement! + return B_BAD_VALUE; +} + Added: haiku/trunk/src/kits/storage/disk_device/jobs/InitializeJob.h =================================================================== --- haiku/trunk/src/kits/storage/disk_device/jobs/InitializeJob.h 2007-10-18 22:36:30 UTC (rev 22619) +++ haiku/trunk/src/kits/storage/disk_device/jobs/InitializeJob.h 2007-10-19 03:18:28 UTC (rev 22620) @@ -0,0 +1,36 @@ +/* + * Copyright 2007, Ingo Weinhold, ingo_weinhold at gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _INITIALIZE_JOB_H +#define _INITIALIZE_JOB_H + +#include "DiskDeviceJob.h" + + +namespace BPrivate { + + +class InitializeJob : public DiskDeviceJob { +public: + + InitializeJob(PartitionReference* partition); + virtual ~InitializeJob(); + + status_t Init(const char* diskSystem, const char* name, + const char* parameters); + + virtual status_t Do(); + +protected: + char* fDiskSystem; + char* fName; + char* fParameters; +}; + + +} // namespace BPrivate + +using BPrivate::InitializeJob; + +#endif // _INITIALIZE_JOB_H From axeld at mail.berlios.de Fri Oct 19 17:20:37 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Fri, 19 Oct 2007 17:20:37 +0200 Subject: [Haiku-commits] r22621 - in haiku/trunk: headers/private/kernel/disk_device_manager src/system/kernel/disk_device_manager Message-ID: <200710191520.l9JFKbEo023570@sheep.berlios.de> Author: axeld Date: 2007-10-19 17:20:36 +0200 (Fri, 19 Oct 2007) New Revision: 22621 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22621&view=rev Modified: haiku/trunk/headers/private/kernel/disk_device_manager/KDiskDevice.h haiku/trunk/src/system/kernel/disk_device_manager/KDiskDevice.cpp haiku/trunk/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp Log: * Fixed a possible dead lock between the kernel daemon and the DDM; the media status checker now only tries to lock the manager, it won't wait anymore. * Added MediaChanged() and UpdateMediaStatusIfNeeded() methods to KDiskDevice. * KDiskDeviceManager::_CheckMediaStatus() now uses these new methods; it should no longer detect removed media more than once :-) Modified: haiku/trunk/headers/private/kernel/disk_device_manager/KDiskDevice.h =================================================================== --- haiku/trunk/headers/private/kernel/disk_device_manager/KDiskDevice.h 2007-10-19 03:18:28 UTC (rev 22620) +++ haiku/trunk/headers/private/kernel/disk_device_manager/KDiskDevice.h 2007-10-19 15:20:36 UTC (rev 22621) @@ -51,8 +51,9 @@ bool IsWriteOnce() const; bool IsRemovable() const; bool HasMedia() const; + bool MediaChanged() const; - virtual status_t GetMediaStatus(status_t *mediaStatus); + void UpdateMediaStatusIfNeeded(); status_t SetPath(const char *path); // TODO: Remove this method or make it private. Once initialized the @@ -81,6 +82,7 @@ virtual void Dump(bool deep = true, int32 level = 0); protected: + virtual status_t GetMediaStatus(status_t *mediaStatus); virtual status_t GetGeometry(device_geometry *geometry); private: Modified: haiku/trunk/src/system/kernel/disk_device_manager/KDiskDevice.cpp =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/KDiskDevice.cpp 2007-10-19 03:18:28 UTC (rev 22620) +++ haiku/trunk/src/system/kernel/disk_device_manager/KDiskDevice.cpp 2007-10-19 15:20:36 UTC (rev 22621) @@ -239,9 +239,26 @@ bool KDiskDevice::HasMedia() const { - return (fMediaStatus == B_OK); + return fMediaStatus == B_OK || fMediaStatus == B_DEV_MEDIA_CHANGED; } + +bool +KDiskDevice::MediaChanged() const +{ + return fMediaStatus == B_DEV_MEDIA_CHANGED; +} + + +void +KDiskDevice::UpdateMediaStatusIfNeeded() +{ + // TODO: allow a device to notify us about its media status! + // This will then also need to clear any B_DEV_MEDIA_CHANGED + GetMediaStatus(&fMediaStatus); +} + + // SetPath status_t KDiskDevice::SetPath(const char *path) Modified: haiku/trunk/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp 2007-10-19 03:18:28 UTC (rev 22620) +++ haiku/trunk/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp 2007-10-19 15:20:36 UTC (rev 22621) @@ -1252,8 +1252,7 @@ void KDiskDeviceManager::_CheckMediaStatus() { - ManagerLocker locker(this); - if (!locker.IsLocked()) + if (fLock.LockWithTimeout(0) != B_OK) return; int32 cookie = 0; @@ -1262,32 +1261,18 @@ if (device == NULL) break; - status_t mediaStatus; - if (device->GetMediaStatus(&mediaStatus) == B_OK) { - bool removed = false; - bool changed = false; + bool hadMedia = device->HasMedia(); + device->UpdateMediaStatusIfNeeded(); - switch (mediaStatus) { - case B_DEV_MEDIA_CHANGED: - changed = true; - break; - case B_DEV_NO_MEDIA: - case B_DEV_DOOR_OPEN: - removed = true; - break; - case B_DEV_MEDIA_CHANGE_REQUESTED: - case B_DEV_NOT_READY: - case B_OK: - break; - } - - // TODO: propagate changes! - if (removed) - dprintf("Media removed from %s\n", device->Path()); - if (changed) + // TODO: propagate changes! + if (device->MediaChanged()) { dprintf("Media changed from %s\n", device->Path()); + } else if (!device->HasMedia() && hadMedia) { + dprintf("Media removed from %s\n", device->Path()); } } + + fLock.Unlock(); } From axeld at mail.berlios.de Fri Oct 19 18:47:07 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Fri, 19 Oct 2007 18:47:07 +0200 Subject: [Haiku-commits] r22622 - haiku/trunk/src/servers/app Message-ID: <200710191647.l9JGl7QS029817@sheep.berlios.de> Author: axeld Date: 2007-10-19 18:47:06 +0200 (Fri, 19 Oct 2007) New Revision: 22622 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22622&view=rev Modified: haiku/trunk/src/servers/app/ServerScreen.cpp haiku/trunk/src/servers/app/ServerScreen.h haiku/trunk/src/servers/app/VirtualScreen.cpp haiku/trunk/src/servers/app/VirtualScreen.h Log: * The app_server now stores the whole display_timing structure of a mode, not just the frequency. * Previously saved modes are no longer supported, though. * Screen modes are now stored with the monitor info it belongs to, IOW the app_server will now choose a mode from the settings that fit your monitor description. Driver support is required for this to work as intended. * The changes are completely untested at this point, though, sorry (shouldn't harm anyone, though) :-) Modified: haiku/trunk/src/servers/app/ServerScreen.cpp =================================================================== --- haiku/trunk/src/servers/app/ServerScreen.cpp 2007-10-19 15:20:36 UTC (rev 22621) +++ haiku/trunk/src/servers/app/ServerScreen.cpp 2007-10-19 16:47:06 UTC (rev 22622) @@ -103,12 +103,27 @@ status_t -Screen::SetMode(uint16 width, uint16 height, uint32 colorspace, +Screen::SetMode(uint16 width, uint16 height, uint32 colorSpace, + const display_timing& timing, bool makeDefault) +{ + display_mode mode; + mode.virtual_width = width; + mode.virtual_height = height; + mode.space = colorSpace; + mode.timing = timing; + mode.flags = 0; + + return SetMode(mode, makeDefault); +} + + +status_t +Screen::SetMode(uint16 width, uint16 height, uint32 colorSpace, float frequency, bool makeDefault) { // search for a matching mode display_mode mode; - status_t status = _FindMode(width, height, colorspace, frequency, &mode); + status_t status = _FindMode(width, height, colorSpace, frequency, &mode); if (status < B_OK) return status; @@ -169,6 +184,13 @@ } +status_t +Screen::GetMonitorInfo(monitor_info& info) const +{ + return fHWInterface->GetMonitorInfo(&info); +} + + BRect Screen::Frame() const { Modified: haiku/trunk/src/servers/app/ServerScreen.h =================================================================== --- haiku/trunk/src/servers/app/ServerScreen.h 2007-10-19 15:20:36 UTC (rev 22621) +++ haiku/trunk/src/servers/app/ServerScreen.h 2007-10-19 16:47:06 UTC (rev 22622) @@ -29,19 +29,22 @@ void Shutdown(); int32 ID() const { return fID; } - status_t GetMonitorInfo(monitor_info& info); + status_t GetMonitorInfo(monitor_info& info) const; - status_t SetMode(const display_mode& mode, bool makeDefault); + status_t SetMode(const display_mode& mode, + bool makeDefault); status_t SetMode(uint16 width, uint16 height, uint32 colorspace, float frequency, bool makeDefault); + status_t SetMode(uint16 width, uint16 height, + uint32 colorspace, + const display_timing& timing, + bool makeDefault); status_t SetPreferredMode(); void GetMode(display_mode* mode) const; - void GetMode(uint16 &width, - uint16 &height, - uint32 &colorspace, - float &frequency) const; + void GetMode(uint16 &width, uint16 &height, + uint32 &colorspace, float &frequency) const; BRect Frame() const; color_space ColorSpace() const; @@ -53,15 +56,13 @@ { return fHWInterface; } private: - status_t _FindMode(uint16 width, - uint16 height, - uint32 colorspace, - float frequency, - display_mode* mode) const; + status_t _FindMode(uint16 width, uint16 height, + uint32 colorspace, float frequency, + display_mode* mode) const; int32 _FindMode(const display_mode* modeList, - uint32 count, uint16 width, uint16 height, - uint32 colorspace, float frequency) const; + uint32 count, uint16 width, uint16 height, + uint32 colorspace, float frequency) const; int32 fID; DrawingEngine* fDriver; Modified: haiku/trunk/src/servers/app/VirtualScreen.cpp =================================================================== --- haiku/trunk/src/servers/app/VirtualScreen.cpp 2007-10-19 15:20:36 UTC (rev 22621) +++ haiku/trunk/src/servers/app/VirtualScreen.cpp 2007-10-19 16:47:06 UTC (rev 22622) @@ -62,7 +62,8 @@ fSettings = *settings; ScreenList list; - status_t status = gScreenManager->AcquireScreens(&desktop, NULL, 0, false, list); + status_t status = gScreenManager->AcquireScreens(&desktop, NULL, 0, false, + list); if (status < B_OK) { // TODO: we would try again here with force == true return status; @@ -81,6 +82,8 @@ status_t VirtualScreen::StoreConfiguration(BMessage& settings) { + // store the configuration of all current screens + for (int32 i = 0; i < fScreenList.CountItems(); i++) { screen_item* item = fScreenList.ItemAt(i); Screen* screen = item->screen; @@ -89,23 +92,39 @@ BMessage screenSettings; screenSettings.AddInt32("id", screen->ID()); - //screenSettings.AddString("name", "-"); + + monitor_info info; + if (screen->GetMonitorInfo(info) == B_OK) { + screenSettings.AddString("vendor", info.vendor); + screenSettings.AddString("name", info.name); + screenSettings.AddInt32("product id", info.product_id); + screenSettings.AddString("serial", info.serial_number); + screenSettings.AddInt32("produced week", info.produced.week); + screenSettings.AddInt32("produced year", info.produced.year); + } + screenSettings.AddRect("frame", item->frame); - // TODO: or just store a display_mode completely? - uint16 width, height; - uint32 colorSpace; - float frequency; - screen->GetMode(width, height, colorSpace, frequency); + display_mode mode; + screen->GetMode(&mode); - screenSettings.AddInt32("width", width); - screenSettings.AddInt32("height", height); - screenSettings.AddInt32("color space", colorSpace); - screenSettings.AddFloat("frequency", frequency); + screenSettings.AddInt32("width", mode.virtual_width); + screenSettings.AddInt32("height", mode.virtual_height); + screenSettings.AddInt32("color space", mode.space); + screenSettings.AddData("timing", B_RAW_TYPE, &mode.timing, + sizeof(display_timing)); settings.AddMessage("screen", &screenSettings); } + // store the configuration of all monitors currently not attached + + BMessage screenSettings; + for (uint32 i = 0; fSettings.FindMessage("screen", i, + &screenSettings) == B_OK; i++) { + settings.AddMessage("screen", &screenSettings); + } + return B_OK; } @@ -124,12 +143,15 @@ if (_FindConfiguration(screen, settings) == B_OK) { // we found settings for this screen, and try to apply them now int32 width, height, colorSpace; - float frequency; + const display_timing* timing; + ssize_t size; if (settings.FindInt32("width", &width) == B_OK && settings.FindInt32("height", &height) == B_OK && settings.FindInt32("color space", &colorSpace) == B_OK - && settings.FindFloat("frequency", &frequency) == B_OK) - status = screen->SetMode(width, height, colorSpace, frequency, true); + && settings.FindData("timing", B_RAW_TYPE, (const void**)&timing, + &size) == B_OK + && size == sizeof(display_timing)) + status = screen->SetMode(width, height, colorSpace, *timing, true); } if (status < B_OK) { // TODO: more intelligent standard mode (monitor preference, desktop default, ...) @@ -220,18 +242,67 @@ status_t VirtualScreen::_FindConfiguration(Screen* screen, BMessage& settings) { - // TODO: we probably want to identify the resolution by connected monitor, - // and not the display driver used... - // For now, we just use the screen ID, which is almost nothing, anyway... + monitor_info info; + bool hasInfo = screen->GetMonitorInfo(info) == B_OK; + if (!hasInfo) { + // only look for a matching ID - this is all we have + for (uint32 i = 0; fSettings.FindMessage("screen", i, + &settings) == B_OK; i++) { + int32 id; + if (settings.FindInt32("id", &id) != B_OK + || screen->ID() != id) + continue; - uint32 i = 0; - while (fSettings.FindMessage("screen", i++, &settings) == B_OK) { + // we found our match + fSettings.RemoveData("screen", i); + return B_OK; + } + } + + // look for a monitor configuration that matches ours + + int32 bestScore = 0; + int32 bestIndex = -1; + BMessage stored; + for (uint32 i = 0; fSettings.FindMessage("screen", i, &stored) == B_OK; + i++) { + int32 score = 0; int32 id; - if (settings.FindInt32("id", &id) != B_OK - || screen->ID() != id) - continue; + if (stored.FindInt32("id", &id) == B_OK && screen->ID() == id) + score++; - // we found our match + const char* vendor; + const char* name; + uint32 productID; + const char* serial; + int32 week, year; + if (stored.FindString("vendor", &vendor) == B_OK + && stored.FindString("name", &name) == B_OK + && stored.FindInt32("product id", (int32*)&productID) == B_OK + && stored.FindString("serial", &serial) == B_OK + && stored.FindInt32("produced week", &week) == B_OK + && stored.FindInt32("produced year", &year) == B_OK) { + if (!strcasecmp(vendor, info.vendor) + && !strcasecmp(name, info.name) + && productID == info.product_id) { + score += 2; + if (!strcmp(serial, info.serial_number)) + score += 2; + if (info.produced.year == year && info.produced.week == week) + score++; + } else + score -= 2; + } + + if (score > bestScore) { + settings = stored; + bestScore = score; + bestIndex = i; + } + } + + if (bestIndex >= 0) { + fSettings.RemoveData("screen", bestIndex); return B_OK; } Modified: haiku/trunk/src/servers/app/VirtualScreen.h =================================================================== --- haiku/trunk/src/servers/app/VirtualScreen.h 2007-10-19 15:20:36 UTC (rev 22621) +++ haiku/trunk/src/servers/app/VirtualScreen.h 2007-10-19 16:47:06 UTC (rev 22622) @@ -31,7 +31,8 @@ ::HWInterface* HWInterface() const { return fHWInterface; } - status_t RestoreConfiguration(Desktop& desktop, const BMessage* settings); + status_t RestoreConfiguration(Desktop& desktop, + const BMessage* settings); status_t StoreConfiguration(BMessage& settings); status_t AddScreen(Screen* screen); @@ -49,7 +50,8 @@ int32 CountScreens() const; private: - status_t _FindConfiguration(Screen* screen, BMessage& settings); + status_t _FindConfiguration(Screen* screen, + BMessage& settings); void _Reset(); struct screen_item { From stippi at mail.berlios.de Fri Oct 19 21:54:06 2007 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Fri, 19 Oct 2007 21:54:06 +0200 Subject: [Haiku-commits] r22623 - haiku/trunk/headers/build Message-ID: <200710191954.l9JJs6ak023256@sheep.berlios.de> Author: stippi Date: 2007-10-19 21:54:05 +0200 (Fri, 19 Oct 2007) New Revision: 22623 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22623&view=rev Modified: haiku/trunk/headers/build/HaikuBuildCompatibility.h Log: * this partly fixes the broken build of the app_server test_environment (yes I still use that), but there are more problems, regarding for example BPrivateScreen definition and the disk device API stuff, I am kind of clueless regarding those. :-( Modified: haiku/trunk/headers/build/HaikuBuildCompatibility.h =================================================================== --- haiku/trunk/headers/build/HaikuBuildCompatibility.h 2007-10-19 16:47:06 UTC (rev 22622) +++ haiku/trunk/headers/build/HaikuBuildCompatibility.h 2007-10-19 19:54:05 UTC (rev 22623) @@ -47,6 +47,10 @@ # define B_FIRST_REAL_TIME_PRIORITY B_REAL_TIME_DISPLAY_PRIORITY #endif +#if __GNUC__ +# define _PRINTFLIKE(_format_, _args_) \ + __attribute__((format(__printf__, _format_, _args_))) +#endif #ifdef __cplusplus extern "C" { @@ -115,5 +119,26 @@ #define B_MPEG_2_5_AUDIO_LAYER_2 (enum mpeg_id)0x302 #define B_MPEG_2_5_AUDIO_LAYER_3 (enum mpeg_id)0x303 +// TODO: experimental API (keep in sync with Accelerant.h) +typedef struct { + uint32 version; + char vendor[128]; + char name[128]; + char serial_number[128]; + uint32 product_id; + struct { + uint16 week; + uint16 year; + } produced; + float width; + float height; + uint32 min_horizontal_frequency; // in kHz + uint32 max_horizontal_frequency; + uint32 min_vertical_frequency; // in Hz + uint32 max_vertical_frequency; + uint32 max_pixel_clock; // in kHz +} monitor_info; + + #endif // HAIKU_BUILD_COMPATIBILITY_H From sbenedetto at mail.berlios.de Sat Oct 20 14:11:17 2007 From: sbenedetto at mail.berlios.de (sbenedetto at BerliOS) Date: Sat, 20 Oct 2007 14:11:17 +0200 Subject: [Haiku-commits] r22624 - haiku/trunk/src/add-ons/kernel/busses/usb Message-ID: <200710201211.l9KCBHCt029167@sheep.berlios.de> Author: sbenedetto Date: 2007-10-20 14:11:16 +0200 (Sat, 20 Oct 2007) New Revision: 22624 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22624&view=rev Modified: haiku/trunk/src/add-ons/kernel/busses/usb/ohci_hardware.h Log: * Renaming macros Modified: haiku/trunk/src/add-ons/kernel/busses/usb/ohci_hardware.h =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/usb/ohci_hardware.h 2007-10-19 19:54:05 UTC (rev 22623) +++ haiku/trunk/src/add-ons/kernel/busses/usb/ohci_hardware.h 2007-10-20 12:11:16 UTC (rev 22624) @@ -19,58 +19,58 @@ // -------------------------------- #define OHCI_REVISION 0x00 -#define OHCI_REV_LO(rev) ((rev) & 0x0f) -#define OHCI_REV_HI(rev) (((rev) >> 4) & 0x03) -#define OHCI_REV_LEGACY(rev) ((rev) & 0x10) +#define OHCI_REVISION_LOW(rev) ((rev) & 0x0f) +#define OHCI_REVISION_HIGH(rev) (((rev) >> 4) & 0x03) +#define OHCI_REVISION_LEGACY(rev) ((rev) & 0x10) // -------------------------------- // Control register (section 7.1.2) // -------------------------------- -#define OHCI_CONTROL 0x04 -#define OHCI_CBSR_MASK 0x00000003 // Control-Bulk Service Ratio -#define OHCI_RATIO_1_1 0x00000000 -#define OHCI_RATIO_1_2 0x00000001 -#define OHCI_RATIO_1_3 0x00000002 -#define OHCI_RATIO_1_4 0x00000003 -#define OHCI_PLE 0x00000004 // Periodic List Enable -#define OHCI_IE 0x00000008 // Isochronous Enable -#define OHCI_CLE 0x00000010 // Control List Enable -#define OHCI_BLE 0x00000020 // Bulk List Enable -#define OHCI_HCFS_MASK 0x000000c0 // HostControllerFunctionalState -#define OHCI_HCFS_RESET 0x00000000 -#define OHCI_HCFS_RESUME 0x00000040 -#define OHCI_HCFS_OPERATIONAL 0x00000080 -#define OHCI_HCFS_SUSPEND 0x000000c0 -#define OHCI_IR 0x00000100 // Interrupt Routing -#define OHCI_RWC 0x00000200 // Remote Wakeup Connected -#define OHCI_RWE 0x00000400 // Remote Wakeup Enabled +#define OHCI_CONTROL 0x04 +#define OHCI_CONTROL_BULK_SERVICE_RATIO_MASK 0x00000003 +#define OHCI_CONTROL_BULK_RATIO_1_1 0x00000000 +#define OHCI_CONTROL_BULK_RATIO_1_2 0x00000001 +#define OHCI_CONTROL_BULK_RATIO_1_3 0x00000002 +#define OHCI_CONTROL_BULK_RATIO_1_4 0x00000003 +#define OHCI_PERIODIC_LIST_ENABLE 0x00000004 +#define OHCI_ISOCHRONOUS_ENABLE 0x00000008 +#define OHCI_CONTROL_LIST_ENABLE 0x00000010 +#define OHCI_BULK_LIST_ENABLE 0x00000020 +#define OHCI_HC_FUNCTIONAL_STATE_MASK 0x000000c0 +#define OHCI_HC_FUNCTIONAL_STATE_RESET 0x00000000 +#define OHCI_HC_FUNCTIONAL_STATE_RESUME 0x00000040 +#define OHCI_HC_FUNCTIONAL_STATE_OPERATIONAL 0x00000080 +#define OHCI_HC_FUNCTIONAL_STATE_SUSPEND 0x000000c0 +#define OHCI_INTERRUPT_ROUTING 0x00000100 +#define OHCI_REMOTE_WAKEUP_CONNECTED 0x00000200 +#define OHCI_REMORE_WAKEUP_ENABLED 0x00000400 // -------------------------------- // Command status register (section 7.1.3) // -------------------------------- -#define OHCI_COMMAND_STATUS 0x08 -#define OHCI_HCR 0x00000001 // Host Controller Reset -#define OHCI_CLF 0x00000002 // Control List Filled -#define OHCI_BLF 0x00000004 // Bulk List Filled -#define OHCI_OCR 0x00000008 // Ownership Change Request -#define OHCI_SOC_MASK 0x00030000 // Scheduling Overrun Count +#define OHCI_COMMAND_STATUS 0x08 +#define OHCI_HOST_CONTROLLER_RESET 0x00000001 +#define OHCI_CONTROL_LIST_FILLED 0x00000002 +#define OHCI_BULK_LIST_FILLED 0x00000004 +#define OHCI_OWNERSHIP_CHANGE_REQUEST 0x00000008 +#define OHCI_SCHEDULING_OVERRUN_COUNT_MASK 0x00030000 // -------------------------------- // Interrupt status register (section 7.1.4) // -------------------------------- -#define OHCI_INTERRUPT_STATUS 0x0c -#define OHCI_SO 0x00000001 // Scheduling Overrun -#define OHCI_WDH 0x00000002 // Writeback Done Head -#define OHCI_SF 0x00000004 // Start of Frame -#define OHCI_RD 0x00000008 // Resume Detected -#define OHCI_UE 0x00000010 // Unrecoverable Error -#define OHCI_FNO 0x00000020 // Frame Number Overflow -#define OHCI_RHSC 0x00000040 // Root Hub Status Change -#define OHCI_OC 0x40000000 // Ownership Change -#define OHCI_MIE 0x80000000 // Master Interrupt Enable +#define OHCI_INTERRUPT_STATUS 0x0c +#define OHCI_SCHEDULING_OVERRUN 0x00000001 +#define OHCI_WRITEBACK_DONE_HEAD 0x00000002 +#define OHCI_START_OF_FRAME 0x00000004 +#define OHCI_RESUME_DETECTED 0x00000008 +#define OHCI_UNRECOVERABLE_ERROR 0x00000010 +#define OHCI_FRAME_NUMBER_OVERFLOW 0x00000020 +#define OHCI_ROOT_HUB_STATUS_CHANGE 0x00000040 +#define OHCI_OWNERSHIP_CHANGE 0x40000000 +#define OHCI_MASTER_INTERRUPT_ENABLE 0x80000000 // -------------------------------- // Interupt enable register (section 7.1.5) @@ -138,34 +138,34 @@ // Frame interval register (section 7.3.1) // -------------------------------- -#define OHCI_FM_INTERVAL 0x34 -#define OHCI_GET_IVAL(s) ((s) & 0x3fff) -#define OHCI_GET_FSMPS(s) (((s) >> 16) & 0x7fff) -#define OHCI_FIT 0x80000000 +#define OHCI_FRAME_INTERVAL 0x34 +#define OHCI_GET_INTERVAL_VALUE(s) ((s) & 0x3fff) +#define OHCI_GET_FS_LARGEST_DATA_PACKET(s) (((s) >> 16) & 0x7fff) +#define OHCI_FRAME_INTERVAL_TOGGLE 0x80000000 // -------------------------------- // Frame remaining register (section 7.3.2) // -------------------------------- -#define OHCI_FM_REMAINING 0x38 +#define OHCI_FRAME_REMAINING 0x38 // -------------------------------- // Frame number register (section 7.3.3) // -------------------------------- -#define OHCI_FM_NUMBER 0x3c +#define OHCI_FRAME_NUMBER 0x3c // -------------------------------- // Periodic start register (section 7.3.4) // -------------------------------- -#define OHCI_PERIODIC_START 0x40 +#define OHCI_PERIODIC_START 0x40 // -------------------------------- -// LS treshold register (section 7.3.5) +// Low Speed (LS) treshold register (section 7.3.5) // -------------------------------- -#define OHCI_LS_THRESHOLD 0x44 +#define OHCI_LOW_SPEED_THRESHOLD 0x44 // -------------------------------- // Root Hub Partition (section 7.4) @@ -175,14 +175,14 @@ // Root Hub Descriptor A register (section 7.4.1) // -------------------------------- -#define OHCI_RH_DESCRIPTOR_A 0x48 -#define OHCI_GET_PORT_COUNT(s) ((s) & 0xff) -#define OHCI_PSM 0x0100 // Power Switching Mode -#define OHCI_NPS 0x0200 // No Power Switching -#define OHCI_DT 0x0400 // Device Type -#define OHCI_OCPM 0x0800 // Overcurrent Protection Mode -#define OHCI_NOCP 0x1000 // No Overcurrent Protection -#define OHCI_GET_POTPGT(s) ((s) >> 24) +#define OHCI_RH_DESCRIPTOR_A 0x48 +#define OHCI_RH_GET_PORT_COUNT(s) ((s) & 0xff) +#define OHCI_RH_POWER_SWITCHING_MODE 0x0100 +#define OHCI_RH_NO_POWER_SWITCHING 0x0200 +#define OHCI_RH_DEVICE_TYPE 0x0400 +#define OHCI_RH_OVER_CURRENT_PROTECTION_MODE 0x0800 +#define OHCI_RH_NO_OVER_CURRENT_PROTECTION_MODE 0x1000 +#define OHCI_RH_GET_POWER_ON_TO_POWER_GOOD_TIME(s) ((s) >> 24) // -------------------------------- // Root Hub Descriptor B register (section 7.4.2) @@ -194,61 +194,61 @@ // Root Hub status register (section 7.4.3) // -------------------------------- -#define OHCI_RH_STATUS 0x50 -#define OHCI_LPS 0x00000001 // Local Power Status -#define OHCI_OCI 0x00000002 // OverCurrent Indicator -#define OHCI_DRWE 0x00008000 // Device Remote Wakeup Enable -#define OHCI_LPSC 0x00010000 // Local Power Status Change -#define OHCI_CCIC 0x00020000 // OverCurrent Indicator Change -#define OHCI_CRWE 0x80000000 // Clear Remote Wakeup Enable +#define OHCI_RH_STATUS 0x50 +#define OHCI_RH_LOCAL_POWER_STATUS 0x00000001 +#define OHCI_RH_OVER_CURRENT_INDICATOR 0x00000002 +#define OHCI_RH_DEVICE_REMOTE_WAKEUP_ENABLE 0x00008000 +#define OHCI_RH_LOCAL_POWER_STATUS_CHANGE 0x00010000 +#define OHCI_RH_OVER_CURRENT_INDICATOR_CHANGE 0x00020000 +#define OHCI_RH_CLEAR_REMOTE_WAKEUP_ENABLE 0x80000000 // -------------------------------- // Root Hub port status (n) register (section 7.4.4) // -------------------------------- -#define OHCI_RH_PORT_STATUS(n) (0x50 + (n)*4) // 1 based indexing -#define OHCI_PORTSTATUS_CCS 0x00000001 // Current Connection Status -#define OHCI_PORTSTATUS_PES 0x00000002 // Port Enable Status -#define OHCI_PORTSTATUS_PSS 0x00000004 // Port Suspend Status -#define OHCI_PORTSTATUS_POCI 0x00000008 // Port Overcurrent Indicator -#define OHCI_PORTSTATUS_PRS 0x00000010 // Port Reset Status -#define OHCI_PORTSTATUS_PPS 0x00000100 // Port Power Status -#define OHCI_PORTSTATUS_LSDA 0x00000200 // Low Speed Device Attached -#define OHCI_PORTSTATUS_CSC 0x00010000 // Connection Status Change -#define OHCI_PORTSTATUS_PESC 0x00020000 // Port Enable Status Change -#define OHCI_PORTSTATUS_PSSC 0x00040000 // Port Suspend Status change -#define OHCI_PORTSTATUS_OCIC 0x00080000 // Port Overcurrent Change -#define OHCI_PORTSTATUS_PRSC 0x00100000 // Port Reset Status Change +#define OHCI_RH_PORT_STATUS(n) (0x50 + (n) * 4) // 1 based indexing +#define OHCI_RH_PORTSTATUS_CCS 0x00000001 // Current Connection Status +#define OHCI_RH_PORTSTATUS_PES 0x00000002 // Port Enable Status +#define OHCI_RH_PORTSTATUS_PSS 0x00000004 // Port Suspend Status +#define OHCI_RH_PORTSTATUS_POCI 0x00000008 // Port Overcurrent Indicator +#define OHCI_RH_PORTSTATUS_PRS 0x00000010 // Port Reset Status +#define OHCI_RH_PORTSTATUS_PPS 0x00000100 // Port Power Status +#define OHCI_RH_PORTSTATUS_LSDA 0x00000200 // Low Speed Device Attached +#define OHCI_RH_PORTSTATUS_CSC 0x00010000 // Connection Status Change +#define OHCI_RH_PORTSTATUS_PESC 0x00020000 // Port Enable Status Change +#define OHCI_RH_PORTSTATUS_PSSC 0x00040000 // Port Suspend Status change +#define OHCI_RH_PORTSTATUS_OCIC 0x00080000 // Port Overcurrent Change +#define OHCI_RH_PORTSTATUS_PRSC 0x00100000 // Port Reset Status Change // -------------------------------- // ???? // -------------------------------- -#define OHCI_LES (OHCI_PLE | OHCI_IE | OHCI_CLE | OHCI_BLE) +#define OHCI_LES (OHCI_PLE | OHCI_IE | OHCI_CLE | OHCI_BLE) // -------------------------------- // All interupts // -------------------------------- -#define OHCI_ALL_INTRS (OHCI_SO | OHCI_WDH | OHCI_SF | OHCI_RD | OHCI_UE | OHCI_FNO | OHCI_RHSC | OHCI_OC) +#define OHCI_ALL_INTRS (OHCI_SO | OHCI_WDH | OHCI_SF | OHCI_RD | OHCI_UE | OHCI_FNO | OHCI_RHSC | OHCI_OC) // -------------------------------- // All normal interupts // -------------------------------- -#define OHCI_NORMAL_INTRS (OHCI_SO | OHCI_WDH | OHCI_RD | OHCI_UE | OHCI_RHSC) +#define OHCI_NORMAL_INTRS (OHCI_SO | OHCI_WDH | OHCI_RD | OHCI_UE | OHCI_RHSC) // -------------------------------- // FSMPS // -------------------------------- -#define OHCI_FSMPS(i) (((i-210)*6/7) << 16) +#define OHCI_FSMPS(i) (((i - 210) * 6 / 7) << 16) // -------------------------------- // Periodic // -------------------------------- -#define OHCI_PERIODIC(i) ((i)*9/10) +#define OHCI_PERIODIC(i) ((i) * 9 / 10) // -------------------------------- // OHCI physical address @@ -264,9 +264,9 @@ typedef struct ohci_hcca { - addr_t hcca_interrupt_table[OHCI_NUMBER_OF_INTERRUPTS]; - uint32 hcca_frame_number; - addr_t hcca_done_head; + uint32 hcca_interrupt_table[OHCI_NUMBER_OF_INTERRUPTS]; + uint16 hcca_frame_number; + uint32 hcca_done_head; uint8 hcca_reserved_for_hc[116]; }; @@ -322,22 +322,22 @@ uint32 last_byte_address; // Physical buffer end }; -#define OHCI_BUFFER_ROUNDING 0x00040000 // Buffer Rounding -#define OHCI_TD_DIRECTION_PID_MASK 0x00180000 // Direction / PID -#define OHCI_TD_DIRECTION_PID_SETUP 0x00000000 -#define OHCI_TD_DIRECTION_PID_OUT 0x00080000 -#define OHCI_TD_DIRECTION_PID_IN 0x00100000 -#define OHCI_TD_GET_DELAY_INTERRUPT(x) (((x) >> 21) & 7) // Delay Interrupt -#define OHCI_TD_SET_DELAY_INTERRUPT(x) ((x) << 21) -#define OHCI_TD_NO_INTERRUPT 0x00e00000 -#define OHCI_TD_INTERRUPT_MASK 0x00e00000 -#define OHCI_TD_TOGGLE_CARRY 0x00000000 -#define OHCI_TD_TOGGLE_0 0x02000000 -#define OHCI_TD_TOGGLE_1 0x03000000 -#define OHCI_TD_TOGGLE_MASK 0x03000000 -#define OHCI_TD_GET_ERROR_COUNT(x) (((x) >> 26) & 3) // Error Count -#define OHCI_TD_GET_CONDITION_CODE(x) ((x) >> 28) // Condition Code -#define OHCI_TD_NO_CONDITION_CODE 0xf0000000 +#define OHCI_BUFFER_ROUNDING 0x00040000 +#define OHCI_TD_DIRECTION_PID_MASK 0x00180000 +#define OHCI_TD_DIRECTION_PID_SETUP 0x00000000 +#define OHCI_TD_DIRECTION_PID_OUT 0x00080000 +#define OHCI_TD_DIRECTION_PID_IN 0x00100000 +#define OHCI_TD_GET_DELAY_INTERRUPT(x) (((x) >> 21) & 7) +#define OHCI_TD_SET_DELAY_INTERRUPT(x) ((x) << 21) +#define OHCI_TD_NO_INTERRUPT 0x00e00000 +#define OHCI_TD_INTERRUPT_MASK 0x00e00000 +#define OHCI_TD_TOGGLE_CARRY 0x00000000 +#define OHCI_TD_TOGGLE_0 0x02000000 +#define OHCI_TD_TOGGLE_1 0x03000000 +#define OHCI_TD_TOGGLE_MASK 0x03000000 +#define OHCI_TD_GET_ERROR_COUNT(x) (((x) >> 26) & 3) +#define OHCI_TD_GET_CONDITION_CODE(x) ((x) >> 28) +#define OHCI_TD_NO_CONDITION_CODE 0xf0000000 #define OHCI_GENERAL_TD_ALIGN 16 @@ -355,22 +355,22 @@ uint16 offset[OHCI_ITD_NOFFSET]; // Buffer offsets }; -#define OHCI_ITD_GET_STARTING_FRAME(x) ((x) & 0x0000ffff) -#define OHCI_ITD_SET_STARTING_FRAME(x) ((x) & 0xffff) -#define OHCI_ITD_GET_DELAY_INTERRUPT(x) (((x) >> 21) & 7) -#define OHCI_ITD_SET_DELAY_INTERRUPT(x) ((x) << 21) -#define OHCI_ITD_NO_INTERRUPT 0x00e00000 -#define OHCI_ITD_GET_FRAME_COUNT(x) ((((x) >> 24) & 7) + 1) -#define OHCI_ITD_SET_FRAME_COUNT(x) (((x) - 1) << 24) -#define OHCI_ITD_GET_CONDITION_CODE(x) ((x) >> 28) -#define OHCI_ITD_NO_CONDITION_CODE 0xf0000000 +#define OHCI_ITD_GET_STARTING_FRAME(x) ((x) & 0x0000ffff) +#define OHCI_ITD_SET_STARTING_FRAME(x) ((x) & 0xffff) +#define OHCI_ITD_GET_DELAY_INTERRUPT(x) (((x) >> 21) & 7) +#define OHCI_ITD_SET_DELAY_INTERRUPT(x) ((x) << 21) +#define OHCI_ITD_NO_INTERRUPT 0x00e00000 +#define OHCI_ITD_GET_FRAME_COUNT(x) ((((x) >> 24) & 7) + 1) +#define OHCI_ITD_SET_FRAME_COUNT(x) (((x) - 1) << 24) +#define OHCI_ITD_GET_CONDITION_CODE(x) ((x) >> 28) +#define OHCI_ITD_NO_CONDITION_CODE 0xf0000000 // TO FIX #define itd_pswn itd_offset // Packet Status Word #define OHCI_ITD_PAGE_SELECT 0x00001000 #define OHCI_ITD_MK_OFFS(len) (0xe000 | ((len) & 0x1fff)) -#define OHCI_ITD_GET_BUFFER_LENGTH(x) ((x) & 0xfff) // Transfer length -#define OHCI_ITD_GET_BUFFER_CONDITION_CODE(x) ((x) >> 12) // Condition Code +#define OHCI_ITD_GET_BUFFER_LENGTH(x) ((x) & 0xfff) +#define OHCI_ITD_GET_BUFFER_CONDITION_CODE(x) ((x) >> 12) #define OHCI_ISOCHRONOUS_TD_ALIGN 32 @@ -378,26 +378,26 @@ // Completion Codes (section 4.3.3) // -------------------------------- -#define OHCI_NO_ERROR 0 -#define OHCI_CRC 1 -#define OHCI_BIT_STUFFING 2 -#define OHCI_DATA_TOGGLE_MISMATCH 3 -#define OHCI_STALL 4 -#define OHCI_DEVICE_NOT_RESPONDING 5 -#define OHCI_PID_CHECK_FAILURE 6 -#define OHCI_UNEXPECTED_PID 7 -#define OHCI_DATA_OVERRUN 8 -#define OHCI_DATA_UNDERRUN 9 -#define OHCI_BUFFER_OVERRUN 12 -#define OHCI_BUFFER_UNDERRUN 13 -#define OHCI_NOT_ACCESSED 15 +#define OHCI_NO_ERROR 0 +#define OHCI_CRC 1 +#define OHCI_BIT_STUFFING 2 +#define OHCI_DATA_TOGGLE_MISMATCH 3 +#define OHCI_STALL 4 +#define OHCI_DEVICE_NOT_RESPONDING 5 +#define OHCI_PID_CHECK_FAILURE 6 +#define OHCI_UNEXPECTED_PID 7 +#define OHCI_DATA_OVERRUN 8 +#define OHCI_DATA_UNDERRUN 9 +#define OHCI_BUFFER_OVERRUN 12 +#define OHCI_BUFFER_UNDERRUN 13 +#define OHCI_NOT_ACCESSED 15 // -------------------------------- // Some delay needed when changing // certain registers. // -------------------------------- -#define OHCI_ENABLE_POWER_DELAY 5 -#define OHCI_READ_DESC_DELAY 5 +#define OHCI_ENABLE_POWER_DELAY 5 +#define OHCI_READ_DESC_DELAY 5 #endif // OHCI_HARD_H From sbenedetto at mail.berlios.de Sat Oct 20 18:31:18 2007 From: sbenedetto at mail.berlios.de (sbenedetto at BerliOS) Date: Sat, 20 Oct 2007 18:31:18 +0200 Subject: [Haiku-commits] r22625 - haiku/trunk/src/add-ons/kernel/busses/usb Message-ID: <200710201631.l9KGVIB5011921@sheep.berlios.de> Author: sbenedetto Date: 2007-10-20 18:31:15 +0200 (Sat, 20 Oct 2007) New Revision: 22625 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22625&view=rev Modified: haiku/trunk/src/add-ons/kernel/busses/usb/ohci.cpp haiku/trunk/src/add-ons/kernel/busses/usb/ohci.h haiku/trunk/src/add-ons/kernel/busses/usb/ohci_hardware.h Log: * Rewrote part of the constructor: most of the code is ported from FreeBSD * Usual clean up Modified: haiku/trunk/src/add-ons/kernel/busses/usb/ohci.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/usb/ohci.cpp 2007-10-20 12:11:16 UTC (rev 22624) +++ haiku/trunk/src/add-ons/kernel/busses/usb/ohci.cpp 2007-10-20 16:31:15 UTC (rev 22625) @@ -11,7 +11,6 @@ #include #include #include -#include #include "ohci.h" @@ -46,7 +45,7 @@ module_info *modules[] = { - (module_info *) &ohci_module, + (module_info *)&ohci_module, NULL }; @@ -71,95 +70,82 @@ fDummyControl(0), fDummyBulk(0), fDummyIsochronous(0), - fRootHub(0), + fRootHub(NULL), fRootHubAddress(0), fNumPorts(0) { - int i; - TRACE(("usb_ohci: constructing new BusManager\n")); - + if (!fInitOK) { + TRACE_ERROR(("usb_ohci: bus manager failed to init\n")); + return; + } + + TRACE(("usb_ohci: constructing new OHCI Host Controller Driver\n")); fInitOK = false; - - fInterruptEndpoints = new(std::nothrow) uint32[OHCI_NUMBER_OF_INTERRUPTS]; - for(i = 0; i < OHCI_NUMBER_OF_INTERRUPTS; i++) //Clear the interrupt list - fInterruptEndpoints[i] = 0; - // enable busmaster and memory mapped access - uint16 cmd = sPCIModule->read_pci_config(fPCIInfo->bus, fPCIInfo->device, fPCIInfo->function, PCI_command, 2); - cmd &= ~PCI_command_io; - cmd |= PCI_command_master | PCI_command_memory; - sPCIModule->write_pci_config(fPCIInfo->bus, fPCIInfo->device, fPCIInfo->function, PCI_command, 2, cmd ); + // enable busmaster and memory mapped access + uint16 command = sPCIModule->read_pci_config(fPCIInfo->bus, + fPCIInfo->device, fPCIInfo->function, PCI_command, 2); + command &= ~PCI_command_io; + command |= PCI_command_master | PCI_command_memory; - // - // 5.1.1.2 map the registers - // - addr_t registeroffset = sPCIModule->read_pci_config(info->bus, - info->device, info->function, PCI_base_registers, 4); - registeroffset &= PCI_address_memory_32_mask; - TRACE(("OHCI: iospace offset: %lx\n" , registeroffset)); - fRegisterArea = map_physical_memory("OHCI base registers", (void *)registeroffset, - B_PAGE_SIZE, B_ANY_KERNEL_BLOCK_ADDRESS, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA | B_READ_AREA | B_WRITE_AREA, (void **)&fRegisterBase); + sPCIModule->write_pci_config(fPCIInfo->bus, fPCIInfo->device, + fPCIInfo->function, PCI_command, 2, command); + + // map the registers + uint32 offset = sPCIModule->read_pci_config(fPCIInfo->bus, + fPCIInfo->device, fPCIInfo->function, PCI_base_registers, 4); + offset &= PCI_address_memory_32_mask; + TRACE(("usb_ohci: iospace offset: %lx\n", offset)); + fRegisterArea = map_physical_memory("OHCI memory mapped registers", + (void *)offset, B_PAGE_SIZE, B_ANY_KERNEL_BLOCK_ADDRESS, + B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA | B_READ_AREA | B_WRITE_AREA, + (void **)&fOperationalRegisters); if (fRegisterArea < B_OK) { - TRACE(("usb_ohci: error mapping the registers\n")); + TRACE_ERROR(("usb_ohci: failed to map register memory\n")); return; } - - // Get the revision of the controller - uint32 rev = ReadReg(OHCI_REVISION) & 0xff; - - // Check the revision of the controller. The revision should be 10xh - TRACE((" OHCI: Version %ld.%ld%s\n", OHCI_REV_HI(rev), OHCI_REV_LO(rev),OHCI_REV_LEGACY(rev) ? ", legacy support" : "")); - if (OHCI_REV_HI(rev) != 1 || OHCI_REV_LO(rev) != 0) { - TRACE(("usb_ohci: Unsupported OHCI revision of the ohci device\n")); + + TRACE(("usb_ohci: mapped operational registers: 0x%08lx\n", + *fOperationalRegisters)); + + // Check the revision of the controller, which should be 10h + uint32 revision = ReadReg(OHCI_REVISION) & 0xff; + TRACE(("usb_ohci: version %ld.%ld%s\n", OHCI_REVISION_HIGH(revision), + OHCI_REVISION_LOW(revision), OHCI_REVISION_LEGACY(revision) + ? ", legacy support" : "")); + if (OHCI_REVISION_HIGH(revision) != 1 || OHCI_REVISION_LOW(revision) != 0) { + TRACE_ERROR(("usb_ohci: unsupported OHCI revision\n")); return; } - + // Set up the Host Controller Communications Area - void *hcca_phy; - fHccaArea = fStack->AllocateArea((void**)&fHcca, &hcca_phy, - B_PAGE_SIZE, "OHCI HCCA"); + void *hccaPhysicalAddress; + fHccaArea = fStack->AllocateArea((void **)&fHcca, &hccaPhysicalAddress, + 2048, "USB OHCI Host Controller Communication Area"); + if (fHccaArea < B_OK) { - TRACE(("usb_ohci: Error allocating HCCA block\n")); + TRACE(("usb_ohci: unable to create the HCCA block area\n")); return; } + memset((void*)fHcca, 0, sizeof(ohci_hcca)); - // - // 5.1.1.3 Take control of the host controller - // - if (ReadReg(OHCI_CONTROL) & OHCI_IR) { - TRACE(("usb_ohci: SMM is in control of the host controller\n")); - WriteReg(OHCI_COMMAND_STATUS, OHCI_OCR); - for (int i = 0; i < 100 && (ReadReg(OHCI_CONTROL) & OHCI_IR); i++) - snooze(1000); - if (ReadReg(OHCI_CONTROL) & OHCI_IR) - TRACE(("usb_ohci: SMM doesn't respond... continueing anyway...\n")); - } else if (!(ReadReg(OHCI_CONTROL) & OHCI_HCFS_RESET)) { - TRACE(("usb_ohci: BIOS is in control of the host controller\n")); - if (!(ReadReg(OHCI_CONTROL) & OHCI_HCFS_OPERATIONAL)) { - WriteReg(OHCI_CONTROL, OHCI_HCFS_RESUME); - snooze(USB_DELAY_BUS_RESET); - } - } else if (ReadReg(OHCI_CONTROL) & OHCI_HCFS_RESET) //Only if no BIOS/SMM control - snooze(USB_DELAY_BUS_RESET); - - // - // 5.1.1.4 Set Up Host controller - // + // Set Up Host controller // Dummy endpoints - fDummyControl = AllocateEndpoint(); + fDummyControl = _AllocateEndpoint(); if (!fDummyControl) return; - fDummyBulk = AllocateEndpoint(); + fDummyBulk = _AllocateEndpoint(); if (!fDummyBulk) return; - fDummyIsochronous = AllocateEndpoint(); + fDummyIsochronous = _AllocateEndpoint(); if (!fDummyIsochronous) return; - //Create the interrupt tree - //Algorhythm kindly borrowed from NetBSD code - for(i = 0; i < OHCI_NO_EDS; i++) { - fInterruptEndpoints[i] = AllocateEndpoint(); + + // Create the interrupt tree + // Algorithm kindly borrowed from NetBSD code + for( uint32 i = 0; i < OHCI_NUMBER_OF_INTERRUPTS; i++) { + fInterruptEndpoints[i] = _AllocateEndpoint(); if (!fInterruptEndpoints[i]) return; if (i != 0) @@ -167,57 +153,102 @@ else fInterruptEndpoints[i]->SetNext(fDummyIsochronous); } - for (i = 0; i < OHCI_NUMBER_OF_INTERRUPTS; i++) + + for (uint32 i = 0; i < OHCI_NUMBER_OF_INTERRUPTS; i++) fHcca->hcca_interrupt_table[revbits[i]] = - fInterruptEndpoints[OHCI_NO_EDS-OHCI_NUMBER_OF_INTERRUPTS+i]->physicaladdress; + fInterruptEndpoints[OHCI_NO_EDS-OHCI_NUMBER_OF_INTERRUPTS+i]->physical_address; - //Go to the hardware part of the initialisation - uint32 frameinterval = ReadReg(OHCI_FM_INTERVAL); - - WriteReg(OHCI_COMMAND_STATUS, OHCI_HCR); - for (i = 0; i < 10; i++){ - snooze(10); //Should be okay in one run: 10 microseconds for reset - if (!(ReadReg(OHCI_COMMAND_STATUS) & OHCI_HCR)) + + // Determine in what context we are running (Kindly copied from FreeBSD) + uint32 control = ReadReg(OHCI_CONTROL); + if (control & OHCI_INTERRUPT_ROUTING) { + TRACE(("usb_ohci: SMM is in control of the host controller\n")); + WriteReg(OHCI_COMMAND_STATUS, OHCI_OWNERSHIP_CHANGE_REQUEST); + for (uint32 i = 0; i < 100 && (control & OHCI_INTERRUPT_ROUTING); i++) { + snooze(1000); + control = ReadReg(OHCI_CONTROL); + } + if (!(control & OHCI_INTERRUPT_ROUTING)) { + TRACE(("usb_ohci: SMM does not respond. Resetting...\n")); + WriteReg(OHCI_CONTROL, OHCI_HC_FUNCTIONAL_STATE_RESET); + snooze(USB_DELAY_BUS_RESET); + } + } else if ((control & OHCI_HC_FUNCTIONAL_STATE_MASK) + != OHCI_HC_FUNCTIONAL_STATE_RESET) { + TRACE(("usb_ohci: BIOS is in control of the host controller\n")); + if ((control & OHCI_HC_FUNCTIONAL_STATE_MASK) + != OHCI_HC_FUNCTIONAL_STATE_OPERATIONAL) { + WriteReg(OHCI_CONTROL, OHCI_HC_FUNCTIONAL_STATE_OPERATIONAL); + // TOFIX: shorter delay + snooze(USB_DELAY_BUS_RESET); + } + } + + // This reset should not be necessary according to the OHCI spec, but + // without it some controllers do not start. + WriteReg(OHCI_CONTROL, OHCI_HC_FUNCTIONAL_STATE_RESET); + snooze(USB_DELAY_BUS_RESET); + + // We now own the host controller and the bus has been reset + uint32 frameInterval = ReadReg(OHCI_FRAME_INTERVAL); + uint32 intervalValue = OHCI_GET_INTERVAL_VALUE(frameInterval); + WriteReg(OHCI_COMMAND_STATUS, OHCI_HOST_CONTROLLER_RESET); + + for (uint32 i = 0; i < 10; i++) { + snooze(10); + if (!(ReadReg(OHCI_COMMAND_STATUS) & OHCI_HOST_CONTROLLER_RESET)) break; } - if (ReadReg(OHCI_COMMAND_STATUS) & OHCI_HCR) { - TRACE(("usb_ohci: Error resetting the host controller\n")); + + if (ReadReg(OHCI_COMMAND_STATUS) & OHCI_HOST_CONTROLLER_RESET) { + TRACE_ERROR(("usb_ohci: Error resetting the host controller (timeout)\n")); return; } - - WriteReg(OHCI_FM_INTERVAL, frameinterval); - //We now have 2 ms to finish the following sequence. - //TODO: maybe add spinlock protection??? - - WriteReg(OHCI_CONTROL_HEAD_ED, (uint32)fDummyControl->physicaladdress); - WriteReg(OHCI_BULK_HEAD_ED, (uint32)fDummyBulk->physicaladdress); - WriteReg(OHCI_HCCA, (uint32)hcca_phy); - - WriteReg(OHCI_INTERRUPT_DISABLE, OHCI_ALL_INTRS); - WriteReg(OHCI_INTERRUPT_ENABLE, OHCI_NORMAL_INTRS); - - // - // 5.1.1.5 Begin Sending SOFs - // - uint32 control = ReadReg(OHCI_CONTROL); - control &= ~(OHCI_CBSR_MASK | OHCI_LES | OHCI_HCFS_MASK | OHCI_IR); - control |= OHCI_PLE | OHCI_IE | OHCI_CLE | OHCI_BLE | - OHCI_RATIO_1_4 | OHCI_HCFS_OPERATIONAL; + + // The controller is now in SUSPEND state, we have 2ms to finish + // TODO: maybe add spinlock protection??? + // Set up host controller register + WriteReg(OHCI_HCCA, (uint32)hccaPhysicalAddress); + WriteReg(OHCI_CONTROL_HEAD_ED, (uint32)fDummyControl->physical_address); + WriteReg(OHCI_BULK_HEAD_ED, (uint32)fDummyBulk->physical_address); + // Disable all interrupts and then switch on all desired interrupts + WriteReg(OHCI_INTERRUPT_DISABLE, OHCI_ALL_INTERRUPTS); + WriteReg(OHCI_INTERRUPT_ENABLE, OHCI_NORMAL_INTERRUPTS + | OHCI_MASTER_INTERRUPT_ENABLE); + // Switch on desired functional features + control = ReadReg(OHCI_CONTROL); + control &= ~(OHCI_CONTROL_BULK_SERVICE_RATIO_MASK | OHCI_ENABLE_LIST + | OHCI_HC_FUNCTIONAL_STATE_MASK | OHCI_INTERRUPT_ROUTING); + control |= OHCI_ENABLE_LIST | OHCI_CONTROL_BULK_RATIO_1_4 + | OHCI_HC_FUNCTIONAL_STATE_OPERATIONAL; + // And finally start the controller WriteReg(OHCI_CONTROL, control); - //The controller is now operational, end of 2ms block. - uint32 interval = OHCI_GET_IVAL(frameinterval); - WriteReg(OHCI_PERIODIC_START, OHCI_PERIODIC(interval)); + // The controller is now OPERATIONAL. + frameInterval = (ReadReg(OHCI_FRAME_INTERVAL) & OHCI_FRAME_INTERVAL_TOGGLE) + ^ OHCI_FRAME_INTERVAL_TOGGLE; + frameInterval |= OHCI_FSMPS(intervalValue) | intervalValue; + WriteReg(OHCI_FRAME_INTERVAL, frameInterval); + // 90% periodic + uint32 periodic = OHCI_PERIODIC(intervalValue); + WriteReg(OHCI_PERIODIC_START, periodic); - //Work on some Roothub settings + // Fiddle the No Over Current Protection bit to avoid chip bug uint32 desca = ReadReg(OHCI_RH_DESCRIPTOR_A); - WriteReg(OHCI_RH_DESCRIPTOR_A, desca | OHCI_NOCP); //FreeBSD source does this to avoid a chip bug - //Enable power - WriteReg(OHCI_RH_STATUS, OHCI_LPSC); - snooze(5000); //Wait for power to stabilize (5ms) + WriteReg(OHCI_RH_DESCRIPTOR_A, desca | OHCI_RH_NO_OVER_CURRENT_PROTECTION); + WriteReg(OHCI_RH_STATUS, OHCI_RH_LOCAL_POWER_STATUS_CHANGE); + snooze(OHCI_ENABLE_POWER_DELAY); WriteReg(OHCI_RH_DESCRIPTOR_A, desca); - snooze(5000); //Delay required by the AMD756 because else the # of ports might be misread - + + // The AMD756 requires a delay before re-reading the register, + // otherwise it will occasionally report 0 ports. + uint32 numberOfPorts = 0; + for (uint32 i = 0; i < 10 && numberOfPorts == 0; i++) { + snooze(OHCI_READ_DESC_DELAY); + uint32 descriptor = ReadReg(OHCI_RH_DESCRIPTOR_A); + numberOfPorts = OHCI_RH_GET_PORT_COUNT(descriptor); + } + fInitOK = true; } @@ -229,35 +260,35 @@ if (fRegisterArea > 0) delete_area(fRegisterArea); if (fDummyControl) - FreeEndpoint(fDummyControl); + _FreeEndpoint(fDummyControl); if (fDummyBulk) - FreeEndpoint(fDummyBulk); + _FreeEndpoint(fDummyBulk); if (fDummyIsochronous) - FreeEndpoint(fDummyIsochronous); + _FreeEndpoint(fDummyIsochronous); if (fRootHub) delete fRootHub; for (int i = 0; i < OHCI_NO_EDS; i++) if (fInterruptEndpoints[i]) - FreeEndpoint(fInterruptEndpoints[i]); + _FreeEndpoint(fInterruptEndpoints[i]); } status_t OHCI::Start() { - TRACE(("OHCI::%s()\n", __FUNCTION__)); + TRACE(("usb_ohci::%s()\n", __FUNCTION__)); if (InitCheck()) return B_ERROR; - if (!(ReadReg(OHCI_CONTROL) & OHCI_HCFS_OPERATIONAL)) { + if (!(ReadReg(OHCI_CONTROL) & OHCI_HC_FUNCTIONAL_STATE_OPERATIONAL)) { TRACE(("usb_ohci::Start(): Controller not started. TODO: find out what happens.\n")); return B_ERROR; } fRootHubAddress = AllocateAddress(); - fNumPorts = OHCI_GET_PORT_COUNT(ReadReg(OHCI_RH_DESCRIPTOR_A)); + fNumPorts = OHCI_RH_GET_PORT_COUNT(ReadReg(OHCI_RH_DESCRIPTOR_A)); - fRootHub = new(std::nothrow) OHCIRootHub(this, fRootHubAddress); + fRootHub = new(std::nothrow) OHCIRootHub(RootObject(), fRootHubAddress); if (!fRootHub) { TRACE_ERROR(("usb_ohci::Start(): no memory to allocate root hub\n")); return B_NO_MEMORY; @@ -275,13 +306,11 @@ status_t -OHCI::SubmitTransfer(Transfer *t) +OHCI::SubmitTransfer(Transfer *transfer) { - TRACE(("usb OHCI::SubmitTransfer: called for device %d\n", t->TransferPipe()->DeviceAddress())); + if (transfer->TransferPipe()->DeviceAddress() == fRootHubAddress) + return fRootHub->ProcessTransfer(this, transfer); - if (t->TransferPipe()->DeviceAddress() == fRootHubAddress) - return fRootHub->ProcessTransfer(t, this); - return B_ERROR; } @@ -289,13 +318,13 @@ status_t OHCI::NotifyPipeChange(Pipe *pipe, usb_change change) { - TRACE(("OHCI::%s(%p, %d)\n", __FUNCTION__, pipe, (int)change)); + TRACE(("usb_ohci::%s(%p, %d)\n", __FUNCTION__, pipe, (int)change)); if (InitCheck()) return B_ERROR; switch (change) { case USB_CHANGE_CREATED: - return InsertEndpointForPipe(pipe); + return _InsertEndpointForPipe(pipe); case USB_CHANGE_DESTROYED: // Do something return B_ERROR; @@ -386,42 +415,42 @@ status_t OHCI::GetPortStatus(uint8 index, usb_port_status *status) { - TRACE(("OHCI::%s(%ud, )\n", __FUNCTION__, index)); + TRACE(("usb_ohci::%s(%ud, )\n", __FUNCTION__, index)); if (index >= fNumPorts) return B_BAD_INDEX; status->status = status->change = 0; uint32 portStatus = ReadReg(OHCI_RH_PORT_STATUS(index)); - TRACE(("OHCIRootHub::GetPortStatus: Port %i Value 0x%lx\n", OHCI_RH_PORT_STATUS(index), portStatus)); + TRACE(("usb_ohci: RootHub::GetPortStatus: Port %i Value 0x%lx\n", OHCI_RH_PORT_STATUS(index), portStatus)); // status - if (portStatus & OHCI_PORTSTATUS_CCS) + if (portStatus & OHCI_RH_PORTSTATUS_CCS) status->status |= PORT_STATUS_CONNECTION; - if (portStatus & OHCI_PORTSTATUS_PES) + if (portStatus & OHCI_RH_PORTSTATUS_PES) status->status |= PORT_STATUS_ENABLE; - if (portStatus & OHCI_PORTSTATUS_PRS) + if (portStatus & OHCI_RH_PORTSTATUS_PRS) status->status |= PORT_STATUS_RESET; - if (portStatus & OHCI_PORTSTATUS_LSDA) + if (portStatus & OHCI_RH_PORTSTATUS_LSDA) status->status |= PORT_STATUS_LOW_SPEED; - if (portStatus & OHCI_PORTSTATUS_PSS) + if (portStatus & OHCI_RH_PORTSTATUS_PSS) status->status |= PORT_STATUS_SUSPEND; - if (portStatus & OHCI_PORTSTATUS_POCI) + if (portStatus & OHCI_RH_PORTSTATUS_POCI) status->status |= PORT_STATUS_OVER_CURRENT; - if (portStatus & OHCI_PORTSTATUS_PPS) + if (portStatus & OHCI_RH_PORTSTATUS_PPS) status->status |= PORT_STATUS_POWER; // change - if (portStatus & OHCI_PORTSTATUS_CSC) + if (portStatus & OHCI_RH_PORTSTATUS_CSC) status->change |= PORT_STATUS_CONNECTION; - if (portStatus & OHCI_PORTSTATUS_PESC) + if (portStatus & OHCI_RH_PORTSTATUS_PESC) status->change |= PORT_STATUS_ENABLE; - if (portStatus & OHCI_PORTSTATUS_PSSC) + if (portStatus & OHCI_RH_PORTSTATUS_PSSC) status->change |= PORT_STATUS_SUSPEND; - if (portStatus & OHCI_PORTSTATUS_OCIC) + if (portStatus & OHCI_RH_PORTSTATUS_OCIC) status->change |= PORT_STATUS_OVER_CURRENT; - if (portStatus & OHCI_PORTSTATUS_PRSC) + if (portStatus & OHCI_RH_PORTSTATUS_PRSC) status->change |= PORT_STATUS_RESET; return B_OK; @@ -437,11 +466,11 @@ switch (feature) { case PORT_RESET: - WriteReg(OHCI_RH_PORT_STATUS(index), OHCI_PORTSTATUS_PRS); + WriteReg(OHCI_RH_PORT_STATUS(index), OHCI_RH_PORTSTATUS_PRS); return B_OK; case PORT_POWER: - WriteReg(OHCI_RH_PORT_STATUS(index), OHCI_PORTSTATUS_PPS); + WriteReg(OHCI_RH_PORT_STATUS(index), OHCI_RH_PORTSTATUS_PPS); return B_OK; } @@ -458,11 +487,11 @@ switch (feature) { case C_PORT_RESET: - WriteReg(OHCI_RH_PORT_STATUS(index), OHCI_PORTSTATUS_CSC); + WriteReg(OHCI_RH_PORT_STATUS(index), OHCI_RH_PORTSTATUS_CSC); return B_OK; case C_PORT_CONNECTION: - WriteReg(OHCI_RH_PORT_STATUS(index), OHCI_PORTSTATUS_CSC); + WriteReg(OHCI_RH_PORT_STATUS(index), OHCI_RH_PORTSTATUS_CSC); return B_OK; } @@ -471,7 +500,7 @@ Endpoint * -OHCI::AllocateEndpoint() +OHCI::_AllocateEndpoint() { TRACE(("OHCI::%s()\n", __FUNCTION__)); //Allocate memory chunk @@ -481,7 +510,7 @@ TRACE(("OHCI::AllocateEndpoint(): Error Allocating Endpoint\n")); return 0; } - endpoint->physicaladdress = (addr_t)phy; + endpoint->physical_address = (addr_t)phy; //Initialize the physical part memset((void *)endpoint->ed, 0, sizeof(ohci_endpoint_descriptor)); @@ -490,23 +519,23 @@ //Add a NULL list by creating one TransferDescriptor TransferDescriptor *trans = new(std::nothrow) TransferDescriptor; endpoint->head = endpoint->tail = trans; - endpoint->ed->head_pointer = endpoint->ed->tail_pointer = trans->physicaladdress; + endpoint->ed->head_pointer = endpoint->ed->tail_pointer = trans->physical_address; return endpoint; } void -OHCI::FreeEndpoint(Endpoint *end) +OHCI::_FreeEndpoint(Endpoint *end) { TRACE(("OHCI::%s(%p)\n", __FUNCTION__, end)); - fStack->FreeChunk((void *)end->ed, (void *) end->physicaladdress, sizeof(ohci_endpoint_descriptor)); + fStack->FreeChunk((void *)end->ed, (void *) end->physical_address, sizeof(ohci_endpoint_descriptor)); delete end; } TransferDescriptor * -OHCI::AllocateTransfer() +OHCI::_AllocateTransfer() { TRACE(("OHCI::%s()\n", __FUNCTION__)); TransferDescriptor *transfer = new TransferDescriptor; @@ -515,30 +544,30 @@ TRACE(("OHCI::AllocateTransfer(): Error Allocating Transfer\n")); return 0; } - transfer->physicaladdress = (addr_t)phy; + transfer->physical_address = (addr_t)phy; memset((void *)transfer->td, 0, sizeof(ohci_general_transfer_descriptor)); return transfer; } void -OHCI::FreeTransfer(TransferDescriptor *trans) +OHCI::_FreeTransfer(TransferDescriptor *trans) { TRACE(("OHCI::%s(%p)\n", __FUNCTION__, trans)); - fStack->FreeChunk((void *)trans->td, (void *) trans->physicaladdress, sizeof(ohci_general_transfer_descriptor)); + fStack->FreeChunk((void *)trans->td, (void *) trans->physical_address, sizeof(ohci_general_transfer_descriptor)); delete trans; } status_t -OHCI::InsertEndpointForPipe(Pipe *p) +OHCI::_InsertEndpointForPipe(Pipe *p) { TRACE(("OHCI: Inserting Endpoint for device %u function %u\n", p->DeviceAddress(), p->EndpointAddress())); if (InitCheck()) return B_ERROR; - Endpoint *endpoint = AllocateEndpoint(); + Endpoint *endpoint = _AllocateEndpoint(); if (!endpoint) return B_NO_MEMORY; @@ -602,7 +631,7 @@ else if (p->Type() & USB_OBJECT_ISO_PIPE) listhead = fDummyIsochronous; else { - FreeEndpoint(endpoint); + _FreeEndpoint(endpoint); return B_ERROR; } @@ -623,19 +652,17 @@ } -void +inline void OHCI::WriteReg(uint32 reg, uint32 value) { - TRACE(("OHCI::%s(%lu, %lu)\n", __FUNCTION__, reg, value)); - *(volatile uint32 *)(fRegisterBase + reg) = value; + *(volatile uint32 *)(fOperationalRegisters + reg) = value; } -uint32 +inline uint32 OHCI::ReadReg(uint32 reg) { - TRACE(("OHCI::%s(%lu)\n", __FUNCTION__, reg)); - return *(volatile uint32 *)(fRegisterBase + reg); + return *(volatile uint32 *)(fOperationalRegisters + reg); } Modified: haiku/trunk/src/add-ons/kernel/busses/usb/ohci.h =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/usb/ohci.h 2007-10-20 12:11:16 UTC (rev 22624) +++ haiku/trunk/src/add-ons/kernel/busses/usb/ohci.h 2007-10-20 16:31:15 UTC (rev 22625) @@ -53,7 +53,7 @@ struct Endpoint { - addr_t physicaladdress;//Point to the physical address + addr_t physical_address;//Point to the physical address ohci_endpoint_descriptor *ed; //Logical 'endpoint' Endpoint *next; //Pointer to the 'next' endpoint TransferDescriptor *head, *tail; //Pointers to the 'head' and 'tail' transfer descriptors @@ -64,17 +64,17 @@ if (end == 0) ed->next_endpoint = 0; else - ed->next_endpoint = end->physicaladdress; + ed->next_endpoint = end->physical_address; }; //Constructor (or better: initialiser) - Endpoint() : physicaladdress(0), ed(0), next(0), head(0), tail(0) {}; + Endpoint() : physical_address(0), ed(0), next(0), head(0), tail(0) {}; }; struct TransferDescriptor { - addr_t physicaladdress; + addr_t physical_address; ohci_general_transfer_descriptor *td; }; @@ -110,7 +110,7 @@ // Global static pci_module_info *sPCIModule; - uint32 *fRegisterBase; + uint32 *fOperationalRegisters; pci_info *fPCIInfo; Stack *fStack; @@ -120,17 +120,18 @@ area_id fHccaArea; struct ohci_hcca *fHcca; Endpoint *fInterruptEndpoints[OHCI_NO_EDS]; + // Dummy endpoints Endpoint *fDummyControl; Endpoint *fDummyBulk; Endpoint *fDummyIsochronous; // functions - Endpoint *AllocateEndpoint(); - void FreeEndpoint(Endpoint *end); - TransferDescriptor *AllocateTransfer(); - void FreeTransfer(TransferDescriptor *trans); + Endpoint *_AllocateEndpoint(); + void _FreeEndpoint(Endpoint *end); + TransferDescriptor *_AllocateTransfer(); + void _FreeTransfer(TransferDescriptor *trans); - status_t InsertEndpointForPipe(Pipe *p); + status_t _InsertEndpointForPipe(Pipe *p); // Root Hub OHCIRootHub *fRootHub; Modified: haiku/trunk/src/add-ons/kernel/busses/usb/ohci_hardware.h =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/usb/ohci_hardware.h 2007-10-20 12:11:16 UTC (rev 22624) +++ haiku/trunk/src/add-ons/kernel/busses/usb/ohci_hardware.h 2007-10-20 16:31:15 UTC (rev 22625) @@ -181,7 +181,7 @@ #define OHCI_RH_NO_POWER_SWITCHING 0x0200 #define OHCI_RH_DEVICE_TYPE 0x0400 #define OHCI_RH_OVER_CURRENT_PROTECTION_MODE 0x0800 -#define OHCI_RH_NO_OVER_CURRENT_PROTECTION_MODE 0x1000 +#define OHCI_RH_NO_OVER_CURRENT_PROTECTION 0x1000 #define OHCI_RH_GET_POWER_ON_TO_POWER_GOOD_TIME(s) ((s) >> 24) // -------------------------------- @@ -221,22 +221,36 @@ #define OHCI_RH_PORTSTATUS_PRSC 0x00100000 // Port Reset Status Change // -------------------------------- -// ???? +// Enable List // -------------------------------- -#define OHCI_LES (OHCI_PLE | OHCI_IE | OHCI_CLE | OHCI_BLE) +#define OHCI_ENABLE_LIST (OHCI_PERIODIC_LIST_ENABLE \ + | OHCI_ISOCHRONOUS_ENABLE \ + | OHCI_CONTROL_LIST_ENABLE \ + | OHCI_BULK_LIST_ENABLE) // -------------------------------- // All interupts // -------------------------------- -#define OHCI_ALL_INTRS (OHCI_SO | OHCI_WDH | OHCI_SF | OHCI_RD | OHCI_UE | OHCI_FNO | OHCI_RHSC | OHCI_OC) +#define OHCI_ALL_INTERRUPTS (OHCI_SCHEDULING_OVERRUN \ + | OHCI_WRITEBACK_DONE_HEAD \ + | OHCI_START_OF_FRAME \ + | OHCI_RESUME_DETECTED \ + | OHCI_UNRECOVERABLE_ERROR \ + | OHCI_FRAME_NUMBER_OVERFLOW \ + | OHCI_ROOT_HUB_STATUS_CHANGE \ + | OHCI_OWNERSHIP_CHANGE) // -------------------------------- // All normal interupts // -------------------------------- -#define OHCI_NORMAL_INTRS (OHCI_SO | OHCI_WDH | OHCI_RD | OHCI_UE | OHCI_RHSC) +#define OHCI_NORMAL_INTERRUPTS (OHCI_SCHEDULING_OVERRUN \ + | OHCI_WRITEBACK_DONE_HEAD \ + | OHCI_RESUME_DETECTED \ + | OHCI_UNRECOVERABLE_ERROR \ + | OHCI_ROOT_HUB_STATUS_CHANGE) // -------------------------------- // FSMPS @@ -397,7 +411,7 @@ // certain registers. // -------------------------------- -#define OHCI_ENABLE_POWER_DELAY 5 -#define OHCI_READ_DESC_DELAY 5 +#define OHCI_ENABLE_POWER_DELAY 5000 +#define OHCI_READ_DESC_DELAY 5000 #endif // OHCI_HARD_H From julun at mail.berlios.de Sat Oct 20 18:51:13 2007 From: julun at mail.berlios.de (julun at BerliOS) Date: Sat, 20 Oct 2007 18:51:13 +0200 Subject: [Haiku-commits] r22626 - haiku/trunk/src/preferences/time Message-ID: <200710201651.l9KGpDZT014993@sheep.berlios.de> Author: julun Date: 2007-10-20 18:51:12 +0200 (Sat, 20 Oct 2007) New Revision: 22626 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22626&view=rev Removed: haiku/trunk/src/preferences/time/SettingsView.cpp haiku/trunk/src/preferences/time/SettingsView.h Modified: haiku/trunk/src/preferences/time/Jamfile haiku/trunk/src/preferences/time/TimeWindow.cpp haiku/trunk/src/preferences/time/TimeWindow.h Log: * remove these until we have something to implement it properly Modified: haiku/trunk/src/preferences/time/Jamfile =================================================================== --- haiku/trunk/src/preferences/time/Jamfile 2007-10-20 16:31:15 UTC (rev 22625) +++ haiku/trunk/src/preferences/time/Jamfile 2007-10-20 16:51:12 UTC (rev 22626) @@ -20,7 +20,6 @@ TZDisplay.cpp ZoneView.cpp DateTime.cpp - SettingsView.cpp : be : Time.rdef ; Deleted: haiku/trunk/src/preferences/time/SettingsView.cpp Deleted: haiku/trunk/src/preferences/time/SettingsView.h Modified: haiku/trunk/src/preferences/time/TimeWindow.cpp =================================================================== --- haiku/trunk/src/preferences/time/TimeWindow.cpp 2007-10-20 16:31:15 UTC (rev 22625) +++ haiku/trunk/src/preferences/time/TimeWindow.cpp 2007-10-20 16:51:12 UTC (rev 22626) @@ -13,7 +13,6 @@ #include "DateTimeView.h" #include "TimeMessages.h" #include "ZoneView.h" -#include "SettingsView.h" #include @@ -103,12 +102,6 @@ tabview->AddTab(fTimeZones, tab); tab->SetLabel("Time Zone"); - fSettingsView = new SettingsView(bounds); - - tab = new BTab(); - tabview->AddTab(fSettingsView, tab); - tab->SetLabel("Settings"); - fBaseView->AddChild(tabview); float width; Modified: haiku/trunk/src/preferences/time/TimeWindow.h =================================================================== --- haiku/trunk/src/preferences/time/TimeWindow.h 2007-10-20 16:31:15 UTC (rev 22625) +++ haiku/trunk/src/preferences/time/TimeWindow.h 2007-10-20 16:51:12 UTC (rev 22626) @@ -18,7 +18,6 @@ class DateTimeView; class TTimeBaseView; class TZoneView; -class SettingsView; class TTimeWindow : public BWindow { @@ -35,7 +34,6 @@ TTimeBaseView *fBaseView; DateTimeView *fDateTimeView; TZoneView *fTimeZones; - SettingsView *fSettingsView; }; #endif // TIME_WINDOW_H From julun at mail.berlios.de Sat Oct 20 20:56:20 2007 From: julun at mail.berlios.de (julun at BerliOS) Date: Sat, 20 Oct 2007 20:56:20 +0200 Subject: [Haiku-commits] r22627 - haiku/trunk/src/preferences/time Message-ID: <200710201856.l9KIuKmP031414@sheep.berlios.de> Author: julun Date: 2007-10-20 20:56:20 +0200 (Sat, 20 Oct 2007) New Revision: 22627 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22627&view=rev Modified: haiku/trunk/src/preferences/time/Time.cpp haiku/trunk/src/preferences/time/Time.h haiku/trunk/src/preferences/time/TimeMessages.h haiku/trunk/src/preferences/time/TimeSettings.cpp haiku/trunk/src/preferences/time/TimeWindow.cpp haiku/trunk/src/preferences/time/TimeWindow.h Log: * save and load the window position inside window class, center on first start Modified: haiku/trunk/src/preferences/time/Time.cpp =================================================================== --- haiku/trunk/src/preferences/time/Time.cpp 2007-10-20 16:51:12 UTC (rev 22626) +++ haiku/trunk/src/preferences/time/Time.cpp 2007-10-20 18:56:20 UTC (rev 22627) @@ -9,24 +9,23 @@ */ #include "Time.h" -#include "TimeMessages.h" -#include "TimeSettings.h" #include "TimeWindow.h" #include -#include #include +const char* kAppSignature = "application/x-vnd.Be-TIME"; + + TimeApplication::TimeApplication() - : BApplication(HAIKU_APP_SIGNATURE), + : BApplication(kAppSignature), fWindow(NULL) { - BPoint pt = TimeSettings().LeftTop(); - fWindow = new TTimeWindow(pt); + fWindow = new TTimeWindow(BRect(100, 100, 570, 327)); } @@ -36,24 +35,6 @@ void -TimeApplication::MessageReceived(BMessage *message) -{ - switch (message->what) { - case UPDATE_SETTINGS: - { - BPoint pt; - if (message->FindPoint("LeftTop", &pt) == B_OK) - TimeSettings().SetLeftTop(pt); - } break; - - default: - BApplication::MessageReceived(message); - break; - } -} - - -void TimeApplication::ReadyToRun() { fWindow->Show(); @@ -63,8 +44,10 @@ void TimeApplication::AboutRequested() { - BAlert alert("about", "Time & Date, by\n\nAndrew Edward McCall\nMike Berg", "OK"); - alert.Go(); + BAlert *alert = new BAlert("about", + "Time & Date, writen by:\n\n\tAndrew Edward McCall\n\tMike Berg\n\t" + "Julun\n\nCopyright 2004-2007, Haiku.", "OK"); + alert->Go(); } Modified: haiku/trunk/src/preferences/time/Time.h =================================================================== --- haiku/trunk/src/preferences/time/Time.h 2007-10-20 16:51:12 UTC (rev 22626) +++ haiku/trunk/src/preferences/time/Time.h 2007-10-20 18:56:20 UTC (rev 22627) @@ -14,7 +14,6 @@ #include -class BMessage; class TTimeWindow; @@ -23,7 +22,6 @@ TimeApplication(); virtual ~TimeApplication(); - virtual void MessageReceived(BMessage* message); virtual void ReadyToRun(); virtual void AboutRequested(); Modified: haiku/trunk/src/preferences/time/TimeMessages.h =================================================================== --- haiku/trunk/src/preferences/time/TimeMessages.h 2007-10-20 16:51:12 UTC (rev 22626) +++ haiku/trunk/src/preferences/time/TimeMessages.h 2007-10-20 18:56:20 UTC (rev 22627) @@ -10,10 +10,6 @@ #ifndef TIME_MESSAGES_H #define TIME_MESSAGES_H -#define HAIKU_APP_SIGNATURE "application/x-vnd.Be-TIME" - -const uint32 UPDATE_SETTINGS = 'TDUS'; - //Timezone messages const uint32 H_REGION_CHANGED = 'h_RC'; const uint32 H_CITY_CHANGED = 'h_CC'; Modified: haiku/trunk/src/preferences/time/TimeSettings.cpp =================================================================== --- haiku/trunk/src/preferences/time/TimeSettings.cpp 2007-10-20 16:51:12 UTC (rev 22626) +++ haiku/trunk/src/preferences/time/TimeSettings.cpp 2007-10-20 18:56:20 UTC (rev 22627) @@ -33,7 +33,7 @@ TimeSettings::LeftTop() const { BPath path; - BPoint leftTop(50.0, 50.0); + BPoint leftTop(-1000.0, -1000.0); if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) { path.Append(fSettingsFile.String()); Modified: haiku/trunk/src/preferences/time/TimeWindow.cpp =================================================================== --- haiku/trunk/src/preferences/time/TimeWindow.cpp 2007-10-20 16:51:12 UTC (rev 22626) +++ haiku/trunk/src/preferences/time/TimeWindow.cpp 2007-10-20 18:56:20 UTC (rev 22627) @@ -12,6 +12,7 @@ #include "BaseView.h" #include "DateTimeView.h" #include "TimeMessages.h" +#include "TimeSettings.h" #include "ZoneView.h" @@ -21,24 +22,18 @@ #include -#define WINDOW_RIGHT 470 -#define WINDOW_BOTTOM 227 +TTimeWindow::TTimeWindow(BRect rect) + : BWindow(rect, "Time", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE) +{ + _InitWindow(); + _AlignWindow(); + AddShortcut('A', B_COMMAND_KEY, new BMessage(B_ABOUT_REQUESTED)); +} -TTimeWindow::TTimeWindow(const BPoint leftTop) - : BWindow(BRect(leftTop, leftTop + BPoint(WINDOW_RIGHT, WINDOW_BOTTOM)), - "Time", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE) + +TTimeWindow::~TTimeWindow() { - BRect frame = Frame(); - BRect bounds = Bounds(); - BRect screenFrame = BScreen().Frame(); - // Code to make sure that the window doesn't get drawn off screen... - if (!(screenFrame.right >= frame.right && screenFrame.bottom >= frame.bottom)) - MoveTo((screenFrame.right - bounds.right) * 0.5f, - (screenFrame.bottom - bounds.bottom) * 0.5f); - - _InitWindow(); - SetPulseRate(500000); } @@ -50,6 +45,10 @@ fBaseView->ChangeTime(message); break; + case B_ABOUT_REQUESTED: + be_app->PostMessage(B_ABOUT_REQUESTED); + break; + default: BWindow::MessageReceived(message); break; @@ -60,10 +59,8 @@ bool TTimeWindow::QuitRequested() { - BMessage msg(UPDATE_SETTINGS); - msg.AddPoint("LeftTop", Frame().LeftTop()); - be_app->PostMessage(&msg); - + TimeSettings().SetLeftTop(Frame().LeftTop()); + fBaseView->StopWatchingAll(fTimeZones); fBaseView->StopWatchingAll(fDateTimeView); @@ -76,6 +73,8 @@ void TTimeWindow::_InitWindow() { + SetPulseRate(500000); + BRect bounds(Bounds()); fBaseView = new TTimeBaseView(bounds, "background view"); @@ -112,3 +111,20 @@ ResizeTo(width +10, height + tabview->TabHeight() +25); } + +void +TTimeWindow::_AlignWindow() +{ + BPoint pt = TimeSettings().LeftTop(); + MoveTo(pt); + + BRect frame = Frame(); + BRect screen = BScreen().Frame(); + if (!frame.Intersects(screen.InsetByCopy(50.0, 50.0))) { + BRect bounds(Bounds()); + BPoint leftTop((screen.Width() - bounds.Width()) / 2.0, + (screen.Height() - bounds.Height()) / 2.0); + + MoveTo(leftTop); + } +} Modified: haiku/trunk/src/preferences/time/TimeWindow.h =================================================================== --- haiku/trunk/src/preferences/time/TimeWindow.h 2007-10-20 16:51:12 UTC (rev 22626) +++ haiku/trunk/src/preferences/time/TimeWindow.h 2007-10-20 18:56:20 UTC (rev 22627) @@ -22,15 +22,17 @@ class TTimeWindow : public BWindow { public: - TTimeWindow(const BPoint topLeft); - virtual ~TTimeWindow() {} + TTimeWindow(BRect rect); + virtual ~TTimeWindow(); virtual bool QuitRequested(); virtual void MessageReceived(BMessage *message); private: void _InitWindow(); + void _AlignWindow(); + private: TTimeBaseView *fBaseView; DateTimeView *fDateTimeView; TZoneView *fTimeZones; From bonefish at mail.berlios.de Sat Oct 20 21:51:50 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sat, 20 Oct 2007 21:51:50 +0200 Subject: [Haiku-commits] r22628 - in haiku/trunk: headers/posix src/system/libroot/posix/unistd Message-ID: <200710201951.l9KJpog9000802@sheep.berlios.de> Author: bonefish Date: 2007-10-20 21:51:49 +0200 (Sat, 20 Oct 2007) New Revision: 22628 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22628&view=rev Added: haiku/trunk/src/system/libroot/posix/unistd/lockf.cpp Modified: haiku/trunk/headers/posix/unistd.h haiku/trunk/src/system/libroot/posix/unistd/Jamfile Log: Patch by Vasilis Kaoutsis: Added and implemented lockf() using fcntl() locking. Small change and notes on standard compliance by myself. Modified: haiku/trunk/headers/posix/unistd.h =================================================================== --- haiku/trunk/headers/posix/unistd.h 2007-10-20 18:56:20 UTC (rev 22627) +++ haiku/trunk/headers/posix/unistd.h 2007-10-20 19:51:49 UTC (rev 22628) @@ -21,6 +21,12 @@ #define STDOUT_FILENO 1 #define STDERR_FILENO 2 +/* function arguments needed by lockf() */ +#define F_ULOCK 0 /* unlock locked sections */ +#define F_LOCK 1 /* lock a section for exclusive use */ +#define F_TLOCK 2 /* test and lock a section for exclusive use */ +#define F_TEST 3 /* test a section for locks by other processes */ + /* POSIX version support */ #define _POSIX_VERSION (199009L) @@ -111,7 +117,8 @@ extern long sysconf(int name); extern long fpathconf(int fd, int name); extern long pathconf(const char *path, int name); -extern size_t confstr(int name, char *buf, size_t len); +extern size_t confstr(int name, char *buf, size_t len); +extern int lockf(int fd, int function, off_t size); /* process functions */ extern pid_t fork(void); Modified: haiku/trunk/src/system/libroot/posix/unistd/Jamfile =================================================================== --- haiku/trunk/src/system/libroot/posix/unistd/Jamfile 2007-10-20 18:56:20 UTC (rev 22627) +++ haiku/trunk/src/system/libroot/posix/unistd/Jamfile 2007-10-20 19:51:49 UTC (rev 22628) @@ -17,6 +17,7 @@ hostname.cpp ioctl.c link.c + lockf.cpp lseek.c mknod.c mount.c Added: haiku/trunk/src/system/libroot/posix/unistd/lockf.cpp =================================================================== --- haiku/trunk/src/system/libroot/posix/unistd/lockf.cpp 2007-10-20 18:56:20 UTC (rev 22627) +++ haiku/trunk/src/system/libroot/posix/unistd/lockf.cpp 2007-10-20 19:51:49 UTC (rev 22628) @@ -0,0 +1,85 @@ +/* + * Copyright 2007, Vasilis Kaoutsis, kaoutsis at sch.gr. + * Distributed under the terms of the MIT License. + */ + +#include +#include +#include + + +int +lockf(int fileDescriptor, int function, off_t size) +{ + struct flock fileLock; + fileLock.l_start = 0; + fileLock.l_len = size; + fileLock.l_whence = SEEK_CUR; + + if (function == F_ULOCK) { + // unlock locked sections + fileLock.l_type = F_UNLCK; + return fcntl(fileDescriptor, F_SETLK, &fileLock); + } else if (function == F_LOCK) { + // lock a section for exclusive use + fileLock.l_type = F_WRLCK; + return fcntl(fileDescriptor, F_SETLKW, &fileLock); + } else if (function == F_TLOCK) { + // test and lock a section for exclusive use + fileLock.l_type = F_WRLCK; + return fcntl(fileDescriptor, F_SETLK, &fileLock); + } else if (function == F_TEST) { + // test a section for locks by other processes + fileLock.l_type = F_WRLCK; + if (fcntl(fileDescriptor, F_GETLK, &fileLock) == -1) + return -1; + if (fileLock.l_type == F_UNLCK) + return 0; + + errno = EAGAIN; + return -1; + } else { + errno = EINVAL; + return -1; + } + + // Notes regarding standard compliance (cf. Open Group Base Specs): + // * "The interaction between fcntl() and lockf() locks is unspecified." + // * fcntl() locking works on a per-process level. The lockf() description + // is a little fuzzy on whether it works the same way. The first quote + // seem to describe per-thread locks (though it might actually mean + // "threads of other processes"), but the others quotes are strongly + // indicating per-process locks: + // - "Calls to lockf() from other threads which attempt to lock the locked + // file section shall either return an error value or block until the + // section becomes unlocked." + // - "All the locks for a process are removed when the process + // terminates." + // - "F_TEST shall detect if a lock by another process is present on the + // specified section." + // - "The sections locked with F_LOCK or F_TLOCK may, in whole or in part, + // contain or be contained by a previously locked section for the same + // process. When this occurs, or if adjacent locked sections would + // occur, the sections shall be combined into a single locked section." + // * fcntl() and lockf() handle a 0 size argument differently. The former + // use the file size at the time of the call: + // "If the command is F_SETLKW and the process must wait for another + // process to release a lock, then the range of bytes to be locked shall + // be determined before the fcntl() function blocks. If the file size + // or file descriptor seek offset change while fcntl() is blocked, this + // shall not affect the range of bytes locked." + // lockf(), on the other hand, is supposed to create a lock whose size + // dynamically adjusts to the file size: + // "If size is 0, the section from the current offset through the largest + // possible file offset shall be locked (that is, from the current + // offset through the present or any future end-of-file)." + // * The lock release handling when closing descriptors sounds a little + // different, though might actually mean the same. + // For fcntl(): + // "All locks associated with a file for a given process shall be removed + // when a file descriptor for that file is closed by that process or the + // process holding that file descriptor terminates." + // For lockf(): + // "File locks shall be released on first close by the locking process of + // any file descriptor for the file." +} From bonefish at mail.berlios.de Sat Oct 20 22:40:24 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sat, 20 Oct 2007 22:40:24 +0200 Subject: [Haiku-commits] r22629 - haiku/trunk/src/apps/codycam Message-ID: <200710202040.l9KKeOug002769@sheep.berlios.de> Author: bonefish Date: 2007-10-20 22:40:09 +0200 (Sat, 20 Oct 2007) New Revision: 22629 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22629&view=rev Modified: haiku/trunk/src/apps/codycam/CodyCam.cpp haiku/trunk/src/apps/codycam/CodyCam.h haiku/trunk/src/apps/codycam/FtpClient.cpp haiku/trunk/src/apps/codycam/FtpClient.h haiku/trunk/src/apps/codycam/Settings.cpp haiku/trunk/src/apps/codycam/Settings.h haiku/trunk/src/apps/codycam/SettingsHandler.cpp haiku/trunk/src/apps/codycam/SettingsHandler.h haiku/trunk/src/apps/codycam/VideoConsumer.cpp haiku/trunk/src/apps/codycam/VideoConsumer.h Log: Style cleanup patch by Vasilis Kaoutsis. Small changes by myself. Modified: haiku/trunk/src/apps/codycam/CodyCam.cpp =================================================================== --- haiku/trunk/src/apps/codycam/CodyCam.cpp 2007-10-20 19:51:49 UTC (rev 22628) +++ haiku/trunk/src/apps/codycam/CodyCam.cpp 2007-10-20 20:40:09 UTC (rev 22629) @@ -1,23 +1,24 @@ #include "CodyCam.h" -#include #include #include +#include + +#include #include -#include +#include +#include +#include +#include #include +#include #include -#include #include -#include -#include #include -#include +#include +#include #include -#include -#include #include -#include #define VIDEO_SIZE_X 320 @@ -38,40 +39,93 @@ const int32 kButtonHeight = 15; const int32 kSliderViewRectHeight = 40; -const rgb_color kViewGray = { 216, 216, 216, 255}; +const rgb_color kViewGray = {216, 216, 216, 255}; -static void ErrorAlert(const char * message, status_t err); -static status_t AddTranslationItems( BMenu * intoMenu, uint32 from_type); +static void ErrorAlert(const char* message, status_t err); +static status_t AddTranslationItems(BMenu* intoMenu, uint32 fromType); #define CALL printf #define ERROR printf #define FTPINFO printf #define INFO printf -//--------------------------------------------------------------- -// The Application -//--------------------------------------------------------------- -int main() { - chdir("/boot/home"); - CodyCam app; - app.Run(); - return 0; +// Utility functions + +static void +ErrorAlert(const char* message, status_t err) +{ + (new BAlert("", message, "Quit"))->Go(); + + printf("%s\n%s [%lx]", message, strerror(err), err); + be_app->PostMessage(B_QUIT_REQUESTED); } -//--------------------------------------------------------------- -CodyCam::CodyCam() : - BApplication("application/x-vnd.Be.CodyCam"), +status_t +AddTranslationItems(BMenu* intoMenu, uint32 fromType) +{ + + BTranslatorRoster* use; + char* translatorTypeName; + const char* translatorIdName; + + use = BTranslatorRoster::Default(); + translatorIdName = "be:translator"; + translatorTypeName = "be:type"; + translator_id* ids = NULL; + int32 count = 0; + + status_t err = use->GetAllTranslators(&ids, &count); + if (err < B_OK) + return err; + + for (int tix = 0; tix < count; tix++) { + const translation_format* formats = NULL; + int32 num_formats = 0; + bool ok = false; + err = use->GetInputFormats(ids[tix], &formats, &num_formats); + if (err == B_OK) + for (int iix = 0; iix < num_formats; iix++) { + if (formats[iix].type == fromType) { + ok = true; + break; + } + } + + if (!ok) + continue; + + err = use->GetOutputFormats(ids[tix], &formats, &num_formats); + if (err == B_OK) + for (int oix = 0; oix < num_formats; oix++) { + if (formats[oix].type != fromType) { + BMessage* itemmsg; + itemmsg = new BMessage(msg_translate); + itemmsg->AddInt32(translatorIdName, ids[tix]); + itemmsg->AddInt32(translatorTypeName, formats[oix].type); + intoMenu->AddItem(new BMenuItem(formats[oix].name, itemmsg)); + } + } + } + delete[] ids; + return B_OK; +} + + +// #pragma mark - + + +CodyCam::CodyCam() + : BApplication("application/x-vnd.Be.CodyCam"), fMediaRoster(NULL), fVideoConsumer(NULL), fWindow(NULL), fPort(0), - mVideoControlWindow(NULL) + fVideoControlWindow(NULL) { } -//--------------------------------------------------------------- CodyCam::~CodyCam() { @@ -87,50 +141,47 @@ CALL("CodyCam::~CodyCam - EXIT\n"); } -//--------------------------------------------------------------- void CodyCam::ReadyToRun() { /* create the window for the app */ - fWindow = new VideoWindow(BRect(28, 28, 28 + (WINDOW_SIZE_X-1), 28 + (WINDOW_SIZE_Y-1)), - (const char *)"CodyCam", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE, &fPort); - + fWindow = new VideoWindow(BRect(28, 28, 28 + (WINDOW_SIZE_X - 1), + 28 + (WINDOW_SIZE_Y - 1)), (const char*)"CodyCam", B_TITLED_WINDOW, + B_NOT_RESIZABLE | B_NOT_ZOOMABLE, &fPort); + /* set up the node connections */ - status_t status = SetUpNodes(); - if (status != B_OK) - { - // This error is not needed because SetUpNodes handles displaying any + status_t status = _SetUpNodes(); + if (status != B_OK) { + // This error is not needed because _SetUpNodes handles displaying any // errors it runs into. // ErrorAlert("Error setting up nodes", status); return; } + + ((VideoWindow*)fWindow)->ApplyControls(); - ((VideoWindow *)fWindow)->ApplyControls(); - } -//--------------------------------------------------------------- + bool CodyCam::QuitRequested() { - TearDownNodes(); + _TearDownNodes(); snooze(100000); return true; } -//--------------------------------------------------------------- void CodyCam::MessageReceived(BMessage *message) { - switch (message->what) - { + switch (message->what) { case msg_start: { - BTimeSource *timeSource = fMediaRoster->MakeTimeSourceFor(fTimeSourceNode); + BTimeSource* timeSource = fMediaRoster->MakeTimeSourceFor(fTimeSourceNode); bigtime_t real = BTimeSource::RealTime(); bigtime_t perf = timeSource->PerformanceTimeFor(real) + 10000; status_t status = fMediaRoster->StartNode(fProducerNode, perf); @@ -139,57 +190,54 @@ timeSource->Release(); break; } + case msg_stop: fMediaRoster->StopNode(fProducerNode, 0, true); break; + case msg_video: { - if (mVideoControlWindow) { - mVideoControlWindow->Activate(); + if (fVideoControlWindow) { + fVideoControlWindow->Activate(); break; } - BParameterWeb * web = NULL; - BView * view = NULL; + BParameterWeb* web = NULL; + BView* view = NULL; media_node node = fProducerNode; status_t err = fMediaRoster->GetParameterWebFor(node, &web); - if ((err >= B_OK) && - (web != NULL)) - { + if (err >= B_OK && web != NULL) { view = BMediaTheme::ViewFor(web); - mVideoControlWindow = new ControlWindow( - BRect(2*WINDOW_OFFSET_X + WINDOW_SIZE_X, WINDOW_OFFSET_Y, - 2*WINDOW_OFFSET_X + WINDOW_SIZE_X + view->Bounds().right, WINDOW_OFFSET_Y + view->Bounds().bottom), - view, node); - fMediaRoster->StartWatching(BMessenger(NULL, mVideoControlWindow), node, B_MEDIA_WEB_CHANGED); - mVideoControlWindow->Show(); + fVideoControlWindow = new ControlWindow( + BRect(2 * WINDOW_OFFSET_X + WINDOW_SIZE_X, WINDOW_OFFSET_Y, + 2 * WINDOW_OFFSET_X + WINDOW_SIZE_X + view->Bounds().right, + WINDOW_OFFSET_Y + view->Bounds().bottom), view, node); + fMediaRoster->StartWatching(BMessenger(NULL, fVideoControlWindow), node, + B_MEDIA_WEB_CHANGED); + fVideoControlWindow->Show(); } break; } + case msg_about: - { - (new BAlert("About CodyCam", "CodyCam\n\nThe Original BeOS WebCam", "Close"))->Go(); + (new BAlert("About CodyCam", "CodyCam\n\nThe Original BeOS WebCam", + "Close"))->Go(); break; - } case msg_control_win: - { // our control window is being asked to go away // set our pointer to NULL - mVideoControlWindow = NULL; + fVideoControlWindow = NULL; break; - - } - + default: BApplication::MessageReceived(message); break; } } -//--------------------------------------------------------------- status_t -CodyCam::SetUpNodes() +CodyCam::_SetUpNodes() { status_t status = B_OK; @@ -198,13 +246,15 @@ if (status != B_OK) { ErrorAlert("Can't find the media roster", status); return status; - } + } + /* find the time source */ status = fMediaRoster->GetTimeSource(&fTimeSourceNode); if (status != B_OK) { ErrorAlert("Can't get a time source", status); return status; } + /* find a video producer node */ INFO("CodyCam acquiring VideoInput node\n"); status = fMediaRoster->GetVideoInput(&fProducerNode); @@ -214,12 +264,13 @@ } /* create the video consumer node */ - fVideoConsumer = new VideoConsumer("CodyCam", ((VideoWindow *)fWindow)->VideoView(), ((VideoWindow *)fWindow)->StatusLine(), NULL, 0); + fVideoConsumer = new VideoConsumer("CodyCam", ((VideoWindow*)fWindow)->VideoView(), + ((VideoWindow*)fWindow)->StatusLine(), NULL, 0); if (!fVideoConsumer) { ErrorAlert("Can't create a video window", B_ERROR); return B_ERROR; } - + /* register the node */ status = fMediaRoster->RegisterNode(fVideoConsumer); if (status != B_OK) { @@ -230,7 +281,8 @@ /* find free producer output */ int32 cnt = 0; - status = fMediaRoster->GetFreeOutputsFor(fProducerNode, &fProducerOut, 1, &cnt, B_MEDIA_RAW_VIDEO); + status = fMediaRoster->GetFreeOutputsFor(fProducerNode, &fProducerOut, 1, &cnt, + B_MEDIA_RAW_VIDEO); if (status != B_OK || cnt < 1) { status = B_RESOURCE_UNAVAILABLE; ErrorAlert("Can't find an available video stream", status); @@ -239,7 +291,8 @@ /* find free consumer input */ cnt = 0; - status = fMediaRoster->GetFreeInputsFor(fVideoConsumer->Node(), &fConsumerIn, 1, &cnt, B_MEDIA_RAW_VIDEO); + status = fMediaRoster->GetFreeInputsFor(fVideoConsumer->Node(), &fConsumerIn, 1, + &cnt, B_MEDIA_RAW_VIDEO); if (status != B_OK || cnt < 1) { status = B_RESOURCE_UNAVAILABLE; ErrorAlert("Can't find an available connection to the video window", status); @@ -249,10 +302,10 @@ /* Connect The Nodes!!! */ media_format format; format.type = B_MEDIA_RAW_VIDEO; - media_raw_video_format vid_format = - { 0, 1, 0, 239, B_VIDEO_TOP_LEFT_RIGHT, 1, 1, {B_RGB32, VIDEO_SIZE_X, VIDEO_SIZE_Y, VIDEO_SIZE_X*4, 0, 0}}; + media_raw_video_format vid_format = {0, 1, 0, 239, B_VIDEO_TOP_LEFT_RIGHT, + 1, 1, {B_RGB32, VIDEO_SIZE_X, VIDEO_SIZE_Y, VIDEO_SIZE_X * 4, 0, 0}}; format.u.raw_video = vid_format; - + /* connect producer to consumer */ status = fMediaRoster->Connect(fProducerOut.source, fConsumerIn.destination, &format, &fProducerOut, &fConsumerIn); @@ -260,20 +313,22 @@ ErrorAlert("Can't connect the video source to the video window", status); return status; } - + + /* set time sources */ + status = fMediaRoster->SetTimeSourceFor(fProducerNode.node, fTimeSourceNode.node); if (status != B_OK) { ErrorAlert("Can't set the timesource for the video source", status); return status; } - + status = fMediaRoster->SetTimeSourceFor(fVideoConsumer->ID(), fTimeSourceNode.node); if (status != B_OK) { ErrorAlert("Can't set the timesource for the video window", status); return status; } - + /* figure out what recording delay to use */ bigtime_t latency = 0; status = fMediaRoster->GetLatencyFor(fProducerNode, &latency); @@ -284,17 +339,18 @@ status = fMediaRoster->GetInitialLatencyFor(fProducerNode, &initLatency); if (status < B_OK) { ErrorAlert("error getting initial latency for fCaptureNode", status); + return status; } + initLatency += estimate_max_scheduling_latency(); - BTimeSource *timeSource = fMediaRoster->MakeTimeSourceFor(fProducerNode); + BTimeSource* timeSource = fMediaRoster->MakeTimeSourceFor(fProducerNode); bool running = timeSource->IsRunning(); - + /* workaround for people without sound cards */ /* because the system time source won't be running */ bigtime_t real = BTimeSource::RealTime(); - if (!running) - { + if (!running) { status = fMediaRoster->StartTimeSource(fTimeSourceNode, real); if (status != B_OK) { timeSource->Release(); @@ -327,17 +383,15 @@ return status; } -//--------------------------------------------------------------- void -CodyCam::TearDownNodes() +CodyCam::_TearDownNodes() { - CALL("CodyCam::TearDownNodes\n"); + CALL("CodyCam::_TearDownNodes\n"); if (!fMediaRoster) return; - if (fVideoConsumer) - { + if (fVideoConsumer) { /* stop */ INFO("stopping nodes!\n"); // fMediaRoster->StopNode(fProducerNode, 0, true); @@ -345,7 +399,7 @@ /* disconnect */ fMediaRoster->Disconnect(fProducerOut.node.node, fProducerOut.source, - fConsumerIn.node.node, fConsumerIn.destination); + fConsumerIn.node.node, fConsumerIn.destination); if (fProducerNode != media_node::null) { INFO("CodyCam releasing fProducerNode\n"); @@ -357,71 +411,14 @@ } } -//--------------------------------------------------------------- -// Utility functions -//--------------------------------------------------------------- -static void -ErrorAlert(const char * message, status_t err) -{ - (new BAlert("", message, "Quit"))->Go(); - - printf("%s\n%s [%lx]", message, strerror(err), err); - be_app->PostMessage(B_QUIT_REQUESTED); -} +// #pragma mark - Video Window Class -//--------------------------------------------------------------- -status_t -AddTranslationItems( BMenu * intoMenu, uint32 from_type) -{ - - BTranslatorRoster * use; - char * translator_type_name; - const char * translator_id_name; - - use = BTranslatorRoster::Default(); - translator_id_name = "be:translator"; - translator_type_name = "be:type"; - translator_id * ids = NULL; - int32 count = 0; - - status_t err = use->GetAllTranslators(&ids, &count); - if (err < B_OK) return err; - for (int tix=0; tixGetInputFormats(ids[tix], &formats, &num_formats); - if (err == B_OK) for (int iix=0; iixGetOutputFormats(ids[tix], &formats, &num_formats); - if (err == B_OK) for (int oix=0; oixAddInt32(translator_id_name, ids[tix]); - itemmsg->AddInt32(translator_type_name, formats[oix].type); - intoMenu->AddItem(new BMenuItem(formats[oix].name, itemmsg)); - } - } - } - delete[] ids; - return B_OK; -} - -//--------------------------------------------------------------- -// Video Window Class -//--------------------------------------------------------------- - -VideoWindow::VideoWindow (BRect frame, const char *title, window_type type, uint32 flags, port_id * consumerport) : - BWindow(frame,title,type,flags), - fPortPtr(consumerport), +VideoWindow::VideoWindow (BRect frame, const char* title, window_type type, uint32 flags, + port_id* consumerPort) + : BWindow(frame,title,type,flags), + fPortPtr(consumerPort), fView(NULL), fVideoView(NULL) { @@ -436,9 +433,9 @@ strcpy(fFtpInfo.passwordText, "password"); strcpy(fFtpInfo.directoryText, "directory"); - SetUpSettings("codycam", ""); + _SetUpSettings("codycam", ""); - BMenuBar* menuBar = new BMenuBar(BRect(0,0,0,0), "menu bar"); + BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 0, 0), "menu bar"); AddChild(menuBar); BMenuItem* menuItem; @@ -482,11 +479,11 @@ AddChild(fView); /* add some controls */ - BuildCaptureControls(fView); + _BuildCaptureControls(fView); /* add another view to hold the video image */ aRect = BRect(0, 0, VIDEO_SIZE_X - 1, VIDEO_SIZE_Y - 1); - aRect.OffsetBy((WINDOW_SIZE_X - VIDEO_SIZE_X)/2, kYBuffer); + aRect.OffsetBy((WINDOW_SIZE_X - VIDEO_SIZE_X) / 2, kYBuffer); fVideoView = new BView(aRect, "Video View", B_FOLLOW_ALL, B_WILL_DRAW); fView->AddChild(fVideoView); @@ -494,15 +491,15 @@ Show(); } -//--------------------------------------------------------------- + VideoWindow::~VideoWindow() { - QuitSettings(); + _QuitSettings(); } -//--------------------------------------------------------------- + bool VideoWindow::QuitRequested() { @@ -510,172 +507,181 @@ return false; } -//--------------------------------------------------------------- void -VideoWindow::MessageReceived(BMessage *message) +VideoWindow::MessageReceived(BMessage* message) { - BControl *p; + BControl* control; - p = NULL; - message->FindPointer((const char *)"source",(void **)&p); - - switch (message->what) - { + control = NULL; + message->FindPointer((const char*)"source", (void **)&control); + + switch (message->what) { case msg_filename: - if (p != NULL) - { - strncpy(fFtpInfo.fileNameText, ((BTextControl *)p)->Text(), 63); + if (control != NULL) { + strncpy(fFtpInfo.fileNameText, ((BTextControl*)control)->Text(), 63); FTPINFO("file is '%s'\n", fFtpInfo.fileNameText); } break; + case msg_rate_15s: FTPINFO("fifteen seconds\n"); fFtpInfo.rate = (bigtime_t)(15 * 1000000); break; + case msg_rate_30s: FTPINFO("thirty seconds\n"); fFtpInfo.rate = (bigtime_t)(30 * 1000000); break; + case msg_rate_1m: FTPINFO("one minute\n"); fFtpInfo.rate = (bigtime_t)(1 * 60 * 1000000); break; + case msg_rate_5m: FTPINFO("five minute\n"); fFtpInfo.rate = (bigtime_t)(5 * 60 * 1000000); break; + case msg_rate_10m: FTPINFO("ten minute\n"); fFtpInfo.rate = (bigtime_t)(10 * 60 * 1000000); break; + case msg_rate_15m: FTPINFO("fifteen minute\n"); fFtpInfo.rate = (bigtime_t)(15 * 60 * 1000000); break; + case msg_rate_30m: FTPINFO("thirty minute\n"); fFtpInfo.rate = (bigtime_t)(30 * 60 * 1000000); break; + case msg_rate_1h: FTPINFO("one hour\n"); fFtpInfo.rate = (bigtime_t)(60LL * 60LL * 1000000LL); break; + case msg_rate_2h: FTPINFO("two hour\n"); fFtpInfo.rate = (bigtime_t)(2LL * 60LL * 60LL * 1000000LL); break; + case msg_rate_4h: FTPINFO("four hour\n"); fFtpInfo.rate = (bigtime_t)(4LL * 60LL * 60LL * 1000000LL); break; + case msg_rate_8h: FTPINFO("eight hour\n"); fFtpInfo.rate = (bigtime_t)(8LL * 60LL * 60LL * 1000000LL); break; + case msg_rate_24h: FTPINFO("24 hour\n"); fFtpInfo.rate = (bigtime_t)(24LL * 60LL * 60LL * 1000000LL); break; + case msg_rate_never: FTPINFO("never\n"); fFtpInfo.rate = (bigtime_t)(B_INFINITE_TIMEOUT); break; + case msg_translate: - message->FindInt32("be:type", (int32 *)&(fFtpInfo.imageFormat)); + message->FindInt32("be:type", (int32*)&(fFtpInfo.imageFormat)); message->FindInt32("be:translator", &(fFtpInfo.translator)); break; + case msg_server: - if (p != NULL) - { - strncpy(fFtpInfo.serverText, ((BTextControl *)p)->Text(), 64); + if (control != NULL) { + strncpy(fFtpInfo.serverText, ((BTextControl*)control)->Text(), 64); FTPINFO("server = '%s'\n", fFtpInfo.serverText); } break; + case msg_login: - if (p != NULL) - { - strncpy(fFtpInfo.loginText, ((BTextControl *)p)->Text(), 64); + if (control != NULL) { + strncpy(fFtpInfo.loginText, ((BTextControl*)control)->Text(), 64); FTPINFO("login = '%s'\n", fFtpInfo.loginText); } break; + case msg_password: - if (p != NULL) - { - strncpy(fFtpInfo.passwordText, ((BTextControl *)p)->Text(), 64); + if (control != NULL) { + strncpy(fFtpInfo.passwordText, ((BTextControl*)control)->Text(), 64); FTPINFO("password = '%s'\n", fFtpInfo.passwordText); - if (Lock()) - { - ((BTextControl *)p)->SetText(""); + if (Lock()) { + ((BTextControl*)control)->SetText(""); Unlock(); } } break; + case msg_directory: - if (p != NULL) - { - strncpy(fFtpInfo.directoryText, ((BTextControl *)p)->Text(), 64); + if (control != NULL) { + strncpy(fFtpInfo.directoryText, ((BTextControl*)control)->Text(), 64); FTPINFO("directory = '%s'\n", fFtpInfo.directoryText); } break; + case msg_passiveftp: - if (p != NULL) - { - fFtpInfo.passiveFtp = ((BCheckBox *)p)->Value(); + if (control != NULL) { + fFtpInfo.passiveFtp = ((BCheckBox*)control)->Value(); if (fFtpInfo.passiveFtp) FTPINFO("using passive ftp\n"); } break; + default: BWindow::MessageReceived(message); return; } if (*fPortPtr) - write_port(*fPortPtr, FTP_INFO, (void *)&fFtpInfo, sizeof(ftp_msg_info)); + write_port(*fPortPtr, FTP_INFO, (void*)&fFtpInfo, sizeof(ftp_msg_info)); } -//--------------------------------------------------------------- -BView * +BView* VideoWindow::VideoView() { return fVideoView; } -//--------------------------------------------------------------- -BStringView * +BStringView* VideoWindow::StatusLine() { return fStatusLine; } -//--------------------------------------------------------------- void -VideoWindow::BuildCaptureControls(BView *theView) +VideoWindow::_BuildCaptureControls(BView* theView) { BRect aFrame, theFrame; theFrame = theView->Bounds(); - theFrame.top += VIDEO_SIZE_Y + 2*kYBuffer + 40; + theFrame.top += VIDEO_SIZE_Y + 2 * kYBuffer + 40; theFrame.left += kXBuffer; - theFrame.right -= (WINDOW_SIZE_X/2 + 5); + theFrame.right -= (WINDOW_SIZE_X / 2 + 5); theFrame.bottom -= kXBuffer; - - fCaptureSetupBox = new BBox( theFrame, "Capture Controls", B_FOLLOW_ALL, B_WILL_DRAW); + + fCaptureSetupBox = new BBox(theFrame, "Capture Controls", B_FOLLOW_ALL, B_WILL_DRAW); fCaptureSetupBox->SetLabel("Capture Controls"); theView->AddChild(fCaptureSetupBox); - + aFrame = fCaptureSetupBox->Bounds(); - aFrame.InsetBy(kXBuffer,kYBuffer); - aFrame.top += kYBuffer/2; + aFrame.InsetBy(kXBuffer, kYBuffer); + aFrame.top += kYBuffer / 2; aFrame.bottom = aFrame.top + kMenuHeight; - - fFileName = new BTextControl(aFrame, "File Name", "File Name:", fFilenameSetting->Value(), new BMessage(msg_filename)); + fFileName = new BTextControl(aFrame, "File Name", "File Name:", + fFilenameSetting->Value(), new BMessage(msg_filename)); + fFileName->SetTarget(BMessenger(NULL, this)); fFileName->SetDivider(fFileName->Divider() - 30); fCaptureSetupBox->AddChild(fFileName); @@ -686,10 +692,12 @@ fImageFormatMenu = new BPopUpMenu("Image Format Menu"); AddTranslationItems(fImageFormatMenu, B_TRANSLATOR_BITMAP); fImageFormatMenu->SetTargetForItems(this); + if (fImageFormatMenu->FindItem("JPEG Image") != NULL) fImageFormatMenu->FindItem("JPEG Image")->SetMarked(true); else - fImageFormatMenu->ItemAt(0)->SetMarked(true); + fImageFormatMenu->ItemAt(0)->SetMarked(true); + fImageFormatSelector = new BMenuField(aFrame, "Format", "Format:", fImageFormatMenu); fImageFormatSelector->SetDivider(fImageFormatSelector->Divider() - 30); fCaptureSetupBox->AddChild(fImageFormatSelector); @@ -698,19 +706,19 @@ aFrame.bottom = aFrame.top + kMenuHeight; fCaptureRateMenu = new BPopUpMenu("Capture Rate Menu"); - fCaptureRateMenu->AddItem(new BMenuItem("Every 15 seconds",new BMessage(msg_rate_15s))); - fCaptureRateMenu->AddItem(new BMenuItem("Every 30 seconds",new BMessage(msg_rate_30s))); - fCaptureRateMenu->AddItem(new BMenuItem("Every minute",new BMessage(msg_rate_1m))); - fCaptureRateMenu->AddItem(new BMenuItem("Every 5 minutes",new BMessage(msg_rate_5m))); - fCaptureRateMenu->AddItem(new BMenuItem("Every 10 minutes",new BMessage(msg_rate_10m))); - fCaptureRateMenu->AddItem(new BMenuItem("Every 15 minutes",new BMessage(msg_rate_15m))); - fCaptureRateMenu->AddItem(new BMenuItem("Every 30 minutes",new BMessage(msg_rate_30m))); - fCaptureRateMenu->AddItem(new BMenuItem("Every hour",new BMessage(msg_rate_1h))); - fCaptureRateMenu->AddItem(new BMenuItem("Every 2 hours",new BMessage(msg_rate_2h))); - fCaptureRateMenu->AddItem(new BMenuItem("Every 4 hours",new BMessage(msg_rate_4h))); - fCaptureRateMenu->AddItem(new BMenuItem("Every 8 hours",new BMessage(msg_rate_8h))); - fCaptureRateMenu->AddItem(new BMenuItem("Every 24 hours",new BMessage(msg_rate_24h))); - fCaptureRateMenu->AddItem(new BMenuItem("Never",new BMessage(msg_rate_never))); + fCaptureRateMenu->AddItem(new BMenuItem("Every 15 seconds", new BMessage(msg_rate_15s))); + fCaptureRateMenu->AddItem(new BMenuItem("Every 30 seconds", new BMessage(msg_rate_30s))); + fCaptureRateMenu->AddItem(new BMenuItem("Every minute", new BMessage(msg_rate_1m))); + fCaptureRateMenu->AddItem(new BMenuItem("Every 5 minutes", new BMessage(msg_rate_5m))); + fCaptureRateMenu->AddItem(new BMenuItem("Every 10 minutes", new BMessage(msg_rate_10m))); + fCaptureRateMenu->AddItem(new BMenuItem("Every 15 minutes", new BMessage(msg_rate_15m))); + fCaptureRateMenu->AddItem(new BMenuItem("Every 30 minutes", new BMessage(msg_rate_30m))); + fCaptureRateMenu->AddItem(new BMenuItem("Every hour", new BMessage(msg_rate_1h))); + fCaptureRateMenu->AddItem(new BMenuItem("Every 2 hours", new BMessage(msg_rate_2h))); + fCaptureRateMenu->AddItem(new BMenuItem("Every 4 hours", new BMessage(msg_rate_4h))); + fCaptureRateMenu->AddItem(new BMenuItem("Every 8 hours", new BMessage(msg_rate_8h))); + fCaptureRateMenu->AddItem(new BMenuItem("Every 24 hours", new BMessage(msg_rate_24h))); + fCaptureRateMenu->AddItem(new BMenuItem("Never", new BMessage(msg_rate_never))); fCaptureRateMenu->SetTargetForItems(this); fCaptureRateMenu->FindItem(fCaptureRateSetting->Value())->SetMarked(true); fCaptureRateSelector = new BMenuField(aFrame, "Rate", "Rate:", fCaptureRateMenu); @@ -718,76 +726,80 @@ fCaptureSetupBox->AddChild(fCaptureRateSelector); aFrame = theView->Bounds(); - aFrame.top += VIDEO_SIZE_Y + 2*kYBuffer + 40; - aFrame.left += WINDOW_SIZE_X/2 + 5; + aFrame.top += VIDEO_SIZE_Y + 2 * kYBuffer + 40; + aFrame.left += WINDOW_SIZE_X / 2 + 5; aFrame.right -= kXBuffer; aFrame.bottom -= kYBuffer; - - fFtpSetupBox = new BBox( aFrame, "Ftp Setup", B_FOLLOW_ALL, B_WILL_DRAW); + + fFtpSetupBox = new BBox(aFrame, "Ftp Setup", B_FOLLOW_ALL, B_WILL_DRAW); fFtpSetupBox->SetLabel("Ftp Setup"); theView->AddChild(fFtpSetupBox); - + aFrame = fFtpSetupBox->Bounds(); aFrame.InsetBy(kXBuffer,kYBuffer); aFrame.top += kYBuffer/2; aFrame.bottom = aFrame.top + kMenuHeight; aFrame.right = aFrame.left + 160; - - fServerName = new BTextControl(aFrame, "Server", "Server:", fServerSetting->Value(), new BMessage(msg_server)); + + fServerName = new BTextControl(aFrame, "Server", "Server:", fServerSetting->Value(), + new BMessage(msg_server)); fServerName->SetTarget(this); fServerName->SetDivider(fServerName->Divider() - 30); fFtpSetupBox->AddChild(fServerName); aFrame.top = aFrame.bottom + kYBuffer; aFrame.bottom = aFrame.top + kMenuHeight; - - fLoginId = new BTextControl(aFrame, "Login", "Login:", fLoginSetting->Value(), new BMessage(msg_login)); + + fLoginId = new BTextControl(aFrame, "Login", "Login:", fLoginSetting->Value(), + new BMessage(msg_login)); fLoginId->SetTarget(this); fLoginId->SetDivider(fLoginId->Divider() - 30); fFtpSetupBox->AddChild(fLoginId); aFrame.top = aFrame.bottom + kYBuffer; aFrame.bottom = aFrame.top + kMenuHeight; - - fPassword = new BTextControl(aFrame, "Password", "Password:", fPasswordSetting->Value(), new BMessage(msg_password)); + + fPassword = new BTextControl(aFrame, "Password", "Password:", + fPasswordSetting->Value(), new BMessage(msg_password)); fPassword->SetTarget(this); fPassword->SetDivider(fPassword->Divider() - 30); fFtpSetupBox->AddChild(fPassword); aFrame.top = aFrame.bottom + kYBuffer; aFrame.bottom = aFrame.top + kMenuHeight; - - fDirectory = new BTextControl(aFrame, "Directory", "Directory:", fDirectorySetting->Value(), new BMessage(msg_directory)); + + fDirectory = new BTextControl(aFrame, "Directory", "Directory:", + fDirectorySetting->Value(), new BMessage(msg_directory)); fDirectory->SetTarget(this); fDirectory->SetDivider(fDirectory->Divider() - 30); fFtpSetupBox->AddChild(fDirectory); aFrame.top = aFrame.bottom + kYBuffer; aFrame.bottom = aFrame.top + kMenuHeight; - - fPassiveFtp = new BCheckBox(aFrame, "Passive ftp", "Passive ftp", new BMessage(msg_passiveftp)); + + fPassiveFtp = new BCheckBox(aFrame, "Passive ftp", "Passive ftp", + new BMessage(msg_passiveftp)); fPassiveFtp->SetTarget(this); fPassiveFtp->SetValue(fPassiveFtpSetting->Value()); fFtpSetupBox->AddChild(fPassiveFtp); - + aFrame = theView->Bounds(); - aFrame.top += VIDEO_SIZE_Y + 2*kYBuffer; + aFrame.top += VIDEO_SIZE_Y + 2 * kYBuffer; aFrame.left += kXBuffer; aFrame.right -= kXBuffer; - aFrame.bottom = aFrame.top + kMenuHeight + 2*kYBuffer; - - fStatusBox = new BBox( aFrame, "Status", B_FOLLOW_ALL, B_WILL_DRAW); + aFrame.bottom = aFrame.top + kMenuHeight + 2 * kYBuffer; + + fStatusBox = new BBox(aFrame, "Status", B_FOLLOW_ALL, B_WILL_DRAW); fStatusBox->SetLabel("Status"); theView->AddChild(fStatusBox); - + aFrame = fStatusBox->Bounds(); - aFrame.InsetBy(kXBuffer,kYBuffer); - - fStatusLine = new BStringView(aFrame,"Status Line","Waiting ..."); + aFrame.InsetBy(kXBuffer, kYBuffer); + + fStatusLine = new BStringView(aFrame, "Status Line", "Waiting ..."); fStatusBox->AddChild(fStatusLine); } -//--------------------------------------------------------------- void VideoWindow::ApplyControls() @@ -803,10 +815,9 @@ fPassiveFtp->Invoke(); } -//--------------------------------------------------------------- void -VideoWindow::SetUpSettings(const char *filename, const char *dirname) +VideoWindow::_SetUpSettings(const char* filename, const char* dirname) { fSettings = new Settings(filename, dirname); @@ -819,18 +830,18 @@ fSettings->Add(fDirectorySetting = new StringValueSetting("Directory", "web/images", "destination directory expected", "")); fSettings->Add(fPassiveFtpSetting = new BooleanValueSetting("PassiveFtp", 1)); - fSettings->Add(fFilenameSetting = new StringValueSetting("StillImageFilename", "codycam.jpg", - "still image filename expected", "")); - fSettings->Add(fCaptureRateSetting = new EnumeratedStringValueSetting("CaptureRate", "Every 5 minutes", kCaptureRate, - "capture rate expected", "unrecognized capture rate specified")); + fSettings->Add(fFilenameSetting = new StringValueSetting("StillImageFilename", + "codycam.jpg", "still image filename expected", "")); + fSettings->Add(fCaptureRateSetting = new EnumeratedStringValueSetting("CaptureRate", + "Every 5 minutes", kCaptureRate, "capture rate expected", + "unrecognized capture rate specified")); fSettings->TryReadingSettings(); } -//--------------------------------------------------------------- void -VideoWindow::QuitSettings() +VideoWindow::_QuitSettings() { fServerSetting->ValueChanged(fServerName->Text()); fLoginSetting->ValueChanged(fLoginId->Text()); @@ -844,13 +855,12 @@ delete fSettings; } -//--------------------------------------------------------------- -ControlWindow::ControlWindow( - const BRect & frame, - BView * controls, - media_node node) : - BWindow(frame, "Video Preferences", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS) +// #pragma mark - + + +ControlWindow::ControlWindow(const BRect& frame, BView* controls, media_node node) + : BWindow(frame, "Video Preferences", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS) { fView = controls; fNode = node; @@ -858,52 +868,47 @@ AddChild(fView); } -//--------------------------------------------------------------- [... truncated: 4161 lines follow ...] From bonefish at mail.berlios.de Sun Oct 21 12:15:58 2007 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sun, 21 Oct 2007 12:15:58 +0200 Subject: [Haiku-commits] r22630 - in haiku/trunk: build/jam src/build/libhaikucompat src/tests/servers/app Message-ID: <200710211015.l9LAFwUJ005485@sheep.berlios.de> Author: bonefish Date: 2007-10-21 12:15:57 +0200 (Sun, 21 Oct 2007) New Revision: 22630 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22630&view=rev Modified: haiku/trunk/build/jam/BuildSetup haiku/trunk/src/build/libhaikucompat/Jamfile haiku/trunk/src/tests/servers/app/Jamfile Log: Added header directories missing for the libbe_test target, since my changes a while ago that removed the incorrect automatic addition of Haiku header directories in case of targets other than "haiku". The app server test environment does now almost build again. The problem left is related to the recent changes of the accelerant interface. I suppose someone in the knows should decide if we can simply use our header or if special handling is needed. Modified: haiku/trunk/build/jam/BuildSetup =================================================================== --- haiku/trunk/build/jam/BuildSetup 2007-10-20 20:40:09 UTC (rev 22629) +++ haiku/trunk/build/jam/BuildSetup 2007-10-21 10:15:57 UTC (rev 22630) @@ -741,7 +741,8 @@ if $(TARGET_PLATFORM) = libbe_test { # headers and flags TARGET_HDRS += - [ PublicHeaders app drivers game interface kernel storage support ] + [ PublicHeaders $(DOT) app drivers game interface kernel storage + support ] [ PrivateHeaders $(DOT) ] ; TARGET_DEFINES += __HAIKU__ ; Modified: haiku/trunk/src/build/libhaikucompat/Jamfile =================================================================== --- haiku/trunk/src/build/libhaikucompat/Jamfile 2007-10-20 20:40:09 UTC (rev 22629) +++ haiku/trunk/src/build/libhaikucompat/Jamfile 2007-10-21 10:15:57 UTC (rev 22630) @@ -2,6 +2,7 @@ SetSubDirSupportedPlatforms libbe_test r5 dano bone ; +UseHeaders [ FDirName $(HAIKU_TOP) headers build private ] : true ; UseHeaders [ FDirName $(HAIKU_TOP) headers build private kernel ] : true ; local libbeTestSources ; Modified: haiku/trunk/src/tests/servers/app/Jamfile =================================================================== --- haiku/trunk/src/tests/servers/app/Jamfile 2007-10-20 20:40:09 UTC (rev 22629) +++ haiku/trunk/src/tests/servers/app/Jamfile 2007-10-21 10:15:57 UTC (rev 22630) @@ -7,6 +7,7 @@ UseLibraryHeaders agg png zlib ; UsePrivateHeaders app graphics input interface shared storage ; +UsePrivateHeaders [ FDirName graphics common ] ; # headers/build/private/kernel is needed for safemode.h and syscalls.h. # headers/private/kernel for the util/* stuff. From superstippi at gmx.de Sun Oct 21 12:47:55 2007 From: superstippi at gmx.de (Stephan Assmus) Date: Sun, 21 Oct 2007 12:47:55 +0200 Subject: [Haiku-commits] r22630 - in haiku/trunk: build/jam src/build/libhaikucompat src/tests/servers/app In-Reply-To: <200710211015.l9LAFwUJ005485@sheep.berlios.de> References: <200710211015.l9LAFwUJ005485@sheep.berlios.de> Message-ID: <20071021124755.653.5@stippis.WG> bonefish at BerliOS wrote (2007-10-21, 12:15:58 [+0200]): > Author: bonefish > Date: 2007-10-21 12:15:57 +0200 (Sun, 21 Oct 2007) New Revision: 22630 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22630&view=rev > > Modified: > haiku/trunk/build/jam/BuildSetup > haiku/trunk/src/build/libhaikucompat/Jamfile > haiku/trunk/src/tests/servers/app/Jamfile > Log: > Added header directories missing for the libbe_test target, since my > changes a while ago that removed the incorrect automatic addition of > Haiku header directories in case of targets other than "haiku". The app > server test environment does now almost build again. The problem left is > related to the recent changes of the accelerant interface. I suppose > someone in the knows should decide if we can simply use our header or if > special handling is needed. Great! Just as I was about to give it another try! :-) Thanks and best regards, -Stephan From axeld at mail.berlios.de Sun Oct 21 12:58:24 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sun, 21 Oct 2007 12:58:24 +0200 Subject: [Haiku-commits] r22631 - in haiku/trunk/src/tests/kits/net: . tcp_shell Message-ID: <200710211058.l9LAwOMG017500@sheep.berlios.de> Author: axeld Date: 2007-10-21 12:58:24 +0200 (Sun, 21 Oct 2007) New Revision: 22631 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22631&view=rev Added: haiku/trunk/src/tests/kits/net/tcp_shell/ haiku/trunk/src/tests/kits/net/tcp_shell/Jamfile haiku/trunk/src/tests/kits/net/tcp_shell/tcp_tester.cpp Removed: haiku/trunk/src/tests/kits/net/new_stack/ haiku/trunk/src/tests/kits/net/tcp_tester.cpp Modified: haiku/trunk/src/tests/kits/net/Jamfile Log: * Removed the "new_stack" test approach; it's no longer useful, and you can still look for it in the SVN history if you like. * Moved tcp_tester.cpp to its own sub-directory tcp_shell - it doesn't yet build, though (due to recent changes to the stack/TCP implementation). Modified: haiku/trunk/src/tests/kits/net/Jamfile =================================================================== --- haiku/trunk/src/tests/kits/net/Jamfile 2007-10-21 10:15:57 UTC (rev 22630) +++ haiku/trunk/src/tests/kits/net/Jamfile 2007-10-21 10:58:24 UTC (rev 22631) @@ -2,22 +2,6 @@ SetSubDirSupportedPlatformsBeOSCompatible ; -SubDirHdrs [ FDirName $(HAIKU_TOP) src tests add-ons kernel file_systems fs_shell ] ; -SubDirHdrs [ FDirName $(HAIKU_TOP) src add-ons kernel network protocols tcp ] ; -SubDirHdrs [ FDirName $(HAIKU_TOP) src add-ons kernel network stack ] ; -UseHeaders $(TARGET_PRIVATE_KERNEL_HEADERS) : true ; -UsePrivateHeaders net ; - -# bonefish: Tried to get the first test compiling. It complained about not -# being able to find some headers, thus I added the respective include dirs -# until it was asking for headers we currently don't have -# (sys/select.h, sys/sockio.h). - -#SubDirHdrs [ FDirName $(HAIKU_TOP) headers posix sys ] ; -#SubDirHdrs [ FDirName $(HAIKU_TOP) headers posix net ] ; -#UsePrivateHeaders kernel ; -#UseArchHeaders $(TARGET_ARCH) ; - SimpleTest udp_client : udp_client.c : $(TARGET_NETWORK_LIBS) ; SimpleTest udp_echo : udp_echo.c : $(TARGET_NETWORK_LIBS) ; SimpleTest udp_server : udp_server.c : $(TARGET_NETWORK_LIBS) ; @@ -25,45 +9,9 @@ SimpleTest tcp_server : tcp_server.c : $(TARGET_NETWORK_LIBS) ; SimpleTest tcp_client : tcp_client.c : $(TARGET_NETWORK_LIBS) ; -SimpleTest tcp_tester : - tcp_tester.cpp - - # stack - net_buffer.cpp - utility.cpp - - # tcp - tcp.cpp - TCPEndpoint.cpp - BufferQueue.cpp - EndpointManager.cpp - - # misc - argv.c - ipv4_address.cpp - - : be libkernelland_emu.so -; - -SEARCH on [ FGristFiles - tcp.cpp TCPEndpoint.cpp BufferQueue.cpp EndpointManager.cpp - ] = [ FDirName $(HAIKU_TOP) src add-ons kernel network protocols tcp ] ; - -SEARCH on [ FGristFiles - ipv4_address.cpp - ] = [ FDirName $(HAIKU_TOP) src add-ons kernel network protocols ipv4 ] ; - -SEARCH on [ FGristFiles - net_buffer.cpp utility.cpp - ] = [ FDirName $(HAIKU_TOP) src add-ons kernel network stack ] ; - -SEARCH on [ FGristFiles - argv.c - ] = [ FDirName $(HAIKU_TOP) src tests add-ons kernel file_systems fs_shell ] ; - SubInclude HAIKU_TOP src tests kits net DialUpPreflet ; SubInclude HAIKU_TOP src tests kits net multicast ; SubInclude HAIKU_TOP src tests kits net netperf ; -# SubInclude HAIKU_TOP src tests kits net new_stack ; SubInclude HAIKU_TOP src tests kits net preflet ; +SubInclude HAIKU_TOP src tests kits net tcp_shell ; SubInclude HAIKU_TOP src tests kits net tcptester ; Added: haiku/trunk/src/tests/kits/net/tcp_shell/Jamfile =================================================================== --- haiku/trunk/src/tests/kits/net/tcp_shell/Jamfile 2007-10-21 10:15:57 UTC (rev 22630) +++ haiku/trunk/src/tests/kits/net/tcp_shell/Jamfile 2007-10-21 10:58:24 UTC (rev 22631) @@ -0,0 +1,45 @@ +SubDir HAIKU_TOP src tests kits net tcp_shell ; + +SetSubDirSupportedPlatformsBeOSCompatible ; + +SubDirHdrs [ FDirName $(HAIKU_TOP) src tests add-ons kernel file_systems fs_shell ] ; +SubDirHdrs [ FDirName $(HAIKU_TOP) src add-ons kernel network protocols tcp ] ; +SubDirHdrs [ FDirName $(HAIKU_TOP) src add-ons kernel network stack ] ; +UseHeaders $(TARGET_PRIVATE_KERNEL_HEADERS) : true ; +UsePrivateHeaders kernel net shared ; + +SimpleTest tcp_shell : + tcp_tester.cpp + + # stack + net_buffer.cpp + utility.cpp + + # tcp + tcp.cpp + TCPEndpoint.cpp + BufferQueue.cpp + EndpointManager.cpp + + # misc + argv.c + ipv4_address.cpp + + : be libkernelland_emu.so +; + +SEARCH on [ FGristFiles + tcp.cpp TCPEndpoint.cpp BufferQueue.cpp EndpointManager.cpp + ] = [ FDirName $(HAIKU_TOP) src add-ons kernel network protocols tcp ] ; + +SEARCH on [ FGristFiles + ipv4_address.cpp + ] = [ FDirName $(HAIKU_TOP) src add-ons kernel network protocols ipv4 ] ; + +SEARCH on [ FGristFiles + net_buffer.cpp utility.cpp + ] = [ FDirName $(HAIKU_TOP) src add-ons kernel network stack ] ; + +SEARCH on [ FGristFiles + argv.c + ] = [ FDirName $(HAIKU_TOP) src tests add-ons kernel file_systems fs_shell ] ; Copied: haiku/trunk/src/tests/kits/net/tcp_shell/tcp_tester.cpp (from rev 22620, haiku/trunk/src/tests/kits/net/tcp_tester.cpp) Deleted: haiku/trunk/src/tests/kits/net/tcp_tester.cpp From axeld at mail.berlios.de Sun Oct 21 13:00:31 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sun, 21 Oct 2007 13:00:31 +0200 Subject: [Haiku-commits] r22632 - haiku/trunk/src/servers/app Message-ID: <200710211100.l9LB0VNp019791@sheep.berlios.de> Author: axeld Date: 2007-10-21 13:00:30 +0200 (Sun, 21 Oct 2007) New Revision: 22632 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22632&view=rev Modified: haiku/trunk/src/servers/app/VirtualScreen.cpp haiku/trunk/src/servers/app/VirtualScreen.h Log: Revised named configurations a bit: * Named settings are only overwritten if they were an exact match (ie. it's the very same monitor). * The unnamed settings retrieval now has two passes, on the first it will now ignore named settings. It will also only remove unnamed settings now. * Added some TODO commments. Modified: haiku/trunk/src/servers/app/VirtualScreen.cpp =================================================================== --- haiku/trunk/src/servers/app/VirtualScreen.cpp 2007-10-21 10:58:24 UTC (rev 22631) +++ haiku/trunk/src/servers/app/VirtualScreen.cpp 2007-10-21 11:00:30 UTC (rev 22632) @@ -140,7 +140,7 @@ status_t status = B_ERROR; BMessage settings; - if (_FindConfiguration(screen, settings) == B_OK) { + if (_GetConfiguration(screen, settings) == B_OK) { // we found settings for this screen, and try to apply them now int32 width, height, colorSpace; const display_timing* timing; @@ -152,6 +152,7 @@ &size) == B_OK && size == sizeof(display_timing)) status = screen->SetMode(width, height, colorSpace, *timing, true); + // TODO: named settings will get lost if setting the mode failed! } if (status < B_OK) { // TODO: more intelligent standard mode (monitor preference, desktop default, ...) @@ -240,32 +241,39 @@ status_t -VirtualScreen::_FindConfiguration(Screen* screen, BMessage& settings) +VirtualScreen::_GetConfiguration(Screen* screen, BMessage& settings) { monitor_info info; bool hasInfo = screen->GetMonitorInfo(info) == B_OK; if (!hasInfo) { // only look for a matching ID - this is all we have - for (uint32 i = 0; fSettings.FindMessage("screen", i, - &settings) == B_OK; i++) { - int32 id; - if (settings.FindInt32("id", &id) != B_OK - || screen->ID() != id) - continue; + for (uint32 k = 0; k < 2; k++) { + for (uint32 i = 0; fSettings.FindMessage("screen", i, + &settings) == B_OK; i++) { + int32 id; + if (k == 0 && settings.HasString("name") + || settings.FindInt32("id", &id) != B_OK + || screen->ID() != id) + continue; - // we found our match - fSettings.RemoveData("screen", i); - return B_OK; + // we found our match, only remove unnamed settings + if (k == 0) + fSettings.RemoveData("screen", i); + return B_OK; + } } + return B_NAME_NOT_FOUND; } // look for a monitor configuration that matches ours + bool exactMatch = false; int32 bestScore = 0; int32 bestIndex = -1; BMessage stored; for (uint32 i = 0; fSettings.FindMessage("screen", i, &stored) == B_OK; i++) { + // TODO: should we ignore unnamed settings here completely? int32 score = 0; int32 id; if (stored.FindInt32("id", &id) == B_OK && screen->ID() == id) @@ -286,8 +294,10 @@ && !strcasecmp(name, info.name) && productID == info.product_id) { score += 2; - if (!strcmp(serial, info.serial_number)) + if (!strcmp(serial, info.serial_number)) { + exactMatch = true; score += 2; + } if (info.produced.year == year && info.produced.week == week) score++; } else @@ -302,7 +312,8 @@ } if (bestIndex >= 0) { - fSettings.RemoveData("screen", bestIndex); + if (exactMatch) + fSettings.RemoveData("screen", bestIndex); return B_OK; } Modified: haiku/trunk/src/servers/app/VirtualScreen.h =================================================================== --- haiku/trunk/src/servers/app/VirtualScreen.h 2007-10-21 10:58:24 UTC (rev 22631) +++ haiku/trunk/src/servers/app/VirtualScreen.h 2007-10-21 11:00:30 UTC (rev 22632) @@ -50,7 +50,7 @@ int32 CountScreens() const; private: - status_t _FindConfiguration(Screen* screen, + status_t _GetConfiguration(Screen* screen, BMessage& settings); void _Reset(); From julun at mail.berlios.de Sun Oct 21 14:40:58 2007 From: julun at mail.berlios.de (julun at BerliOS) Date: Sun, 21 Oct 2007 14:40:58 +0200 Subject: [Haiku-commits] r22633 - haiku/trunk/src/preferences/time Message-ID: <200710211240.l9LCewrh030767@sheep.berlios.de> Author: julun Date: 2007-10-21 14:40:57 +0200 (Sun, 21 Oct 2007) New Revision: 22633 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22633&view=rev Modified: haiku/trunk/src/preferences/time/AnalogClock.cpp haiku/trunk/src/preferences/time/AnalogClock.h haiku/trunk/src/preferences/time/BaseView.cpp haiku/trunk/src/preferences/time/DateTimeView.cpp haiku/trunk/src/preferences/time/DateTimeView.h haiku/trunk/src/preferences/time/TZDisplay.cpp haiku/trunk/src/preferences/time/TimeWindow.cpp haiku/trunk/src/preferences/time/TimeWindow.h haiku/trunk/src/preferences/time/ZoneView.cpp haiku/trunk/src/preferences/time/ZoneView.h Log: * code cleanup, small refactoring * make the panel font sensitve within the possible plain font range Modified: haiku/trunk/src/preferences/time/AnalogClock.cpp =================================================================== --- haiku/trunk/src/preferences/time/AnalogClock.cpp 2007-10-21 11:00:30 UTC (rev 22632) +++ haiku/trunk/src/preferences/time/AnalogClock.cpp 2007-10-21 12:40:57 UTC (rev 22633) @@ -183,8 +183,8 @@ // #pragma mark - -TAnalogClock::TAnalogClock(BRect frame, const char *name, uint32 resizeMask, uint32 flags) - : BView(frame, name, resizeMask, flags | B_DRAW_ON_CHILDREN), +TAnalogClock::TAnalogClock(BRect frame, const char *name) + : BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW | B_DRAW_ON_CHILDREN), fBitmap(NULL), fClock(NULL) { Modified: haiku/trunk/src/preferences/time/AnalogClock.h =================================================================== --- haiku/trunk/src/preferences/time/AnalogClock.h 2007-10-21 11:00:30 UTC (rev 22632) +++ haiku/trunk/src/preferences/time/AnalogClock.h 2007-10-21 12:40:57 UTC (rev 22633) @@ -19,8 +19,7 @@ class TAnalogClock : public BView { public: - TAnalogClock(BRect frame, const char *name, - uint32 resizeMask, uint32 flags); + TAnalogClock(BRect frame, const char *name); virtual ~TAnalogClock(); virtual void AttachedToWindow(); Modified: haiku/trunk/src/preferences/time/BaseView.cpp =================================================================== --- haiku/trunk/src/preferences/time/BaseView.cpp 2007-10-21 11:00:30 UTC (rev 22632) +++ haiku/trunk/src/preferences/time/BaseView.cpp 2007-10-21 12:40:57 UTC (rev 22633) @@ -16,7 +16,7 @@ TTimeBaseView::TTimeBaseView(BRect frame, const char *name) - : BView(frame, name, B_FOLLOW_ALL_SIDES, B_PULSE_NEEDED), + : BView(frame, name, B_FOLLOW_NONE, B_PULSE_NEEDED), fMessage(H_TIME_UPDATE) { } Modified: haiku/trunk/src/preferences/time/DateTimeView.cpp =================================================================== --- haiku/trunk/src/preferences/time/DateTimeView.cpp 2007-10-21 11:00:30 UTC (rev 22632) +++ haiku/trunk/src/preferences/time/DateTimeView.cpp 2007-10-21 12:40:57 UTC (rev 22633) @@ -27,9 +27,6 @@ #include -#include - - #ifdef HAIKU_TARGET_PLATFORM_HAIKU #include #else @@ -39,12 +36,13 @@ DateTimeView::DateTimeView(BRect frame) - : BView(frame,"Settings", B_FOLLOW_ALL, - B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP), + : BView(frame, "dateTimeView", B_FOLLOW_NONE, B_WILL_DRAW | B_NAVIGABLE_JUMP), fGmtTime(NULL), + fUseGmtTime(false), fInitialized(false) { _ReadRTCSettings(); + _InitView(); } @@ -61,8 +59,11 @@ SetViewColor(Parent()->ViewColor()); if (!fInitialized) { - _InitView(); fInitialized = true; + + fGmtTime->SetTarget(this); + fLocalTime->SetTarget(this); + fCalendarView->SetTarget(this); } } @@ -76,8 +77,8 @@ //draw a separator line BRect bounds(Bounds()); - BPoint start(bounds.Width() / 2.0f + 2.0f, bounds.top + 2.0f); - BPoint end(bounds.Width() / 2.0 + 2.0f, bounds.bottom - 2.0f); + BPoint start(bounds.Width() / 2.0f, bounds.top + 5.0f); + BPoint end(bounds.Width() / 2.0, bounds.bottom - 5.0f); BeginLineArray(2); AddLine(start, end, dark); @@ -118,6 +119,7 @@ } break; case kRTCUpdate: + fUseGmtTime = !fUseGmtTime; _UpdateGmtSettings(); break; @@ -129,94 +131,68 @@ void -DateTimeView::GetPreferredSize(float *width, float *height) -{ - // hardcode in TimeWindow ... - *width = 470.0f; - *height = 227.0f; - - if (fInitialized) { - // we are initialized - *width = Bounds().Width(); - *height = fGmtTime->Frame().bottom; - } -} - - -void DateTimeView::_InitView() { font_height fontHeight; be_plain_font->GetHeight(&fontHeight); - float textHeight = fontHeight.descent + fontHeight.ascent + fontHeight.leading; + float textHeight = fontHeight.descent + fontHeight.ascent + + fontHeight.leading + 6.0; // 6px border // left side - BRect frameLeft(Bounds()); - frameLeft.right = frameLeft.Width() / 2.0; - frameLeft.InsetBy(10.0f, 10.0f); - frameLeft.bottom = frameLeft.top + textHeight + 6.0; + BRect bounds = Bounds(); + bounds.InsetBy(10.0, 10.0); + bounds.top += textHeight + 10.0; - fDateEdit = new TDateEdit(frameLeft, "date_edit", 3); - AddChild(fDateEdit); - - frameLeft.top = fDateEdit->Frame().bottom + 10; - frameLeft.bottom = Bounds().bottom - 10; - - fCalendarView = new BCalendarView(frameLeft, "calendar"); + fCalendarView = new BCalendarView(bounds, "calendar"); fCalendarView->SetWeekNumberHeaderVisible(false); - AddChild(fCalendarView); + fCalendarView->ResizeToPreferred(); fCalendarView->SetSelectionMessage(new BMessage(kDayChanged)); fCalendarView->SetInvocationMessage(new BMessage(kDayChanged)); - fCalendarView->SetTarget(this); - // right side - BRect frameRight(Bounds()); - frameRight.left = frameRight.Width() / 2.0; - frameRight.InsetBy(10.0f, 10.0f); - frameRight.bottom = frameRight.top + textHeight + 6.0; + bounds.top -= textHeight + 10.0; + bounds.bottom = bounds.top + textHeight; + bounds.right = fCalendarView->Frame().right; - fTimeEdit = new TTimeEdit(frameRight, "time_edit", 4); + fDateEdit = new TDateEdit(bounds, "dateEdit", 3); + AddChild(fDateEdit); + AddChild(fCalendarView); + + // right side, 2px extra for separator + bounds.OffsetBy(bounds.Width() + 22.0, 0.0); + fTimeEdit = new TTimeEdit(bounds, "timeEdit", 4); AddChild(fTimeEdit); - frameRight.top = fTimeEdit->Frame().bottom + 10.0; - frameRight.bottom = Bounds().bottom - 10.0; + bounds = fCalendarView->Frame(); + bounds.OffsetBy(bounds.Width() + 22.0, 0.0); - float left = fTimeEdit->Frame().left; - float tmp = MIN(frameRight.Width(), frameRight.Height()); - frameRight.left = left + (fTimeEdit->Bounds().Width() - tmp) / 2.0; - frameRight.bottom = frameRight.top + tmp; - frameRight.right = frameRight.left + tmp; - - fClock = new TAnalogClock(frameRight, "analog clock", B_FOLLOW_NONE, B_WILL_DRAW); + fClock = new TAnalogClock(bounds, "analogClock"); AddChild(fClock); // clock radio buttons - frameRight.left = left; - frameRight.top = fClock->Frame().bottom + 10.0; - BStringView *text = new BStringView(frameRight, "clockis", "Clock set to:"); + bounds.top = fClock->Frame().bottom + 10.0; + BStringView *text = new BStringView(bounds, "clockSetTo", "Clock set to:"); AddChild(text); text->ResizeToPreferred(); - frameRight.left += 10.0f; - frameRight.top = text->Frame().bottom + 5.0; - - fLocalTime = new BRadioButton(frameRight, "local", "Local time", + bounds.left += 10.0f; + bounds.top = text->Frame().bottom; + fLocalTime = new BRadioButton(bounds, "localTime", "Local Time", new BMessage(kRTCUpdate)); AddChild(fLocalTime); fLocalTime->ResizeToPreferred(); - fLocalTime->SetTarget(this); - frameRight.left = fLocalTime->Frame().right +10.0f; - - fGmtTime = new BRadioButton(frameRight, "gmt", "GMT", new BMessage(kRTCUpdate)); + bounds.left = fLocalTime->Frame().right + 10.0; + fGmtTime = new BRadioButton(bounds, "greenwichMeanTime", "GMT", + new BMessage(kRTCUpdate)); AddChild(fGmtTime); fGmtTime->ResizeToPreferred(); - fGmtTime->SetTarget(this); - if (fIsLocalTime) - fLocalTime->SetValue(B_CONTROL_ON); - else + if (fUseGmtTime) fGmtTime->SetValue(B_CONTROL_ON); + else + fLocalTime->SetValue(B_CONTROL_ON); + + ResizeTo(fClock->Frame().right + 10.0, fGmtTime->Frame().bottom + 10.0); } @@ -228,26 +204,18 @@ return; path.Append("RTC_time_settings"); - - BFile file; + BEntry entry(path.Path()); if (entry.Exists()) { - file.SetTo(&entry, B_READ_ONLY); + BFile file(&entry, B_READ_ONLY); if (file.InitCheck() == B_OK) { - char localTime[6]; - file.Read(localTime, 6); - BString text(localTime); - if (text.Compare("local", 4) == 0) - fIsLocalTime = true; - else - fIsLocalTime = false; + char buffer[6]; + file.Read(buffer, 6); + if (strncmp(buffer, "gmt", 3) == 0) + fUseGmtTime = true; } - } else { - // create set to local - fIsLocalTime = true; - file.SetTo(&entry, B_CREATE_FILE | B_READ_WRITE); - file.Write("local", 5); - } + } else + _UpdateGmtSettings(); } @@ -262,10 +230,10 @@ BFile file(path.Path(), B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY); if (file.InitCheck() == B_OK) { - if (fLocalTime->Value() == B_CONTROL_ON) - file.Write("local", 5); - else + if (fUseGmtTime) file.Write("gmt", 3); + else + file.Write("local", 5); } } @@ -288,8 +256,7 @@ entry.GetPath(&path); // take the existing timezone and set it's gmt use - _kern_set_tzfilename(path.Path(), B_PATH_NAME_LENGTH - , fGmtTime->Value() == B_CONTROL_ON); + _kern_set_tzfilename(path.Path(), B_PATH_NAME_LENGTH, fUseGmtTime); } @@ -314,7 +281,7 @@ && message->FindInt32("minute", &minute) == B_OK && message->FindInt32("second", &second) == B_OK) { - fTimeEdit->SetTime(hour, minute, second); fClock->SetTime(hour, minute, second); + fTimeEdit->SetTime(hour, minute, second); } } Modified: haiku/trunk/src/preferences/time/DateTimeView.h =================================================================== --- haiku/trunk/src/preferences/time/DateTimeView.h 2007-10-21 11:00:30 UTC (rev 22632) +++ haiku/trunk/src/preferences/time/DateTimeView.h 2007-10-21 12:40:57 UTC (rev 22633) @@ -29,7 +29,6 @@ virtual void AttachedToWindow(); virtual void Draw(BRect updaterect); virtual void MessageReceived(BMessage *message); - virtual void GetPreferredSize(float *width, float *height); private: void _InitView(); @@ -46,7 +45,7 @@ BCalendarView *fCalendarView; TAnalogClock *fClock; - bool fIsLocalTime; + bool fUseGmtTime; bool fInitialized; }; Modified: haiku/trunk/src/preferences/time/TZDisplay.cpp =================================================================== --- haiku/trunk/src/preferences/time/TZDisplay.cpp 2007-10-21 11:00:30 UTC (rev 22632) +++ haiku/trunk/src/preferences/time/TZDisplay.cpp 2007-10-21 12:40:57 UTC (rev 22633) @@ -19,8 +19,8 @@ { font_height fontHeight; be_plain_font->GetHeight(&fontHeight); - float height = ceil(fontHeight.descent) + ceil(fontHeight.ascent) - + ceil(fontHeight.leading); + float height = ceil(fontHeight.descent + fontHeight.ascent + + fontHeight.leading); return height; } } @@ -51,28 +51,28 @@ void TTZDisplay::ResizeToPreferred() { - float height = _FontHeight(); - ResizeTo(Bounds().Width(), height *2); + ResizeTo(Bounds().Width(), _FontHeight() * 2.0 + 4.0); } void TTZDisplay::Draw(BRect /* updateRect */) { - BRect bounds(Bounds()); SetLowColor(ViewColor()); - FillRect(bounds, B_SOLID_LOW); + + BRect bounds = Bounds(); + FillRect(Bounds(), B_SOLID_LOW); - float height = _FontHeight(); + float fontHeight = _FontHeight(); - BPoint drawpt(bounds.left +2, height /2.0 +1); - DrawString(fLabel.String(), drawpt); + BPoint pt(bounds.left + 2.0, fontHeight / 2.0 + 2.0); + DrawString(fLabel.String(), pt); - drawpt.y += height +2; - DrawString(fText.String(), drawpt); + pt.y += fontHeight; + DrawString(fText.String(), pt); - drawpt.x = bounds.right -be_plain_font->StringWidth(fTime.String()) - 2; - DrawString(fTime.String(), drawpt); + pt.x = bounds.right - StringWidth(fTime.String()) - 2.0; + DrawString(fTime.String(), pt); } Modified: haiku/trunk/src/preferences/time/TimeWindow.cpp =================================================================== --- haiku/trunk/src/preferences/time/TimeWindow.cpp 2007-10-21 11:00:30 UTC (rev 22632) +++ haiku/trunk/src/preferences/time/TimeWindow.cpp 2007-10-21 12:40:57 UTC (rev 22633) @@ -61,7 +61,7 @@ { TimeSettings().SetLeftTop(Frame().LeftTop()); - fBaseView->StopWatchingAll(fTimeZones); + fBaseView->StopWatchingAll(fTimeZoneView); fBaseView->StopWatchingAll(fDateTimeView); be_app->PostMessage(B_QUIT_REQUESTED); @@ -75,40 +75,35 @@ { SetPulseRate(500000); - BRect bounds(Bounds()); + fDateTimeView = new DateTimeView(Bounds()); - fBaseView = new TTimeBaseView(bounds, "background view"); + BRect bounds = fDateTimeView->Bounds(); + fTimeZoneView = new TimeZoneView(bounds); + + fBaseView = new TTimeBaseView(bounds, "baseView"); AddChild(fBaseView); - bounds.top = 9; - BTabView *tabview = new BTabView(bounds, "tab_view"); - - bounds = tabview->Bounds(); - bounds.InsetBy(4, 6); - bounds.bottom -= tabview->TabHeight(); - - fDateTimeView = new DateTimeView(bounds); fBaseView->StartWatchingAll(fDateTimeView); + fBaseView->StartWatchingAll(fTimeZoneView); + bounds.OffsetBy(10.0, 10.0); + BTabView *tabView = new BTabView(bounds.InsetByCopy(-5.0, -5.0), + "tabView" , B_WIDTH_AS_USUAL, B_FOLLOW_NONE); + BTab *tab = new BTab(); - tabview->AddTab(fDateTimeView, tab); + tabView->AddTab(fDateTimeView, tab); tab->SetLabel("Date & Time"); - fTimeZones = new TZoneView(bounds); - fBaseView->StartWatchingAll(fTimeZones); - tab = new BTab(); - tabview->AddTab(fTimeZones, tab); - tab->SetLabel("Time Zone"); + tabView->AddTab(fTimeZoneView, tab); + tab->SetLabel("Timezone"); - fBaseView->AddChild(tabview); + fBaseView->AddChild(tabView); + tabView->ResizeBy(0.0, tabView->TabHeight()); + fBaseView->ResizeTo(tabView->Bounds().Width() + 10.0, + tabView->Bounds().Height() + 10.0); - float width; - float height; - fDateTimeView->GetPreferredSize(&width, &height); - - // width/ height from DateTimeView + all InsetBy etc.. - ResizeTo(width +10, height + tabview->TabHeight() +25); + ResizeTo(fBaseView->Bounds().Width(), fBaseView->Bounds().Height()); } Modified: haiku/trunk/src/preferences/time/TimeWindow.h =================================================================== --- haiku/trunk/src/preferences/time/TimeWindow.h 2007-10-21 11:00:30 UTC (rev 22632) +++ haiku/trunk/src/preferences/time/TimeWindow.h 2007-10-21 12:40:57 UTC (rev 22633) @@ -17,7 +17,7 @@ class BMessage; class DateTimeView; class TTimeBaseView; -class TZoneView; +class TimeZoneView; class TTimeWindow : public BWindow { @@ -35,7 +35,7 @@ private: TTimeBaseView *fBaseView; DateTimeView *fDateTimeView; - TZoneView *fTimeZones; + TimeZoneView *fTimeZoneView; }; #endif // TIME_WINDOW_H Modified: haiku/trunk/src/preferences/time/ZoneView.cpp =================================================================== --- haiku/trunk/src/preferences/time/ZoneView.cpp 2007-10-21 11:00:30 UTC (rev 22632) +++ haiku/trunk/src/preferences/time/ZoneView.cpp 2007-10-21 12:40:57 UTC (rev 22633) @@ -58,32 +58,33 @@ }; -TZoneView::TZoneView(BRect frame) - : BView(frame, B_EMPTY_STRING, B_FOLLOW_ALL, B_WILL_DRAW | B_NAVIGABLE_JUMP), - fNotInitialized(true) +TimeZoneView::TimeZoneView(BRect frame) + : BView(frame, "timeZoneView", B_FOLLOW_NONE, B_WILL_DRAW | B_NAVIGABLE_JUMP), + fInitialized(false) { ReadTimeZoneLink(); InitView(); } -TZoneView::~TZoneView() +TimeZoneView::~TimeZoneView() { } void -TZoneView::AttachedToWindow() +TimeZoneView::AttachedToWindow() { if (Parent()) SetViewColor(Parent()->ViewColor()); - if (fNotInitialized) { - // stupid hack - fRegionPopUp->SetTargetForItems(this); + if (!fInitialized) { + fInitialized = true; + fSetZone->SetTarget(this); fCityList->SetTarget(this); - + fRegionPopUp->SetTargetForItems(this); + // update displays BPath parent; fCurrentZone.GetParent(&parent); @@ -92,15 +93,13 @@ fCityList->Select(czone); fCurrent->SetText(((TZoneItem *)fCityList->ItemAt(czone))->Text()); } - fNotInitialized = false; - ResizeTo(Bounds().Width(), Bounds().Height() +40); } fCityList->ScrollToSelection(); } void -TZoneView::MessageReceived(BMessage *message) +TimeZoneView::MessageReceived(BMessage *message) { int32 change; switch(message->what) { @@ -135,15 +134,8 @@ } -const char* -TZoneView::TimeZone() -{ - return fCurrent->Text(); -} - - void -TZoneView::UpdateDateTime(BMessage *message) +TimeZoneView::UpdateDateTime(BMessage *message) { int32 hour; int32 minute; @@ -165,58 +157,53 @@ void -TZoneView::InitView() +TimeZoneView::InitView() { - font_height fontHeight; - be_plain_font->GetHeight(&fontHeight); - float textHeight = fontHeight.descent + fontHeight.ascent + fontHeight.leading; - // Zone menu - fRegionPopUp = new BPopUpMenu(B_EMPTY_STRING, true, true, B_ITEMS_IN_COLUMN); + fRegionPopUp = new BPopUpMenu("", true, true, B_ITEMS_IN_COLUMN); BuildRegionMenu(); // left side BRect frameLeft(Bounds()); - frameLeft.right = frameLeft.Width() / 2; + frameLeft.right = frameLeft.Width() / 2.0; frameLeft.InsetBy(10.0f, 10.0f); BMenuField *menuField = new BMenuField(frameLeft, "regions", NULL, fRegionPopUp, false); AddChild(menuField); menuField->ResizeToPreferred(); - frameLeft.top = menuField->Frame().bottom +10; + frameLeft.top = menuField->Frame().bottom + 10.0; frameLeft.right -= B_V_SCROLL_BAR_WIDTH; // City Listing - fCityList = new BListView(frameLeft, "cityList", B_SINGLE_SELECTION_LIST, - B_FOLLOW_ALL, B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS); + fCityList = new BListView(frameLeft, "cityList", B_SINGLE_SELECTION_LIST); fCityList->SetSelectionMessage(new BMessage(H_CITY_CHANGED)); fCityList->SetInvocationMessage(new BMessage(H_SET_TIME_ZONE)); - BScrollView *scrollList = new BScrollView("scroll_list", fCityList, + BScrollView *scrollList = new BScrollView("scrollList", fCityList, B_FOLLOW_ALL, 0, false, true); AddChild(scrollList); // right side BRect frameRight(Bounds()); - frameRight.left = frameRight.Width() / 2; + frameRight.left = frameRight.Width() / 2.0; frameRight.InsetBy(10.0f, 10.0f); frameRight.top = frameLeft.top; // Time Displays - fCurrent = new TTZDisplay(frameRight, "current", "Current time:"); + fCurrent = new TTZDisplay(frameRight, "currentTime", "Current time:"); AddChild(fCurrent); fCurrent->ResizeToPreferred(); - frameRight.OffsetBy(0, (textHeight) * 3 +10.0); - fPreview = new TTZDisplay(frameRight, "preview", "Preview time:"); + frameRight.top = fCurrent->Frame().bottom + 10.0; + fPreview = new TTZDisplay(frameRight, "previewTime", "Preview time:"); AddChild(fPreview); fPreview->ResizeToPreferred(); // set button - fSetZone = new BButton(frameRight, "set", "Set Timezone", - new BMessage(H_SET_TIME_ZONE), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); + fSetZone = new BButton(frameRight, "setTimeZone", "Set Time Zone", + new BMessage(H_SET_TIME_ZONE)); AddChild(fSetZone); fSetZone->SetEnabled(false); fSetZone->ResizeToPreferred(); @@ -227,7 +214,7 @@ void -TZoneView::BuildRegionMenu() +TimeZoneView::BuildRegionMenu() { BPath path; if (find_directory(B_BEOS_ETC_DIRECTORY, &path) != B_OK) @@ -280,7 +267,7 @@ int32 -TZoneView::FillCityList(const char *area) +TimeZoneView::FillCityList(const char *area) { // clear list int32 count = fCityList->CountItems(); @@ -334,7 +321,7 @@ void -TZoneView::ChangeRegion(BMessage *message) +TimeZoneView::ChangeRegion(BMessage *message) { BString area; message->FindString("region", &area); @@ -344,7 +331,7 @@ void -TZoneView::ReadTimeZoneLink() +TimeZoneView::ReadTimeZoneLink() { BEntry tzLink; @@ -387,7 +374,7 @@ void -TZoneView::SetPreview() +TimeZoneView::SetPreview() { int32 selection = fCityList->CurrentSelection(); if (selection >= 0) { @@ -413,7 +400,7 @@ void -TZoneView::SetCurrent(const char *text) +TimeZoneView::SetCurrent(const char *text) { SetTimeZone(fCurrentZone.Path()); @@ -426,7 +413,7 @@ void -TZoneView::SetTimeZone() +TimeZoneView::SetTimeZone() { /* set time based on supplied timezone. How to do this? 1) replace symlink "timezone" in B_USER_SETTINGS_DIR with a link to the new timezone @@ -486,7 +473,7 @@ void -TZoneView::SetTimeZone(const char *zone) +TimeZoneView::SetTimeZone(const char *zone) { putenv(BString("TZ=").Append(zone).String()); tzset(); Modified: haiku/trunk/src/preferences/time/ZoneView.h =================================================================== --- haiku/trunk/src/preferences/time/ZoneView.h 2007-10-21 11:00:30 UTC (rev 22632) +++ haiku/trunk/src/preferences/time/ZoneView.h 2007-10-21 12:40:57 UTC (rev 22633) @@ -21,15 +21,13 @@ class TTZDisplay; -class TZoneView : public BView { +class TimeZoneView : public BView { public: - TZoneView(BRect frame); - virtual ~TZoneView(); + TimeZoneView(BRect frame); + virtual ~TimeZoneView(); virtual void AttachedToWindow(); virtual void MessageReceived(BMessage *message); - - const char* TimeZone(); private: void UpdateDateTime(BMessage *message); @@ -55,7 +53,7 @@ int32 fHour; int32 fMinute; BPath fCurrentZone; - bool fNotInitialized; + bool fInitialized; }; #endif //Zone_View_H From axeld at mail.berlios.de Sun Oct 21 15:45:47 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sun, 21 Oct 2007 15:45:47 +0200 Subject: [Haiku-commits] r22634 - haiku/trunk/src/tests/add-ons/kernel Message-ID: <200710211345.l9LDjlua001574@sheep.berlios.de> Author: axeld Date: 2007-10-21 15:45:47 +0200 (Sun, 21 Oct 2007) New Revision: 22634 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22634&view=rev Modified: haiku/trunk/src/tests/add-ons/kernel/kernelland_emu.cpp Log: Made our kernel-emu a bit more complete. Modified: haiku/trunk/src/tests/add-ons/kernel/kernelland_emu.cpp =================================================================== --- haiku/trunk/src/tests/add-ons/kernel/kernelland_emu.cpp 2007-10-21 12:40:57 UTC (rev 22633) +++ haiku/trunk/src/tests/add-ons/kernel/kernelland_emu.cpp 2007-10-21 13:45:47 UTC (rev 22634) @@ -697,6 +697,39 @@ } +extern "C" int32 +atomic_test_and_set(vint32 *value, int32 newValue, int32 testAgainst) +{ +#if __INTEL__ + int32 oldValue; + asm volatile("lock; cmpxchg %%ecx, (%%edx)" + : "=a" (oldValue) : "a" (testAgainst), "c" (newValue), "d" (value)); + return oldValue; +#else +#warn "atomic_test_and_set() won't work correctly!" + int32 oldValue = *value; + if (oldValue == testAgainst) + *value = newValue; + + return oldValue; +#endif +} + + +extern "C" int +add_debugger_command(char *name, int (*func)(int, char **), char *desc) +{ + return B_OK; +} + + +extern "C" int +remove_debugger_command(char * name, int (*func)(int, char **)) +{ + return B_OK; +} + + extern "C" void panic(const char *format, ...) { @@ -729,6 +762,19 @@ extern "C" void +kprintf(const char *format,...) +{ + va_list args; + va_start(args, format); + printf("\33[35m"); + vprintf(format, args); + printf("\33[0m"); + fflush(stdout); + va_end(args); +} + + +extern "C" void dump_block(const char *buffer, int size, const char *prefix) { const int DUMPED_BLOCK_SIZE = 16; From axeld at mail.berlios.de Sun Oct 21 15:51:50 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sun, 21 Oct 2007 15:51:50 +0200 Subject: [Haiku-commits] r22635 - haiku/trunk/src/preferences/time Message-ID: <200710211351.l9LDpovF001881@sheep.berlios.de> Author: axeld Date: 2007-10-21 15:51:50 +0200 (Sun, 21 Oct 2007) New Revision: 22635 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22635&view=rev Modified: haiku/trunk/src/preferences/time/DateTimeView.cpp Log: Fixed build under BeOS. Modified: haiku/trunk/src/preferences/time/DateTimeView.cpp =================================================================== --- haiku/trunk/src/preferences/time/DateTimeView.cpp 2007-10-21 13:45:47 UTC (rev 22634) +++ haiku/trunk/src/preferences/time/DateTimeView.cpp 2007-10-21 13:51:50 UTC (rev 22635) @@ -28,10 +28,10 @@ #ifdef HAIKU_TARGET_PLATFORM_HAIKU -#include +# include #else -void _kset_tzfilename_(const char *name, size_t length, bool isGMT); -#define _kern_set_tzfilename _kset_tzfilename_ +extern "C" void _kset_tzfilename_(const char *name, size_t length, bool isGMT); +# define _kern_set_tzfilename _kset_tzfilename_ #endif From HOST.HAIKU at gmx.de Sun Oct 21 16:30:33 2007 From: HOST.HAIKU at gmx.de (Julun) Date: Sun, 21 Oct 2007 16:30:33 +0200 Subject: [Haiku-commits] r22635 - haiku/trunk/src/preferences/time In-Reply-To: <200710211351.l9LDpovF001881@sheep.berlios.de> References: <200710211351.l9LDpovF001881@sheep.berlios.de> Message-ID: <1192977033.7465.6.camel@ubuntu> Hi, On Sun, 2007-10-21 at 15:51 +0200, axeld at BerliOS wrote: > Author: axeld > Date: 2007-10-21 15:51:50 +0200 (Sun, 21 Oct 2007) > New Revision: 22635 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22635&view=rev > > Modified: > haiku/trunk/src/preferences/time/DateTimeView.cpp > Log: > Fixed build under BeOS. Thanks :) i think i found the missing kernel call on R5 to read the timezone file, but while doing strings on time prefs i only got the function name. does someone know the arguments to pass to _kget_tzfilename_ or where to look for them? thx, Julun From stippi at mail.berlios.de Sun Oct 21 17:19:25 2007 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Sun, 21 Oct 2007 17:19:25 +0200 Subject: [Haiku-commits] r22636 - haiku/trunk/headers/private/mail Message-ID: <200710211519.l9LFJPRU006640@sheep.berlios.de> Author: stippi Date: 2007-10-21 17:19:25 +0200 (Sun, 21 Oct 2007) New Revision: 22636 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22636&view=rev Modified: haiku/trunk/headers/private/mail/NodeMessage.h Log: * part of libbe_test build fix... why is the _IMPEXP stuff there in the first place? Is it even needed? Modified: haiku/trunk/headers/private/mail/NodeMessage.h =================================================================== --- haiku/trunk/headers/private/mail/NodeMessage.h 2007-10-21 13:51:50 UTC (rev 22635) +++ haiku/trunk/headers/private/mail/NodeMessage.h 2007-10-21 15:19:25 UTC (rev 22636) @@ -23,7 +23,7 @@ #include #include -#if defined(HAIKU_TARGET_PLATFORM_DANO) || defined(HAIKU_TARGET_PLATFORM_HAIKU) +#if defined(HAIKU_TARGET_PLATFORM_DANO) || defined(HAIKU_TARGET_PLATFORM_HAIKU) || defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) #define _IMPEXP_MAIL #endif From stippi at mail.berlios.de Sun Oct 21 17:48:12 2007 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Sun, 21 Oct 2007 17:48:12 +0200 Subject: [Haiku-commits] r22637 - haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests Message-ID: <200710211548.l9LFmCgB008158@sheep.berlios.de> Author: stippi Date: 2007-10-21 17:48:12 +0200 (Sun, 21 Oct 2007) New Revision: 22637 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22637&view=rev Modified: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/ControlTest.h Log: * fix build in test environment Modified: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/ControlTest.h =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/ControlTest.h 2007-10-21 15:19:25 UTC (rev 22636) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/ControlTest.h 2007-10-21 15:48:12 UTC (rev 22637) @@ -10,6 +10,7 @@ class BButton; +class BControl; class BFont; class LabeledCheckBox; class View; From stippi at mail.berlios.de Sun Oct 21 17:52:56 2007 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Sun, 21 Oct 2007 17:52:56 +0200 Subject: [Haiku-commits] r22638 - haiku/trunk/src/apps/clock Message-ID: <200710211552.l9LFquEJ008478@sheep.berlios.de> Author: stippi Date: 2007-10-21 17:52:56 +0200 (Sun, 21 Oct 2007) New Revision: 22638 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22638&view=rev Modified: haiku/trunk/src/apps/clock/cl_wind.cpp Log: * fix build in test environment Modified: haiku/trunk/src/apps/clock/cl_wind.cpp =================================================================== --- haiku/trunk/src/apps/clock/cl_wind.cpp 2007-10-21 15:48:12 UTC (rev 22637) +++ haiku/trunk/src/apps/clock/cl_wind.cpp 2007-10-21 15:52:56 UTC (rev 22638) @@ -13,6 +13,7 @@ #include +#include #include From stippi at mail.berlios.de Sun Oct 21 17:54:04 2007 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Sun, 21 Oct 2007 17:54:04 +0200 Subject: [Haiku-commits] r22639 - haiku/trunk/headers/build Message-ID: <200710211554.l9LFs4LR008541@sheep.berlios.de> Author: stippi Date: 2007-10-21 17:54:04 +0200 (Sun, 21 Oct 2007) New Revision: 22639 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22639&view=rev Modified: haiku/trunk/headers/build/HaikuBuildCompatibility.h Log: * added more stuff which was needed to get the test environment to compile again Modified: haiku/trunk/headers/build/HaikuBuildCompatibility.h =================================================================== --- haiku/trunk/headers/build/HaikuBuildCompatibility.h 2007-10-21 15:52:56 UTC (rev 22638) +++ haiku/trunk/headers/build/HaikuBuildCompatibility.h 2007-10-21 15:54:04 UTC (rev 22639) @@ -52,7 +52,31 @@ __attribute__((format(__printf__, _format_, _args_))) #endif +// BeOS version of BeBuild.h defines this +#define _IMPEXP_ROOT __declspec(dllimport) +#define _IMPEXP_BE __declspec(dllimport) +#define _IMPEXP_MEDIA __declspec(dllimport) +#define _IMPEXP_TRACKER __declspec(dllimport) +#define _IMPEXP_TRANSLATION __declspec(dllimport) +#define _IMPEXP_DEVICE __declspec(dllimport) + #ifdef __cplusplus +class BBuffer; +class BBufferConsumer; +class BBufferGroup; +class BContinuousParameter; +class BControllable; +class BFileInterface; +class BParameterWeb; +class BTextView; +class BTranslator; +class BTimeSource; +class BRegion; +struct entry_ref; +struct media_node; +#endif + +#ifdef __cplusplus extern "C" { #endif From stippi at mail.berlios.de Sun Oct 21 17:55:53 2007 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Sun, 21 Oct 2007 17:55:53 +0200 Subject: [Haiku-commits] r22640 - haiku/trunk/src/tests/servers/app Message-ID: <200710211555.l9LFtrln008641@sheep.berlios.de> Author: stippi Date: 2007-10-21 17:55:53 +0200 (Sun, 21 Oct 2007) New Revision: 22640 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22640&view=rev Modified: haiku/trunk/src/tests/servers/app/Jamfile Log: * we don't actually need the AccelerantHWInterface in the test environment, therefor we don't need to worry about the extended Accelerant interface Modified: haiku/trunk/src/tests/servers/app/Jamfile =================================================================== --- haiku/trunk/src/tests/servers/app/Jamfile 2007-10-21 15:54:04 UTC (rev 22639) +++ haiku/trunk/src/tests/servers/app/Jamfile 2007-10-21 15:55:53 UTC (rev 22640) @@ -116,8 +116,8 @@ ServerWindow.cpp # DrawingEngine Classes - AccelerantBuffer.cpp - AccelerantHWInterface.cpp +# AccelerantBuffer.cpp +# AccelerantHWInterface.cpp BitmapBuffer.cpp drawing_support.cpp DrawingEngine.cpp From korli at users.berlios.de Sun Oct 21 19:02:43 2007 From: korli at users.berlios.de (=?ISO-8859-1?Q?J=E9r=F4me_Duval?=) Date: Sun, 21 Oct 2007 19:02:43 +0200 Subject: [Haiku-commits] r22635 - haiku/trunk/src/preferences/time In-Reply-To: <1192977033.7465.6.camel@ubuntu> References: <200710211351.l9LDpovF001881@sheep.berlios.de> <1192977033.7465.6.camel@ubuntu> Message-ID: 2007/10/21, Julun : > someone know the arguments to pass to _kget_tzfilename_ or where to look > for them? > I would think the same as for ours : status_t _user_get_tzfilename(char *filename, size_t length, bool *_isGMT) Bye, J?r?me From ingo_weinhold at gmx.de Sun Oct 21 19:53:11 2007 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Sun, 21 Oct 2007 19:53:11 +0200 Subject: [Haiku-commits] r22636 - haiku/trunk/headers/private/mail In-Reply-To: <200710211519.l9LFJPRU006640@sheep.berlios.de> References: <200710211519.l9LFJPRU006640@sheep.berlios.de> Message-ID: <20071021195311.6179.1@graete.1192972911.fake> On 2007-10-21 at 17:19:25 [+0200], stippi at BerliOS wrote: > Author: stippi > Date: 2007-10-21 17:19:25 +0200 (Sun, 21 Oct 2007) > New Revision: 22636 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22636&view=rev > > Modified: > haiku/trunk/headers/private/mail/NodeMessage.h > Log: > * part of libbe_test build fix... why is the _IMPEXP stuff there in the > first place? Is it even needed? Nope, it's just legacy. CU, Ingo From oruizdorantes at mail.berlios.de Sun Oct 21 19:56:01 2007 From: oruizdorantes at mail.berlios.de (oruizdorantes at BerliOS) Date: Sun, 21 Oct 2007 19:56:01 +0200 Subject: [Haiku-commits] r22641 - in haiku/trunk/headers/os: . bluetooth Message-ID: <200710211756.l9LHu1Dh000337@sheep.berlios.de> Author: oruizdorantes Date: 2007-10-21 19:56:01 +0200 (Sun, 21 Oct 2007) New Revision: 22641 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22641&view=rev Added: haiku/trunk/headers/os/bluetooth/ haiku/trunk/headers/os/bluetooth/DeviceClass.h haiku/trunk/headers/os/bluetooth/LocalDevice.h haiku/trunk/headers/os/bluetooth/bdaddrUtils.h haiku/trunk/headers/os/bluetooth/bluetooth.h Log: Headers for the bluetooth kit, based in the Motorola JSR82 API Added: haiku/trunk/headers/os/bluetooth/DeviceClass.h =================================================================== --- haiku/trunk/headers/os/bluetooth/DeviceClass.h 2007-10-21 15:55:53 UTC (rev 22640) +++ haiku/trunk/headers/os/bluetooth/DeviceClass.h 2007-10-21 17:56:01 UTC (rev 22641) @@ -0,0 +1,47 @@ +/* + * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#ifndef _DEVICE_CLASS_H +#define _DEVICE_CLASS_H + +#include + +namespace Bluetooth { + + class DeviceClass { + + public: + DeviceClass(int record) { + this->record = record; + } + + int getServiceClasses() { + return (record & 0x00FFE000) >> 13; + } + + int getMajorDeviceClass() { + return (record & 0x00001F00) >> 8; + } + + void getMajorDeviceClass(BString* str) { + + } + + int getMinorDeviceClass() { + return (record & 0x000000FF) >> 2; + } + + void getMinorDeviceClass(BString* str) { + + } + + private: + int record; + }; +} + +#endif Added: haiku/trunk/headers/os/bluetooth/LocalDevice.h =================================================================== --- haiku/trunk/headers/os/bluetooth/LocalDevice.h 2007-10-21 15:55:53 UTC (rev 22640) +++ haiku/trunk/headers/os/bluetooth/LocalDevice.h 2007-10-21 17:56:01 UTC (rev 22641) @@ -0,0 +1,49 @@ +/* + * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#ifndef _LOCAL_DEVICE_H +#define _LOCAL_DEVICE_H + +#include +#include + +#include + +namespace Bluetooth { + + class DiscoveryAgent; + + class LocalDevice { + + public: + /* Possible throwing */ + static LocalDevice* getLocalDevice(); + static LocalDevice* getLocalDevice(uint8 dev); + static LocalDevice* getLocalDevice(bdaddr_t bdaddr); + + DiscoveryAgent* getDiscoveryAgent(); + BString getFriendlyName(); + DeviceClass getDeviceClass(); + /* Possible throwing */ + bool setDiscoverable(int mode); + + BString getProperty(const char* property); + void getProperty(const char* property, uint32* value); + + int getDiscoverable(); + BString getBluetoothAddress(); +/* + ServiceRecord getRecord(Connection notifier); + void updateRecord(ServiceRecord srvRecord); +*/ + private: + LocalDevice(); + }; + +} + +#endif Added: haiku/trunk/headers/os/bluetooth/bdaddrUtils.h =================================================================== --- haiku/trunk/headers/os/bluetooth/bdaddrUtils.h 2007-10-21 15:55:53 UTC (rev 22640) +++ haiku/trunk/headers/os/bluetooth/bdaddrUtils.h 2007-10-21 17:56:01 UTC (rev 22641) @@ -0,0 +1,41 @@ +/* + * Copyright 2007 Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + */ + +#ifndef _BDADDR_UTILS_H +#define _BDADDR_UTILS_H + + +namespace Bluetooth { + + class bdaddrUtils { + + public: + static inline bdaddr_t nullAddress() { + + return ((bdaddr_t) {{0, 0, 0, 0, 0, 0}}); + } + static inline bdaddr_t localAddress() { + + return ((bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}}); + } + + static inline bdaddr_t broadcastAddress() { + + return ((bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}); + } + + static const char* ToString(bdaddr_t bdaddr) { + static char str[12]; + + return str; + } + + }; +} + +#endif Added: haiku/trunk/headers/os/bluetooth/bluetooth.h =================================================================== --- haiku/trunk/headers/os/bluetooth/bluetooth.h 2007-10-21 15:55:53 UTC (rev 22640) +++ haiku/trunk/headers/os/bluetooth/bluetooth.h 2007-10-21 17:56:01 UTC (rev 22641) @@ -0,0 +1,38 @@ +/* + * Copyright 2007 Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + */ + +#ifndef _BLUETOOTH_H +#define _BLUETOOTH_H + +#include + +/* Bluetooth version */ +#define BLUETOOTH_1_1B 0 +#define BLUETOOTH_1_1 1 +#define BLUETOOTH_1_2 2 +#define BLUETOOTH_2_0 3 + +#define BLUETOOTH_VERSION BLUETOOTH_2_0 + + +/* Bluetooth common types */ + +/* BD Address */ +typedef struct { + uint8 b[6]; +} __attribute__((packed)) bdaddr_t; + +/* 128 integer type needed for SDP */ +struct int128 { + int8 b[16]; +}; +typedef struct int128 int128; +typedef struct int128 uint128; + + +#endif From oruizdorantes at mail.berlios.de Sun Oct 21 19:58:38 2007 From: oruizdorantes at mail.berlios.de (oruizdorantes at BerliOS) Date: Sun, 21 Oct 2007 19:58:38 +0200 Subject: [Haiku-commits] r22642 - in haiku/trunk/src/kits: . bluetooth Message-ID: <200710211758.l9LHwcSV000411@sheep.berlios.de> Author: oruizdorantes Date: 2007-10-21 19:58:38 +0200 (Sun, 21 Oct 2007) New Revision: 22642 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22642&view=rev Added: haiku/trunk/src/kits/bluetooth/ haiku/trunk/src/kits/bluetooth/Jamfile haiku/trunk/src/kits/bluetooth/LocalDevice.cpp Modified: haiku/trunk/src/kits/Jamfile Log: Dummy implementation of the LocalDevice class Modified: haiku/trunk/src/kits/Jamfile =================================================================== --- haiku/trunk/src/kits/Jamfile 2007-10-21 17:56:01 UTC (rev 22641) +++ haiku/trunk/src/kits/Jamfile 2007-10-21 17:58:38 UTC (rev 22642) @@ -82,6 +82,7 @@ SubInclude HAIKU_TOP src kits app ; +SubInclude HAIKU_TOP src kits bluetooth ; SubInclude HAIKU_TOP src kits debug ; SubInclude HAIKU_TOP src kits device ; SubInclude HAIKU_TOP src kits game ; Added: haiku/trunk/src/kits/bluetooth/Jamfile =================================================================== --- haiku/trunk/src/kits/bluetooth/Jamfile 2007-10-21 17:56:01 UTC (rev 22641) +++ haiku/trunk/src/kits/bluetooth/Jamfile 2007-10-21 17:58:38 UTC (rev 22642) @@ -0,0 +1,6 @@ +SubDir HAIKU_TOP src kits bluetooth ; + +SharedLibrary libbluetooth.so : + LocalDevice.cpp + : be +; Added: haiku/trunk/src/kits/bluetooth/LocalDevice.cpp =================================================================== --- haiku/trunk/src/kits/bluetooth/LocalDevice.cpp 2007-10-21 17:56:01 UTC (rev 22641) +++ haiku/trunk/src/kits/bluetooth/LocalDevice.cpp 2007-10-21 17:58:38 UTC (rev 22642) @@ -0,0 +1,113 @@ +/* + * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + + +#include +#include + +namespace Bluetooth { + + + LocalDevice* + LocalDevice::getLocalDevice() { + + return NULL; + + } + + + LocalDevice* + LocalDevice::getLocalDevice(uint8 dev) { + + return NULL; + + } + + + LocalDevice* + LocalDevice::getLocalDevice(bdaddr_t bdaddr){ + + return NULL; + + } + + + DiscoveryAgent* + LocalDevice::getDiscoveryAgent() { + + return NULL; + } + + + BString + LocalDevice::getFriendlyName() { + + return NULL; + } + + + DeviceClass + LocalDevice::getDeviceClass() { + + return NULL; + } + + + bool + LocalDevice::setDiscoverable(int mode) { + + return false; + } + + + BString + LocalDevice::getProperty(const char* property) { + + return NULL; + + } + + + void + LocalDevice::getProperty(const char* property, uint32* value) { + + *value = 0; + + } + + + int + LocalDevice::getDiscoverable() { + + return 0; + } + + + BString + LocalDevice::getBluetoothAddress() { + + return NULL; + } + + + /* + ServiceRecord + LocalDevice::getRecord(Connection notifier) { + + } + + void + LocalDevice::updateRecord(ServiceRecord srvRecord) { + + } + */ + LocalDevice::LocalDevice() { + + } + + +} From axeld at pinc-software.de Sun Oct 21 21:52:16 2007 From: axeld at pinc-software.de (Axel =?iso-8859-15?q?D=F6rfler?=) Date: Sun, 21 Oct 2007 21:52:16 +0200 CEST Subject: [Haiku-commits] r22642 - in haiku/trunk/src/kits: . bluetooth In-Reply-To: <200710211758.l9LHwcSV000411@sheep.berlios.de> Message-ID: <24177754732-BeMail@zon> oruizdorantes at BerliOS wrote: > +namespace Bluetooth { > + > + > + LocalDevice* > + LocalDevice::getLocalDevice() { Welcome Oliver! Nice to see you starting to work in the repository now! :-) Anyway, would you mind having a look at our coding style? - we do not indent because of a namespace - brackets of functions/methods go to the next line - method names start with upper case Bye, Axel. From axeld at mail.berlios.de Sun Oct 21 22:10:45 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sun, 21 Oct 2007 22:10:45 +0200 Subject: [Haiku-commits] r22643 - in haiku/trunk: headers/os/drivers headers/posix headers/posix/netinet headers/posix/sys headers/private/net src/add-ons/kernel/network/protocols/tcp src/add-ons/kernel/network/socket src/add-ons/kernel/network/stack src/kits/network src/kits/network/dns/dst src/kits/network/dns/inet src/kits/network/dns/irs src/kits/network/dns/resolv src/servers/net Message-ID: <200710212010.l9LKAjsD007517@sheep.berlios.de> Author: axeld Date: 2007-10-21 22:10:43 +0200 (Sun, 21 Oct 2007) New Revision: 22643 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22643&view=rev Modified: haiku/trunk/headers/os/drivers/socket_interface.h haiku/trunk/headers/posix/netinet/in.h haiku/trunk/headers/posix/stdint.h haiku/trunk/headers/posix/sys/socket.h haiku/trunk/headers/private/net/ProtocolUtilities.h haiku/trunk/headers/private/net/net_socket.h haiku/trunk/headers/private/net/net_stack.h haiku/trunk/src/add-ons/kernel/network/protocols/tcp/EndpointManager.cpp haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.cpp haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.h haiku/trunk/src/add-ons/kernel/network/socket/socket.cpp haiku/trunk/src/add-ons/kernel/network/stack/net_socket.cpp haiku/trunk/src/add-ons/kernel/network/stack/utility.cpp haiku/trunk/src/kits/network/dns/dst/dst_api.c haiku/trunk/src/kits/network/dns/dst/support.c haiku/trunk/src/kits/network/dns/inet/inet_addr.c haiku/trunk/src/kits/network/dns/inet/inet_ntop.c haiku/trunk/src/kits/network/dns/irs/getnameinfo.c haiku/trunk/src/kits/network/dns/resolv/res_debug.c haiku/trunk/src/kits/network/socket.cpp haiku/trunk/src/servers/net/DHCPClient.cpp Log: * int32_t, uint32_t are now of type "int", and no longer of type "long". This should help to reduce the number of warnings imported code will throw during compilation (helps a lot with tcpdump, for example). * Since long is 64 bit on 64 bit platforms, we might want to think about doing that change for the Haiku types int32 and uint32 as well. * Fixed several occurences of hidden type problems. * Fixed build of the stack and TCP under BeOS. * Fixed incorrect typedef in socket_interface.h. * Minor cleanup. Modified: haiku/trunk/headers/os/drivers/socket_interface.h =================================================================== --- haiku/trunk/headers/os/drivers/socket_interface.h 2007-10-21 17:58:38 UTC (rev 22642) +++ haiku/trunk/headers/os/drivers/socket_interface.h 2007-10-21 20:10:43 UTC (rev 22643) @@ -14,7 +14,7 @@ #define B_SOCKET_MODULE_NAME "network/socket/v1" -typedef struct socket_module_info { +struct socket_module_info { struct module_info info; int (*accept)(int socket, struct sockaddr *address, socklen_t *_addressLength); Modified: haiku/trunk/headers/posix/netinet/in.h =================================================================== --- haiku/trunk/headers/posix/netinet/in.h 2007-10-21 17:58:38 UTC (rev 22642) +++ haiku/trunk/headers/posix/netinet/in.h 2007-10-21 20:10:43 UTC (rev 22643) @@ -22,7 +22,8 @@ * and we are not allowed to import all the BeOS types here. */ #ifndef htonl - extern uint32_t __swap_int32(uint32_t); /* private */ +// extern uint32_t __swap_int32(uint32_t); /* private */ + extern unsigned long __swap_int32(unsigned long); /* private */ extern uint16_t __swap_int16(uint16_t); /* private */ #if BYTE_ORDER == LITTLE_ENDIAN #define htonl(x) __swap_int32(x) Modified: haiku/trunk/headers/posix/stdint.h =================================================================== --- haiku/trunk/headers/posix/stdint.h 2007-10-21 17:58:38 UTC (rev 22642) +++ haiku/trunk/headers/posix/stdint.h 2007-10-21 20:10:43 UTC (rev 22643) @@ -1,6 +1,7 @@ -/* -** Distributed under the terms of the Haiku License. -*/ +/* + * Copyright 2003-2007, Haiku Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + */ #ifndef _STDINT_H_ #define _STDINT_H_ @@ -27,8 +28,8 @@ #define INT32_MIN (-INT32_MAX-1) #define UINT32_MAX (4294967295UL) -typedef signed long int32_t; -typedef unsigned long uint32_t; +typedef signed int int32_t; +typedef unsigned int uint32_t; #define INT64_MAX (9223372036854775807LL) #define INT64_MIN (-INT64_MAX-1) Modified: haiku/trunk/headers/posix/sys/socket.h =================================================================== --- haiku/trunk/headers/posix/sys/socket.h 2007-10-21 17:58:38 UTC (rev 22642) +++ haiku/trunk/headers/posix/sys/socket.h 2007-10-21 20:10:43 UTC (rev 22643) @@ -83,13 +83,12 @@ uint8_t sa_data[30]; }; -/* this can hold ANY sockaddr we care to throw at it! */ struct sockaddr_storage { - uint8_t ss_len; /* total length */ - uint8_t ss_family; /* address family */ - uint8_t __ss_pad1[6]; /* align to quad */ - uint64_t __ss_pad2; /* force alignment for stupid compilers */ - uint8_t __ss_pad3[112]; /* pad to a total of 128 bytes */ + uint8_t ss_len; /* total length */ + uint8_t ss_family; /* address family */ + uint8_t __ss_pad1[6]; /* align to quad */ + uint64_t __ss_pad2; /* force alignment to 64 bit */ + uint8_t __ss_pad3[112]; /* pad to a total of 128 bytes */ }; struct msghdr { Modified: haiku/trunk/headers/private/net/ProtocolUtilities.h =================================================================== --- haiku/trunk/headers/private/net/ProtocolUtilities.h 2007-10-21 17:58:38 UTC (rev 22642) +++ haiku/trunk/headers/private/net/ProtocolUtilities.h 2007-10-21 20:10:43 UTC (rev 22643) @@ -5,20 +5,21 @@ * Authors: * Hugo Santos, hugosantos at gmail.com */ - #ifndef PROTOCOL_UTILITIES_H #define PROTOCOL_UTILITIES_H + #include +#include #include #include +#include #include #include #include #include -#include class BenaphoreLocking { public: Modified: haiku/trunk/headers/private/net/net_socket.h =================================================================== --- haiku/trunk/headers/private/net/net_socket.h 2007-10-21 17:58:38 UTC (rev 22642) +++ haiku/trunk/headers/private/net/net_socket.h 2007-10-21 20:10:43 UTC (rev 22643) @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku, Inc. All Rights Reserved. + * Copyright 2006-2007, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. */ #ifndef NET_SOCKET_H @@ -9,10 +9,11 @@ #include #include -#include #include +struct selectsync; + #define NET_SOCKET_MODULE_NAME "network/stack/socket/v1" typedef struct net_socket { @@ -42,32 +43,36 @@ struct net_socket_module_info { struct module_info info; - status_t (*open_socket)(int family, int type, int protocol, net_socket **_socket); + status_t (*open_socket)(int family, int type, int protocol, + net_socket **_socket); status_t (*close)(net_socket *socket); status_t (*free)(net_socket *socket); - status_t (*readv)(net_socket *socket, const iovec *vecs, size_t vecCount, - size_t *_length); - status_t (*writev)(net_socket *socket, const iovec *vecs, size_t vecCount, - size_t *_length); - status_t (*control)(net_socket *socket, int32 op, void *data, size_t length); + status_t (*readv)(net_socket *socket, const iovec *vecs, + size_t vecCount, size_t *_length); + status_t (*writev)(net_socket *socket, const iovec *vecs, + size_t vecCount, size_t *_length); + status_t (*control)(net_socket *socket, int32 op, void *data, + size_t length); ssize_t (*read_avail)(net_socket *socket); ssize_t (*send_avail)(net_socket *socket); status_t (*send_data)(net_socket *socket, net_buffer *buffer); - status_t (*receive_data)(net_socket *socket, size_t length, uint32 flags, - net_buffer **_buffer); + status_t (*receive_data)(net_socket *socket, size_t length, + uint32 flags, net_buffer **_buffer); status_t (*get_option)(net_socket *socket, int level, int option, void *value, int *_length); status_t (*set_option)(net_socket *socket, int level, int option, const void *value, int length); - status_t (*get_next_stat)(uint32 *cookie, int family, struct net_stat *stat); + status_t (*get_next_stat)(uint32 *cookie, int family, + struct net_stat *stat); // connections - status_t (*spawn_pending_socket)(net_socket *parent, net_socket **_socket); + status_t (*spawn_pending_socket)(net_socket *parent, + net_socket **_socket); void (*delete_socket)(net_socket *socket); status_t (*dequeue_connected)(net_socket *parent, net_socket **_socket); ssize_t (*count_connected)(net_socket *parent); @@ -75,10 +80,10 @@ status_t (*set_connected)(net_socket *socket); // notifications - status_t (*request_notification)(net_socket *socket, uint8 event, uint32 ref, - selectsync *sync); + status_t (*request_notification)(net_socket *socket, uint8 event, + uint32 ref, struct selectsync *sync); status_t (*cancel_notification)(net_socket *socket, uint8 event, - selectsync *sync); + struct selectsync *sync); status_t (*notify)(net_socket *socket, uint8 event, int32 value); // standard socket API Modified: haiku/trunk/headers/private/net/net_stack.h =================================================================== --- haiku/trunk/headers/private/net/net_stack.h 2007-10-21 17:58:38 UTC (rev 22642) +++ haiku/trunk/headers/private/net/net_stack.h 2007-10-21 20:10:43 UTC (rev 22643) @@ -78,9 +78,10 @@ status_t (*register_domain_receiving_protocol)(int family, int type, const char *moduleName); - status_t (*get_domain_receiving_protocol)(struct net_domain *domain, uint32 type, - struct net_protocol_module_info **_module); - status_t (*put_domain_receiving_protocol)(struct net_domain *domain, uint32 type); + status_t (*get_domain_receiving_protocol)(struct net_domain *domain, + uint32 type, struct net_protocol_module_info **_module); + status_t (*put_domain_receiving_protocol)(struct net_domain *domain, + uint32 type); // devices status_t (*register_device_deframer)(struct net_device *device, @@ -94,33 +95,37 @@ status_t (*unregister_device_handler)(struct net_device *device, int32 type); status_t (*register_device_monitor)(struct net_device *device, - struct net_device_monitor *monitor); + struct net_device_monitor *monitor); status_t (*unregister_device_monitor)(struct net_device *device, - struct net_device_monitor *monitor); + struct net_device_monitor *monitor); status_t (*device_link_changed)(struct net_device *device); status_t (*device_removed)(struct net_device *device); status_t (*device_enqueue_buffer)(struct net_device *device, - struct net_buffer *buffer); + struct net_buffer *buffer); // Utility Functions // notification - status_t (*notify_socket)(struct net_socket *socket, uint8 event, int32 value); + status_t (*notify_socket)(struct net_socket *socket, uint8 event, + int32 value); // checksum uint16 (*checksum)(uint8 *buffer, size_t length); // fifo - status_t (*init_fifo)(struct net_fifo *fifo, const char *name, size_t maxBytes); + status_t (*init_fifo)(struct net_fifo *fifo, const char *name, + size_t maxBytes); void (*uninit_fifo)(struct net_fifo *fifo); - status_t (*fifo_enqueue_buffer)(struct net_fifo *fifo, struct net_buffer *buffer); + status_t (*fifo_enqueue_buffer)(struct net_fifo *fifo, + struct net_buffer *buffer); ssize_t (*fifo_dequeue_buffer)(struct net_fifo *fifo, uint32 flags, bigtime_t timeout, struct net_buffer **_buffer); status_t (*clear_fifo)(struct net_fifo *fifo); - status_t (*fifo_socket_enqueue_buffer)(struct net_fifo *, struct net_socket *, - uint8 event, struct net_buffer *); + status_t (*fifo_socket_enqueue_buffer)(struct net_fifo *fifo, + struct net_socket *socket, uint8 event, + struct net_buffer *buffer); // timer void (*init_timer)(struct net_timer *timer, net_timer_func hook, void *data); Modified: haiku/trunk/src/add-ons/kernel/network/protocols/tcp/EndpointManager.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/tcp/EndpointManager.cpp 2007-10-21 17:58:38 UTC (rev 22642) +++ haiku/trunk/src/add-ons/kernel/network/protocols/tcp/EndpointManager.cpp 2007-10-21 20:10:43 UTC (rev 22643) @@ -9,13 +9,15 @@ #include "EndpointManager.h" -#include "TCPEndpoint.h" +#include + +#include + #include - #include -#include +#include "TCPEndpoint.h" //#define TRACE_ENDPOINT_MANAGER Modified: haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp 2007-10-21 17:58:38 UTC (rev 22642) +++ haiku/trunk/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp 2007-10-21 20:10:43 UTC (rev 22643) @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -196,9 +197,10 @@ status_t status = B_OK; - while (status == B_OK && !atomic_test_and_set(&fCondition, 0, 1)) + while (status == B_OK && !atomic_test_and_set(&fCondition, 0, 1)) { status = acquire_sem_etc(fSem, 1, B_ABSOLUTE_TIMEOUT | B_CAN_INTERRUPT, timeout); + } locker.Lock(); if (status == B_OK && wakeNext) @@ -212,7 +214,13 @@ WaitList::Signal() { atomic_or(&fCondition, 1); +#ifdef __HAIKU__ release_sem_etc(fSem, 1, B_DO_NOT_RESCHEDULE | B_RELEASE_IF_WAITING_ONLY); +#else + int32 count; + if (get_sem_count(fSem, &count) == B_OK && count < 0) + release_sem_etc(fSem, 1, B_DO_NOT_RESCHEDULE); +#endif } Modified: haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.cpp 2007-10-21 17:58:38 UTC (rev 22642) +++ haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.cpp 2007-10-21 20:10:43 UTC (rev 22643) @@ -1,10 +1,11 @@ /* - * Copyright 2006, Haiku, Inc. All Rights Reserved. + * Copyright 2006-2007, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: * Axel D?rfler, axeld at pinc-software.de * Andrew Galante, haiku.galante at gmail.com + * Hugo Santos, hugosantos at gmail.com */ @@ -134,9 +135,9 @@ bump_option(option, length); option->kind = TCP_OPTION_TIMESTAMP; option->length = 10; - option->timestamp.timestamp_value = htonl(segment.timestamp_value); + option->timestamp.value = htonl(segment.timestamp_value); // TSecr is opaque to us, we send it as we received it. - option->timestamp.timestamp_reply = segment.timestamp_reply; + option->timestamp.reply = segment.timestamp_reply; bump_option(option, length); } @@ -307,9 +308,9 @@ case TCP_OPTION_TIMESTAMP: if (option->length == 10 && (size - 10) >= 0) { segment.options |= TCP_HAS_TIMESTAMPS; - segment.timestamp_value = option->timestamp.timestamp_value; + segment.timestamp_value = option->timestamp.value; segment.timestamp_reply = - ntohl(option->timestamp.timestamp_reply); + ntohl(option->timestamp.reply); } break; case TCP_OPTION_SACK_PERMITTED: @@ -386,6 +387,33 @@ #endif +static int +dump_endpoints(int argc, char *argv[]) +{ + EndpointManagerList::Iterator it = sEndpointManagers.GetIterator(); + + while (it.HasNext()) + it.Next()->DumpEndpoints(); + + return 0; +} + + +static int +dump_endpoint(int argc, char *argv[]) +{ + if (argc < 2) { + kprintf("usage: tcp_endpoint [address]\n"); + return 0; + } + + TCPEndpoint *endpoint = (TCPEndpoint *)strtoul(argv[1], NULL, 16); + endpoint->DumpInternalState(); + + return 0; +} + + // #pragma mark - protocol API @@ -674,33 +702,6 @@ } -static int -dump_endpoints(int argc, char *argv[]) -{ - EndpointManagerList::Iterator it = sEndpointManagers.GetIterator(); - - while (it.HasNext()) - it.Next()->DumpEndpoints(); - - return 0; -} - - -static int -dump_endpoint(int argc, char *argv[]) -{ - if (argc < 2) { - kprintf("usage: tcp_endpoint [address]\n"); - return 0; - } - - TCPEndpoint *endpoint = (TCPEndpoint *)strtoul(argv[1], NULL, 16); - endpoint->DumpInternalState(); - - return 0; -} - - // #pragma mark - Modified: haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.h =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.h 2007-10-21 17:58:38 UTC (rev 22642) +++ haiku/trunk/src/add-ons/kernel/network/protocols/tcp/tcp.h 2007-10-21 20:10:43 UTC (rev 22643) @@ -1,9 +1,11 @@ /* - * Copyright 2006, Haiku, Inc. All Rights Reserved. + * Copyright 2006-2007, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: + * Axel D?rfler, axeld at pinc-software.de * Andrew Galante, haiku.galante at gmail.com + * Hugo Santos, hugosantos at gmail.com */ #ifndef TCP_H #define TCP_H @@ -115,13 +117,13 @@ uint8 kind; uint8 length; union { - uint8 window_shift; - uint16 max_segment_size; + uint8 window_shift; + uint16 max_segment_size; struct { - uint32 timestamp_value; - uint32 timestamp_reply; - } timestamp; - tcp_sack sack[0]; + uint32 value; + uint32 reply; + } timestamp; + tcp_sack sack[0]; }; } _PACKED; Modified: haiku/trunk/src/add-ons/kernel/network/socket/socket.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/socket/socket.cpp 2007-10-21 17:58:38 UTC (rev 22642) +++ haiku/trunk/src/add-ons/kernel/network/socket/socket.cpp 2007-10-21 20:10:43 UTC (rev 22643) @@ -221,7 +221,7 @@ int -getsockopt(int socket, int level, int option, void *value, size_t *_length) +getsockopt(int socket, int level, int option, void *value, socklen_t *_length) { sockopt_args args; args.level = level; @@ -240,7 +240,7 @@ int -setsockopt(int socket, int level, int option, const void *value, size_t length) +setsockopt(int socket, int level, int option, const void *value, socklen_t length) { sockopt_args args; args.level = level; Modified: haiku/trunk/src/add-ons/kernel/network/stack/net_socket.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/stack/net_socket.cpp 2007-10-21 17:58:38 UTC (rev 22642) +++ haiku/trunk/src/add-ons/kernel/network/stack/net_socket.cpp 2007-10-21 20:10:43 UTC (rev 22643) @@ -14,6 +14,7 @@ #include #include +#include #include #include #include Modified: haiku/trunk/src/add-ons/kernel/network/stack/utility.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/stack/utility.cpp 2007-10-21 17:58:38 UTC (rev 22642) +++ haiku/trunk/src/add-ons/kernel/network/stack/utility.cpp 2007-10-21 20:10:43 UTC (rev 22643) @@ -91,9 +91,13 @@ return NULL; } +#ifdef _KERNEL_MODE fStatus = user_memcpy(fBuffer, source, length); if (fStatus < B_OK) return NULL; +#else + memcpy(fBuffer, source, length); +#endif void *current = fBuffer; @@ -242,7 +246,11 @@ void Fifo::WakeAll() { +#ifdef __HAIKU__ release_sem_etc(notify, 0, B_RELEASE_ALL); +#else + release_sem_etc(notify, 0, waiting); +#endif } Modified: haiku/trunk/src/kits/network/dns/dst/dst_api.c =================================================================== --- haiku/trunk/src/kits/network/dns/dst/dst_api.c 2007-10-21 17:58:38 UTC (rev 22642) +++ haiku/trunk/src/kits/network/dns/dst/dst_api.c 2007-10-21 20:10:43 UTC (rev 22643) @@ -611,7 +611,7 @@ b64_ntop(&out_key[6], len - 6, enc_key, sizeof(enc_key)); else b64_ntop(&out_key[4], len - 4, enc_key, sizeof(enc_key)); - fprintf(fp, "%s IN KEY %ld %d %d %s\n", + fprintf(fp, "%s IN KEY %d %d %d %s\n", key->dk_key_name, key->dk_flags, key->dk_proto, key->dk_alg, enc_key); fclose(fp); Modified: haiku/trunk/src/kits/network/dns/dst/support.c =================================================================== --- haiku/trunk/src/kits/network/dns/dst/support.c 2007-10-21 17:58:38 UTC (rev 22642) +++ haiku/trunk/src/kits/network/dns/dst/support.c 2007-10-21 20:10:43 UTC (rev 22643) @@ -280,7 +280,7 @@ if (filename_length < 1 + strlen(name) + 4 + 6 + 1 + strlen(suffix)) return (-1); my_id = id; - sprintf(filename, "K%s+%03d+%05ld.%s", name, alg, my_id, + sprintf(filename, "K%s+%03d+%05d.%s", name, alg, my_id, (const char *) suffix); if (strrchr(filename, '/')) return (-1); Modified: haiku/trunk/src/kits/network/dns/inet/inet_addr.c =================================================================== --- haiku/trunk/src/kits/network/dns/inet/inet_addr.c 2007-10-21 17:58:38 UTC (rev 22642) +++ haiku/trunk/src/kits/network/dns/inet/inet_addr.c 2007-10-21 20:10:43 UTC (rev 22643) @@ -89,7 +89,7 @@ * Ascii internet address interpretation routine. * The value returned is in network order. */ -u_long +in_addr_t inet_addr(const char *cp) { struct in_addr val; Modified: haiku/trunk/src/kits/network/dns/inet/inet_ntop.c =================================================================== --- haiku/trunk/src/kits/network/dns/inet/inet_ntop.c 2007-10-21 17:58:38 UTC (rev 22642) +++ haiku/trunk/src/kits/network/dns/inet/inet_ntop.c 2007-10-21 20:10:43 UTC (rev 22643) @@ -46,8 +46,8 @@ * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. */ -static const char *inet_ntop4 __P((const u_char *src, char *dst, size_t size)); -static const char *inet_ntop6 __P((const u_char *src, char *dst, size_t size)); +static const char *inet_ntop4 __P((const u_char *src, char *dst, socklen_t size)); +static const char *inet_ntop6 __P((const u_char *src, char *dst, socklen_t size)); /* char * * inet_ntop(af, src, dst, size) @@ -62,7 +62,7 @@ int af; const void *src; char *dst; - size_t size; + socklen_t size; { switch (af) { case AF_INET: @@ -91,7 +91,7 @@ inet_ntop4(src, dst, size) const u_char *src; char *dst; - size_t size; + socklen_t size; { static const char fmt[] = "%u.%u.%u.%u"; char tmp[sizeof "255.255.255.255"]; @@ -114,7 +114,7 @@ inet_ntop6(src, dst, size) const u_char *src; char *dst; - size_t size; + socklen_t size; { /* * Note that int32_t and int16_t need only be "at least" large enough @@ -194,7 +194,7 @@ /* * Check for overflow, copy, and we're done. */ - if ((size_t)(tp - tmp) > size) { + if ((socklen_t)(tp - tmp) > size) { errno = ENOSPC; return (NULL); } Modified: haiku/trunk/src/kits/network/dns/irs/getnameinfo.c =================================================================== --- haiku/trunk/src/kits/network/dns/irs/getnameinfo.c 2007-10-21 17:58:38 UTC (rev 22642) +++ haiku/trunk/src/kits/network/dns/irs/getnameinfo.c 2007-10-21 20:10:43 UTC (rev 22643) @@ -89,11 +89,11 @@ int getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) const struct sockaddr *sa; - size_t salen; + socklen_t salen; char *host; - size_t hostlen; + socklen_t hostlen; char *serv; - size_t servlen; + socklen_t servlen; int flags; { struct afd *afd; Modified: haiku/trunk/src/kits/network/dns/resolv/res_debug.c =================================================================== --- haiku/trunk/src/kits/network/dns/resolv/res_debug.c 2007-10-21 17:58:38 UTC (rev 22642) +++ haiku/trunk/src/kits/network/dns/resolv/res_debug.c 2007-10-21 20:10:43 UTC (rev 22643) @@ -190,7 +190,7 @@ else if (section == ns_s_ar && ns_rr_type(rr) == ns_t_opt) { u_int32_t ttl = ns_rr_ttl(rr); fprintf(file, - "; EDNS: version: %lu, udp=%u, flags=%04lx\n", + "; EDNS: version: %u, udp=%u, flags=%04x\n", (ttl>>16)&0xff, ns_rr_class(rr), ttl&0xffff); } else { n = ns_sprintrr(handle, &rr, NULL, NULL, @@ -642,7 +642,7 @@ static char nbuf[40]; /* XXX nonreentrant */ if (ns_format_ttl(value, nbuf, sizeof nbuf) < 0) - sprintf(nbuf, "%lu", value); + sprintf(nbuf, "%u", value); return (nbuf); } Modified: haiku/trunk/src/kits/network/socket.cpp =================================================================== --- haiku/trunk/src/kits/network/socket.cpp 2007-10-21 17:58:38 UTC (rev 22642) +++ haiku/trunk/src/kits/network/socket.cpp 2007-10-21 20:10:43 UTC (rev 22643) @@ -418,7 +418,7 @@ extern "C" int -getsockopt(int socket, int level, int option, void *value, size_t *_length) +getsockopt(int socket, int level, int option, void *value, socklen_t *_length) { if (check_r5_compatibility()) { if (option == R5_SO_FIONREAD) { @@ -447,7 +447,8 @@ extern "C" int -setsockopt(int socket, int level, int option, const void *value, size_t length) +setsockopt(int socket, int level, int option, const void *value, + socklen_t length) { if (check_r5_compatibility()) convert_from_r5_sockopt(level, option); Modified: haiku/trunk/src/servers/net/DHCPClient.cpp =================================================================== --- haiku/trunk/src/servers/net/DHCPClient.cpp 2007-10-21 17:58:38 UTC (rev 22642) +++ haiku/trunk/src/servers/net/DHCPClient.cpp 2007-10-21 20:10:43 UTC (rev 22643) @@ -80,7 +80,13 @@ }; struct dhcp_option_cookie { - dhcp_option_cookie() : state(0), file_has_options(false), server_name_has_options(false) {} + dhcp_option_cookie() + : + state(0), + file_has_options(false), + server_name_has_options(false) + { + } const uint8* next; uint8 state; @@ -122,7 +128,8 @@ uint8* PutOption(uint8* options, message_option option, uint8 data); uint8* PutOption(uint8* options, message_option option, uint16 data); uint8* PutOption(uint8* options, message_option option, uint32 data); - uint8* PutOption(uint8* options, message_option option, const uint8* data, uint32 size); + uint8* PutOption(uint8* options, message_option option, const uint8* data, + uint32 size); uint8* FinishOptions(uint8 *); } _PACKED; @@ -263,7 +270,8 @@ { uint8 *next = options; next = PutOption(next, OPTION_MESSAGE_TYPE, type); - next = PutOption(next, OPTION_MESSAGE_SIZE, (uint16)htons(sizeof(dhcp_message))); + next = PutOption(next, OPTION_MESSAGE_SIZE, + (uint16)htons(sizeof(dhcp_message))); return next; } @@ -298,7 +306,8 @@ uint8* -dhcp_message::PutOption(uint8* options, message_option option, const uint8* data, uint32 size) +dhcp_message::PutOption(uint8* options, message_option option, + const uint8* data, uint32 size) { options[0] = option; options[1] = size; @@ -438,9 +447,10 @@ if (state == INIT) status = _SendMessage(socket, discover, broadcast); - else + else { status = _SendMessage(socket, request, state != RENEWAL ? broadcast : fServer); + } if (status < B_OK) break; @@ -490,13 +500,15 @@ _PrepareMessage(request, state); status = _SendMessage(socket, request, broadcast); - // we're sending a broadcast so that all potential offers get an answer + // we're sending a broadcast so that all potential offers + // get an answer break; } case DHCP_ACK: { - if (state != REQUESTING && state != REBINDING && state != RENEWAL) + if (state != REQUESTING && state != REBINDING + && state != RENEWAL) continue; // TODO: we might want to configure the stuff, don't we? @@ -520,7 +532,8 @@ if (state != REQUESTING) continue; - // try again (maybe we should prefer other servers if this happens more than once) + // try again (maybe we should prefer other servers if this + // happens more than once) status = _SendMessage(socket, discover, broadcast); if (status == B_OK) state = INIT; @@ -591,8 +604,10 @@ FILE* file = fopen("/etc/resolv.conf", "w"); for (uint32 i = 0; i < size / 4; i++) { printf("DNS: %s\n", _ToString(&data[i*4]).String()); - if (file != NULL) - fprintf(file, "nameserver %s\n", _ToString(&data[i*4]).String()); + if (file != NULL) { + fprintf(file, "nameserver %s\n", + _ToString(&data[i*4]).String()); + } } fclose(file); break; @@ -652,7 +667,8 @@ message.hardware_type = ARP_HARDWARE_TYPE_ETHER; message.hardware_address_length = 6; message.transaction_id = htonl(fTransactionID); - message.seconds_since_start = htons(min_c((fStartTime - system_time()) / 1000000LL, 65535)); + message.seconds_since_start = htons(min_c((fStartTime - system_time()) + / 1000000LL, 65535)); memcpy(message.mac_address, fMAC, 6); message_type type = message.Type(); @@ -669,9 +685,10 @@ // In RENEWAL or REBINDING state, we must set the client_address field, and not // use OPTION_REQUEST_IP_ADDRESS for DHCP_REQUEST messages if (type == DHCP_REQUEST && (state == INIT || state == REQUESTING)) { - next = message.PutOption(next, OPTION_REQUEST_IP_ADDRESS, fAssignedAddress); + next = message.PutOption(next, OPTION_REQUEST_IP_ADDRESS, + (uint32)fAssignedAddress); next = message.PutOption(next, OPTION_REQUEST_PARAMETERS, - kRequiredParameters, sizeof(kRequiredParameters)); + kRequiredParameters, sizeof(kRequiredParameters)); } else message.client_address = fAssignedAddress; @@ -683,7 +700,7 @@ { uint8 *next = message.PrepareMessage(type); next = message.PutOption(next, OPTION_REQUEST_PARAMETERS, - kRequiredParameters, sizeof(kRequiredParameters)); + kRequiredParameters, sizeof(kRequiredParameters)); message.FinishOptions(next); break; } From axeld at mail.berlios.de Sun Oct 21 22:14:33 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sun, 21 Oct 2007 22:14:33 +0200 Subject: [Haiku-commits] r22644 - haiku/trunk/src/add-ons/kernel/file_systems/nfs Message-ID: <200710212014.l9LKEX6x007904@sheep.berlios.de> Author: axeld Date: 2007-10-21 22:14:32 +0200 (Sun, 21 Oct 2007) New Revision: 22644 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22644&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/nfs/nfs_add_on.c haiku/trunk/src/add-ons/kernel/file_systems/nfs/nfs_add_on.h Log: * Fixed lots of warnings (there are still a lot left). * Got rid of the PARAMS_AS_STRING stuff (it's always defined, anyway). * Will remove BeOS support, too, in the future. * Minor cleanup. Modified: haiku/trunk/src/add-ons/kernel/file_systems/nfs/nfs_add_on.c =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/nfs/nfs_add_on.c 2007-10-21 20:10:43 UTC (rev 22643) +++ haiku/trunk/src/add-ons/kernel/file_systems/nfs/nfs_add_on.c 2007-10-21 20:14:32 UTC (rev 22644) @@ -17,9 +17,6 @@ #include #include -/* Haiku requires a string for mount params... */ -#define PARAMS_AS_STRING 1 - #ifndef UDP_SIZE_MAX #define UDP_SIZE_MAX 65515 #endif @@ -28,6 +25,8 @@ /* declare gSocket and others */ KSOCKET_MODULE_DECL; +static int fs_rmdir(fs_nspace *ns, fs_node *dir, const char *name); + /* *** configuration *** */ //#define NFS_FS_FLAGS B_FS_IS_SHARED @@ -60,7 +59,9 @@ static vint32 refcount = 0; /* we only want to read the config once ? */ -static status_t read_config(void) + +static status_t +read_config(void) { void *handle; const char *str, *endptr; @@ -102,7 +103,8 @@ return B_OK; } -extern status_t + +status_t create_socket(fs_nspace *ns) { struct sockaddr_in addr; @@ -150,26 +152,30 @@ return B_OK; } -extern status_t + +#if 0 +static status_t connect_socket(fs_nspace *ns) { - uint16 port=conf_high_port; - + uint16 port = conf_high_port; + struct sockaddr_in addr; - addr.sin_family=AF_INET; - addr.sin_addr.s_addr=htonl(INADDR_ANY); - //addr.sin_addr.s_addr=htonl(INADDR_LOOPBACK); - addr.sin_port=htons(port); - memset (addr.sin_zero,0,sizeof(addr.sin_zero)); - + addr.sin_family = AF_INET; + addr.sin_addr.s_addr = htonl(INADDR_ANY); + //addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + addr.sin_port = htons(port); + memset(addr.sin_zero,0,sizeof(addr.sin_zero)); + if (kconnect(ns->s,(const struct sockaddr *)&ns->nfsAddr,sizeof(ns->nfsAddr))<0) { return -1; } return B_OK; } +#endif -extern status_t + +status_t init_postoffice(fs_nspace *ns) { status_t result; @@ -193,7 +199,8 @@ return B_OK; } -extern void + +void shutdown_postoffice(fs_nspace *ns) { status_t result; @@ -204,7 +211,8 @@ wait_for_thread (ns->tid,&result); } -extern status_t + +status_t postoffice_func(fs_nspace *ns) { uint8 *buffer=(uint8 *)malloc(B_UDP_MAX_SIZE); @@ -240,9 +248,10 @@ return B_OK; } -uint8 *send_rpc_call (fs_nspace *ns, const struct sockaddr_in *addr, - int32 prog, int32 vers, int32 proc, - const struct XDROutPacket *packet) + +uint8 * +send_rpc_call(fs_nspace *ns, const struct sockaddr_in *addr, int32 prog, + int32 vers, int32 proc, const struct XDROutPacket *packet) { int32 xid; size_t authSize; @@ -290,45 +299,40 @@ checksemstate(xid, pending->sem, 0); #endif - do - { + do { ssize_t bytes; - do - { - bytes=ksendto (ns->s,(const void *)XDROutPacketBuffer(&rpc_call), - XDROutPacketLength(&rpc_call),0, - (const struct sockaddr *)addr,sizeof(*addr)); + do { + bytes = ksendto(ns->s,(const void *)XDROutPacketBuffer(&rpc_call), + XDROutPacketLength(&rpc_call), 0, + (const struct sockaddr *)addr, sizeof(*addr)); } - while ((bytes<0)&&(errno==EINTR)); - - do - { - result=acquire_sem_etc (pending->sem,1,B_TIMEOUT,(retries)?(conf_call_timeout):(2*conf_call_timeout)); + while (bytes < 0 && errno == EINTR); + + do { + result = acquire_sem_etc (pending->sem,1,B_TIMEOUT,(retries)?(conf_call_timeout):(2*conf_call_timeout)); } - while (result==B_INTERRUPTED); - + while (result == B_INTERRUPTED); + retries--; - } - while ((result==B_TIMED_OUT)&&(retries>=0)); + } while (result == B_TIMED_OUT && retries >= 0); - if (result>=B_OK) - { - uint8 *buffer=pending->buffer; - pending->buffer=NULL; - SemaphorePoolPut(&ns->pendingCalls.fPool,pending->sem); - + if (result >= B_OK) { + uint8 *buffer = pending->buffer; + pending->buffer = NULL; + SemaphorePoolPut(&ns->pendingCalls.fPool, pending->sem); + PendingCallDestroy(pending); free(pending); - - XDROutPacketDestroy (&rpc_call); + + XDROutPacketDestroy(&rpc_call); return buffer; } // we timed out - call=RPCPendingCallsFindAndRemovePendingCall(&ns->pendingCalls,xid,addr); + call = RPCPendingCallsFindAndRemovePendingCall(&ns->pendingCalls, xid, addr); - kmessage ("nfs: xid %ld timed out, removing from queue",xid); + kmessage("nfs: xid %ld timed out, removing from queue", xid); #if 0 if (call==NULL) @@ -349,77 +353,74 @@ #endif } #endif - + free(pending->buffer); - + /* mmu_man */ if (call) /* if the call has been found and removed (atomic op), the sem hasn't been released */ - SemaphorePoolPut(&ns->pendingCalls.fPool,pending->sem); + SemaphorePoolPut(&ns->pendingCalls.fPool, pending->sem); else delete_sem(pending->sem); /* else it's in an unknown state, forget it */ - PendingCallDestroy (pending); + PendingCallDestroy(pending); free(pending); - + XDROutPacketDestroy (&rpc_call); return NULL; } -bool is_successful_reply (struct XDRInPacket *reply) + +bool +is_successful_reply(struct XDRInPacket *reply) { - bool success=false; - - int32 xid=XDRInPacketGetInt32(reply); + bool success = false; + + int32 xid = XDRInPacketGetInt32(reply); rpc_msg_type mtype=(rpc_msg_type)XDRInPacketGetInt32(reply); rpc_reply_stat replyStat=(rpc_reply_stat)XDRInPacketGetInt32(reply); (void)xid; (void)mtype; - - if (replyStat==RPC_MSG_DENIED) - { - rpc_reject_stat rejectStat=(rpc_reject_stat)XDRInPacketGetInt32(reply); - - if (rejectStat==RPC_RPC_MISMATCH) - { + + if (replyStat == RPC_MSG_DENIED) { + rpc_reject_stat rejectStat = (rpc_reject_stat)XDRInPacketGetInt32(reply); + + if (rejectStat == RPC_RPC_MISMATCH) { int32 low=XDRInPacketGetInt32(reply); int32 high=XDRInPacketGetInt32(reply); - - kmessage ("RPC_MISMATCH (%ld,%ld)",low,high); + + kmessage ("RPC_MISMATCH (%ld,%ld)", low, high); + } else { + rpc_auth_stat authStat = (rpc_auth_stat)XDRInPacketGetInt32(reply); + + kmessage ("RPC_AUTH_ERROR (%d)", authStat); } - else - { - rpc_auth_stat authStat=(rpc_auth_stat)XDRInPacketGetInt32(reply); - - kmessage ("RPC_AUTH_ERROR (%d)",authStat); - } - } - else - { - rpc_auth_flavor flavor=(rpc_auth_flavor)XDRInPacketGetInt32(reply); + } else { + rpc_auth_flavor flavor = (rpc_auth_flavor)XDRInPacketGetInt32(reply); char body[400]; - size_t bodyLength=XDRInPacketGetDynamic(reply,body); - - rpc_accept_stat acceptStat=(rpc_accept_stat)XDRInPacketGetInt32(reply); + size_t bodyLength = XDRInPacketGetDynamic(reply, body); + + rpc_accept_stat acceptStat = (rpc_accept_stat)XDRInPacketGetInt32(reply); (void)flavor; (void)bodyLength; - - if (acceptStat==RPC_PROG_MISMATCH) - { - int32 low=XDRInPacketGetInt32(reply); - int32 high=XDRInPacketGetInt32(reply); - - kmessage ("RPC_PROG_MISMATCH (%ld,%ld)",low,high); - } - else if (acceptStat!=RPC_SUCCESS) - kmessage ("Accepted but failed (%d)",acceptStat); + + if (acceptStat == RPC_PROG_MISMATCH) { + int32 low = XDRInPacketGetInt32(reply); + int32 high = XDRInPacketGetInt32(reply); + + kmessage ("RPC_PROG_MISMATCH (%ld,%ld)", low, high); + } else if (acceptStat != RPC_SUCCESS) + kmessage ("Accepted but failed (%d)", acceptStat); else - success=true; + success = true; } return success; } -status_t get_remote_address (fs_nspace *ns, int32 prog, int32 vers, int32 prot, struct sockaddr_in *addr) + +status_t +get_remote_address(fs_nspace *ns, int32 prog, int32 vers, int32 prot, + struct sockaddr_in *addr) { struct XDROutPacket call; uint8 *replyBuf; @@ -556,111 +557,107 @@ return B_OK; } -status_t nfs_getattr (fs_nspace *ns, const nfs_fhandle *fhandle, - struct stat *st) + +status_t +nfs_getattr(fs_nspace *ns, const nfs_fhandle *fhandle, struct stat *st) { struct XDROutPacket call; struct XDRInPacket reply; uint8 *replyBuf; int32 status; - - XDROutPacketInit (&call); - XDRInPacketInit (&reply); - - XDROutPacketAddFixed (&call,fhandle->opaque,NFS_FHSIZE); - - replyBuf=send_rpc_call (ns,&ns->nfsAddr,NFS_PROGRAM,NFS_VERSION,NFSPROC_GETATTR,&call); - if (!replyBuf) - { - XDRInPacketDestroy (&reply); - XDROutPacketDestroy (&call); + XDROutPacketInit(&call); + XDRInPacketInit(&reply); + + XDROutPacketAddFixed(&call, fhandle->opaque, NFS_FHSIZE); + + replyBuf = send_rpc_call(ns, &ns->nfsAddr, NFS_PROGRAM, NFS_VERSION, + NFSPROC_GETATTR, &call); + if (replyBuf == NULL) { + XDRInPacketDestroy(&reply); + XDROutPacketDestroy(&call); return EHOSTUNREACH; } - XDRInPacketSetTo (&reply,replyBuf,0); + XDRInPacketSetTo(&reply, replyBuf, 0); - if (!is_successful_reply(&reply)) - { - XDRInPacketDestroy (&reply); - XDROutPacketDestroy (&call); + if (!is_successful_reply(&reply)) { + XDRInPacketDestroy(&reply); + XDROutPacketDestroy(&call); return B_ERROR; } - - status=XDRInPacketGetInt32(&reply); - - if (status!=NFS_OK) - { - XDRInPacketDestroy (&reply); - XDROutPacketDestroy (&call); + + status = XDRInPacketGetInt32(&reply); + if (status != NFS_OK) { + XDRInPacketDestroy(&reply); + XDROutPacketDestroy(&call); return map_nfs_to_system_error(status); } - - get_nfs_attr (&reply,st); - XDRInPacketDestroy (&reply); - XDROutPacketDestroy (&call); + get_nfs_attr(&reply, st); + + XDRInPacketDestroy(&reply); + XDROutPacketDestroy(&call); return B_OK; } -extern status_t + +status_t nfs_truncate_file(fs_nspace *ns, const nfs_fhandle *fhandle, struct stat *st) { struct XDROutPacket call; struct XDRInPacket reply; uint8 *replyBuf; int32 status; - - XDROutPacketInit (&call); - XDRInPacketInit (&reply); - - XDROutPacketAddFixed(&call,fhandle->opaque,NFS_FHSIZE); - XDROutPacketAddInt32 (&call,-1); - XDROutPacketAddInt32 (&call,-1); - XDROutPacketAddInt32 (&call,-1); - XDROutPacketAddInt32 (&call,0); - XDROutPacketAddInt32 (&call,time(NULL)); - XDROutPacketAddInt32 (&call,0); - XDROutPacketAddInt32 (&call,time(NULL)); - XDROutPacketAddInt32 (&call,0); + XDROutPacketInit(&call); + XDRInPacketInit(&reply); - replyBuf=send_rpc_call (ns,&ns->nfsAddr,NFS_PROGRAM,NFS_VERSION,NFSPROC_SETATTR,&call); + XDROutPacketAddFixed(&call, fhandle->opaque, NFS_FHSIZE); - if (!replyBuf) - { - XDRInPacketDestroy (&reply); - XDROutPacketDestroy (&call); + XDROutPacketAddInt32(&call, -1); + XDROutPacketAddInt32(&call, -1); + XDROutPacketAddInt32(&call, -1); + XDROutPacketAddInt32(&call, 0); + XDROutPacketAddInt32(&call, time(NULL)); + XDROutPacketAddInt32(&call, 0); + XDROutPacketAddInt32(&call, time(NULL)); + XDROutPacketAddInt32(&call, 0); + + replyBuf = send_rpc_call(ns, &ns->nfsAddr, NFS_PROGRAM, NFS_VERSION, + NFSPROC_SETATTR, &call); + if (replyBuf == NULL) { + XDRInPacketDestroy(&reply); + XDROutPacketDestroy(&call); return EHOSTUNREACH; } - - XDRInPacketSetTo(&reply,replyBuf,0); - if (!is_successful_reply(&reply)) - { - XDRInPacketDestroy (&reply); - XDROutPacketDestroy (&call); + XDRInPacketSetTo(&reply, replyBuf, 0); + + if (!is_successful_reply(&reply)) { + XDRInPacketDestroy(&reply); + XDROutPacketDestroy(&call); return B_ERROR; } - - status=XDRInPacketGetInt32(&reply); - - if (status!=NFS_OK) - { - XDRInPacketDestroy (&reply); - XDROutPacketDestroy (&call); + + status = XDRInPacketGetInt32(&reply); + if (status != NFS_OK) { + XDRInPacketDestroy(&reply); + XDROutPacketDestroy(&call); return map_nfs_to_system_error(status); } - + if (st) - get_nfs_attr (&reply,st); + get_nfs_attr(&reply,st); - XDRInPacketDestroy (&reply); - XDROutPacketDestroy (&call); + XDRInPacketDestroy(&reply); + XDROutPacketDestroy(&call); return B_OK; } -void get_nfs_attr (struct XDRInPacket *reply, struct stat *st) + +void +get_nfs_attr(struct XDRInPacket *reply, struct stat *st) { nfs_ftype ftype=(nfs_ftype)XDRInPacketGetInt32(reply); (void) ftype; @@ -689,10 +686,11 @@ XDRInPacketGetInt32(reply); // usecs } -status_t map_nfs_to_system_error (status_t nfsstatus) + +status_t +map_nfs_to_system_error(status_t nfsstatus) { - switch (nfsstatus) - { + switch (nfsstatus) { case NFS_OK: return B_OK; @@ -746,24 +744,27 @@ } } -extern nfs_fhandle + +nfs_fhandle handle_from_vnid(fs_nspace *ns, ino_t vnid) { fs_node *current; - - while (acquire_sem (ns->sem)==B_INTERRUPTED); - - current=ns->first; - - while ((current)&&(current->vnid!=vnid)) - current=current->next; - - while (release_sem (ns->sem)==B_INTERRUPTED); - + + while (acquire_sem(ns->sem) == B_INTERRUPTED); + + current = ns->first; + + while (current != NULL && current->vnid != vnid) + current = current->next; + + while (release_sem(ns->sem) == B_INTERRUPTED); + return current->fhandle; } -void insert_node (fs_nspace *ns, fs_node *node) + +void +insert_node(fs_nspace *ns, fs_node *node) { fs_node *current; @@ -787,7 +788,9 @@ while (release_sem (ns->sem)==B_INTERRUPTED); } -void remove_node (fs_nspace *ns, ino_t vnid) + +void +remove_node(fs_nspace *ns, ino_t vnid) { fs_node *current; fs_node *previous; @@ -797,14 +800,12 @@ current=ns->first; previous=NULL; - while ((current)&&(current->vnid!=vnid)) - { - previous=current; - current=current->next; + while (current != NULL && current->vnid != vnid) { + previous = current; + current = current->next; } - - if (current) - { + + if (current) { if (previous) previous->next=current->next; else @@ -816,7 +817,11 @@ while (release_sem (ns->sem)==B_INTERRUPTED); } -extern int + +// #pragma mark - + + +static int #ifdef __HAIKU__ fs_read_vnode(fs_nspace *ns, ino_t vnid, fs_node **node, char r) #else @@ -848,7 +853,8 @@ return B_OK; } -extern int + +static int #ifdef __HAIKU__ fs_release_vnode(fs_nspace *ns, fs_node *node, char r) #else @@ -861,19 +867,8 @@ return B_OK; } -#ifdef __HAIKU__ -/* no reason to do it, - * the VFS does it the best possible way for an unix fs anyway. - * so we use NULL for this call. - */ -extern int -fs_get_vnode_name(fs_nspace *ns, fs_node *node, char *buffer, size_t len) -{ - return ENOSYS; -} -#endif -extern int +static int #ifdef __HAIKU__ fs_walk(fs_nspace *ns, fs_node *base, const char *file, ino_t *vnid, int *type) #else @@ -947,7 +942,8 @@ return B_OK; } -extern int + +static int fs_opendir(fs_nspace *ns, fs_node *node, nfs_cookie **cookie) { struct stat st; @@ -965,7 +961,8 @@ return B_OK; } -extern int + +static int fs_closedir(fs_nspace *ns, fs_node *node, nfs_cookie *cookie) { (void) ns; @@ -974,7 +971,8 @@ return B_OK; } -extern int + +static int fs_rewinddir(fs_nspace *ns, fs_node *node, nfs_cookie *cookie) { (void) ns; @@ -984,7 +982,8 @@ return B_OK; } -extern int + +static int #ifdef __HAIKU__ fs_readdir(fs_nspace *ns, fs_node *node, nfs_cookie *cookie, struct dirent *buf, size_t bufsize, uint32 *num) #else @@ -1118,7 +1117,8 @@ return B_OK; } -extern int + +static int fs_free_dircookie(fs_nspace *ns, fs_node *node, nfs_cookie *cookie) { (void) ns; @@ -1127,7 +1127,8 @@ return B_OK; } -extern int + +static int fs_rstat(fs_nspace *ns, fs_node *node, struct stat *st) { status_t result; @@ -1140,20 +1141,23 @@ return B_OK; } -extern void + +void fs_nspaceInit(struct fs_nspace *nspace) { RPCPendingCallsInit (&nspace->pendingCalls); } -extern void + +void fs_nspaceDestroy(struct fs_nspace *nspace) { RPCPendingCallsDestroy (&nspace->pendingCalls); } -#ifdef PARAMS_AS_STRING -int parse_nfs_params(const char *str, struct mount_nfs_params *params) + +static int +parse_nfs_params(const char *str, struct mount_nfs_params *params) { const char *p, *e; long v; @@ -1237,18 +1241,17 @@ params->hostname, params->uid, params->gid); return B_OK; } -#endif -extern int + +static int #ifdef __HAIKU__ -fs_mount(nspace_id nsid, const char *devname, uint32 flags, const char *_parms, fs_nspace **data, ino_t *vnid) +fs_mount(dev_t nsid, const char *devname, uint32 flags, const char *_parms, + fs_volume *_data, ino_t *vnid) #else -fs_mount(nspace_id nsid, const char *devname, ulong flags, const char *_parms, size_t len, fs_nspace **data, ino_t *vnid) +fs_mount(nspace_id nsid, const char *devname, ulong flags, const char *_parms, + size_t len, fs_nspace **_data, ino_t *vnid) #endif { -#ifndef PARAMS_AS_STRING - struct mount_nfs_params *parms = (struct mount_nfs_params *)_parms; // XXX: FIXME -#endif status_t result; fs_nspace *ns; fs_node *rootNode; @@ -1257,104 +1260,87 @@ (void) len; #endif - if (_parms==NULL) + if (_parms == NULL) return EINVAL; -dprintf("nfs: mount(%ld, %s, %08lx)\n", nsid, devname, flags); -#ifndef PARAMS_AS_STRING -dprintf("nfs: nfs_params(ip:%lu, server:%s, export:%s, uid:%d, gid:%d, hostname:%s)\n", - parms->serverIP, - parms->server, - parms->_export, - parms->uid, - parms->gid, - parms->hostname); -#else -dprintf("nfs: nfs_params: %s\n", _parms); -#endif + dprintf("nfs: mount(%ld, %s, %08lx)\n", nsid, devname, flags); + dprintf("nfs: nfs_params: %s\n", _parms); // HAIKU: this should go to std_ops if (!refcount) read_config(); - + result = ksocket_init(); if (result < B_OK) return result; result = ENOMEM; - ns=(fs_nspace *)malloc(sizeof(fs_nspace)); + ns = (fs_nspace *)malloc(sizeof(fs_nspace)); if (!ns) goto err_nspace; - fs_nspaceInit (ns); + fs_nspaceInit(ns); - ns->nsid=nsid; - - ns->params.server=NULL; - ns->params._export=NULL; - ns->params.hostname=NULL; -#ifdef PARAMS_AS_STRING + ns->nsid = nsid; + + ns->params.server = NULL; + ns->params._export = NULL; + ns->params.hostname = NULL; if ((result = parse_nfs_params(_parms, &ns->params)) < 0) goto err_params; -#else - ns->params.serverIP=parms->serverIP; - ns->params.server=strdup(parms->server); - ns->params._export=strdup(parms->_export); - ns->params.uid=parms->uid; - ns->params.gid=parms->gid; - ns->params.hostname=strdup(parms->hostname); -#endif - ns->xid=0; - ns->mountAddr.sin_family=AF_INET; - ns->mountAddr.sin_addr.s_addr=htonl(ns->params.serverIP); - memset (ns->mountAddr.sin_zero,0,sizeof(ns->mountAddr.sin_zero)); + ns->xid = 0; + ns->mountAddr.sin_family = AF_INET; + ns->mountAddr.sin_addr.s_addr = htonl(ns->params.serverIP); + memset(ns->mountAddr.sin_zero, 0, sizeof(ns->mountAddr.sin_zero)); - if ((result=create_socket(ns))mountAddr))mountAddr)) < B_OK) goto err_sem; - memcpy (&ns->nfsAddr,&ns->mountAddr,sizeof(ns->mountAddr)); -dprintf("nfs: mountd at %08lx:%d\n", ns->mountAddr.sin_addr.s_addr, ntohs(ns->mountAddr.sin_port)); - - if ((result=get_remote_address(ns,NFS_PROGRAM,NFS_VERSION,PMAP_IPPROTO_UDP,&ns->nfsAddr))nfsAddr, &ns->mountAddr, sizeof(ns->mountAddr)); +dprintf("nfs: mountd at %08x:%d\n", ns->mountAddr.sin_addr.s_addr, ntohs(ns->mountAddr.sin_port)); + + if ((result = get_remote_address(ns, NFS_PROGRAM, NFS_VERSION, + PMAP_IPPROTO_UDP, &ns->nfsAddr)) < B_OK) goto err_sem; -dprintf("nfs: nfsd at %08lx:%d\n", ns->nfsAddr.sin_addr.s_addr, ntohs(ns->nfsAddr.sin_port)); +dprintf("nfs: nfsd at %08x:%d\n", ns->nfsAddr.sin_addr.s_addr, ntohs(ns->nfsAddr.sin_port)); // result = connect_socket(ns); //dprintf("nfs: connect: %s\n", strerror(result)); - if ((result=create_sem(1,"nfs_sem"))sem=result; - - set_sem_owner (ns->sem,B_SYSTEM_TEAM); - + ns->sem = result; + + set_sem_owner(ns->sem, B_SYSTEM_TEAM); + result = ENOMEM; - rootNode=(fs_node *)malloc(sizeof(fs_node)); + rootNode = (fs_node *)malloc(sizeof(fs_node)); if (!rootNode) goto err_rootvn; - rootNode->next=NULL; + rootNode->next = NULL; - if ((result=nfs_mount(ns,ns->params._export,&rootNode->fhandle))params._export, &rootNode->fhandle)) < B_OK) goto err_mount; - if ((result=nfs_getattr(ns,&rootNode->fhandle,&st))fhandle, &st)) < B_OK) goto err_publish; - ns->rootid=st.st_ino; - rootNode->vnid=ns->rootid; - - *vnid=ns->rootid; + ns->rootid = st.st_ino; + rootNode->vnid = ns->rootid; - if ((result=publish_vnode(nsid,*vnid,rootNode))rootid; + + if ((result = publish_vnode(nsid, *vnid, rootNode)) < B_OK) goto err_publish; - - *data=ns; + *_data = ns; + ns->first=rootNode; return B_OK; @@ -1389,18 +1375,19 @@ return result; } -extern int -fs_unmount(fs_nspace *ns) + +static int +fs_unmount(fs_volume _volume) { - free (ns->params.hostname); - free (ns->params._export); - free (ns->params.server); - - while (ns->first) - { - fs_node *next=ns->first->next; + fs_nspace *ns = (fs_nspace *)_volume; + free(ns->params.hostname); + free(ns->params._export); + free(ns->params.server); + + while (ns->first) { + fs_node *next = ns->first->next; free(ns->first); - ns->first=next; + ns->first = next; } // Unlike in BeOS, we need to put the reference to our root node ourselves @@ -1408,15 +1395,16 @@ put_vnode(ns->nsid, ns->rootid); #endif - delete_sem (ns->sem); + delete_sem(ns->sem); shutdown_postoffice(ns); - fs_nspaceDestroy (ns); + fs_nspaceDestroy(ns); free(ns); ksocket_cleanup(); return B_OK; } -extern int + +static int fs_rfsstat(fs_nspace *ns, struct fs_info *info) { struct XDROutPacket call; @@ -1425,66 +1413,60 @@ uint8 *replyBuf; int32 status; //dprintf("nfs: rfsstat()\n");//XXX:mmu_man:debug - - XDROutPacketInit (&call); - XDRInPacketInit (&reply); - - XDROutPacketAddFixed (&call,rootHandle.opaque,NFS_FHSIZE); - - replyBuf=send_rpc_call (ns,&ns->nfsAddr,NFS_PROGRAM,NFS_VERSION,NFSPROC_STATFS,&call); - if (!replyBuf) - { - XDRInPacketDestroy (&reply); - XDROutPacketDestroy (&call); + XDROutPacketInit(&call); + XDRInPacketInit(&reply); + + XDROutPacketAddFixed(&call, rootHandle.opaque, NFS_FHSIZE); + + replyBuf = send_rpc_call(ns, &ns->nfsAddr, NFS_PROGRAM, NFS_VERSION, + NFSPROC_STATFS, &call); + if (replyBuf == NULL) { + XDRInPacketDestroy(&reply); + XDROutPacketDestroy(&call); return EHOSTUNREACH; } - - XDRInPacketSetTo(&reply,replyBuf,0); - if (!is_successful_reply(&reply)) - { - XDRInPacketDestroy (&reply); - XDROutPacketDestroy (&call); + XDRInPacketSetTo(&reply, replyBuf, 0); + + if (!is_successful_reply(&reply)) { + XDRInPacketDestroy(&reply); + XDROutPacketDestroy(&call); return B_ERROR; } - - status=XDRInPacketGetInt32(&reply); - - if (status!=NFS_OK) - { - XDRInPacketDestroy (&reply); - XDROutPacketDestroy (&call); + + status = XDRInPacketGetInt32(&reply); + if (status != NFS_OK) { + XDRInPacketDestroy(&reply); + XDROutPacketDestroy(&call); //dprintf("nfs: rfsstat() error 0x%08lx\n", map_nfs_to_system_error(status)); return map_nfs_to_system_error(status); } - - info->dev=ns->nsid; - info->root=ns->rootid; - info->flags=NFS_FS_FLAGS; + info->dev = ns->nsid; + info->root = ns->rootid; + info->flags = NFS_FS_FLAGS; + XDRInPacketGetInt32(&reply); // tsize - info->block_size=XDRInPacketGetInt32(&reply); - info->io_size=8192; - info->total_blocks=XDRInPacketGetInt32(&reply); - info->free_blocks=XDRInPacketGetInt32(&reply); - info->total_nodes=100; - info->free_nodes=100; - //strcpy (info->device_name,"nfs_device"); - strcpy (info->device_name,""); - strcpy (info->volume_name,"nfs://"); - strcat (info->volume_name,ns->params.server); - strcat (info->volume_name,ns->params._export); - //strcpy (info->fsh_name,"nfs_fsh"); - strcpy (info->fsh_name,"nfs"); + info->block_size = XDRInPacketGetInt32(&reply); + info->io_size = 8192; [... truncated: 486 lines follow ...] From axeld at mail.berlios.de Sun Oct 21 22:25:55 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sun, 21 Oct 2007 22:25:55 +0200 Subject: [Haiku-commits] r22645 - haiku/trunk/src/tests/kits/net/tcp_shell Message-ID: <200710212025.l9LKPt0g008756@sheep.berlios.de> Author: axeld Date: 2007-10-21 22:25:54 +0200 (Sun, 21 Oct 2007) New Revision: 22645 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22645&view=rev Added: haiku/trunk/src/tests/kits/net/tcp_shell/tcp_shell.cpp Removed: haiku/trunk/src/tests/kits/net/tcp_shell/tcp_tester.cpp Modified: haiku/trunk/src/tests/kits/net/tcp_shell/Jamfile Log: Now builds again, but it doesn't work yet due to the changes in the stack. Modified: haiku/trunk/src/tests/kits/net/tcp_shell/Jamfile =================================================================== --- haiku/trunk/src/tests/kits/net/tcp_shell/Jamfile 2007-10-21 20:14:32 UTC (rev 22644) +++ haiku/trunk/src/tests/kits/net/tcp_shell/Jamfile 2007-10-21 20:25:54 UTC (rev 22645) @@ -5,11 +5,11 @@ SubDirHdrs [ FDirName $(HAIKU_TOP) src tests add-ons kernel file_systems fs_shell ] ; SubDirHdrs [ FDirName $(HAIKU_TOP) src add-ons kernel network protocols tcp ] ; SubDirHdrs [ FDirName $(HAIKU_TOP) src add-ons kernel network stack ] ; -UseHeaders $(TARGET_PRIVATE_KERNEL_HEADERS) : true ; -UsePrivateHeaders kernel net shared ; +UseHeaders $(HAIKU_PRIVATE_KERNEL_HEADERS) : true ; +UsePrivateHeaders net shared ; SimpleTest tcp_shell : - tcp_tester.cpp + tcp_shell.cpp # stack net_buffer.cpp Copied: haiku/trunk/src/tests/kits/net/tcp_shell/tcp_shell.cpp (from rev 22631, haiku/trunk/src/tests/kits/net/tcp_shell/tcp_tester.cpp) =================================================================== --- haiku/trunk/src/tests/kits/net/tcp_shell/tcp_tester.cpp 2007-10-21 10:58:24 UTC (rev 22631) +++ haiku/trunk/src/tests/kits/net/tcp_shell/tcp_shell.cpp 2007-10-21 20:25:54 UTC (rev 22645) @@ -0,0 +1,1594 @@ +/* + * Copyright 2006-2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Axel D?rfler, axeld at pinc-software.de + */ + + +#include "argv.h" +#include "tcp.h" +#include "utility.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + + +struct context { + BLocker lock; + sem_id wait_sem; + struct list list; + net_route route; + bool server; + thread_id thread; +}; + +struct cmd_entry { + char* name; + void (*func)(int argc, char **argv); + char* help; +}; + +struct net_socket_private : net_socket { + struct list_link link; + team_id owner; + uint32 max_backlog; + uint32 child_count; + struct list pending_children; + struct list connected_children; + + struct select_sync_pool *select_pool; + benaphore lock; +}; + + +extern "C" status_t _add_builtin_module(module_info *info); +extern bool gDebugOutputEnabled; + // from libkernelland_emu.so + +extern struct net_buffer_module_info gNetBufferModule; + // from net_buffer.cpp +extern net_address_module_info gIPv4AddressModule; + // from ipv4_address.cpp +extern module_info *modules[]; + // from tcp.cpp + + +extern struct net_protocol_module_info gDomainModule; +static struct net_protocol sDomainProtocol; +struct net_interface gInterface; +extern struct net_socket_module_info gNetSocketModule; +struct net_protocol_module_info *gTCPModule; +struct net_socket *gServerSocket, *gClientSocket; +static struct context sClientContext, sServerContext; + +static vint32 sPacketNumber = 1; +static double sRandomDrop = 0.0; +static set sDropList; +static bigtime_t sRoundTripTime = 0; +static bool sIncreasingRoundTrip = false; +static bool sRandomRoundTrip = false; +static bool sTCPDump = true; +static bigtime_t sStartTime; +static double sRandomReorder = 0.0; +static set sReorderList; +static bool sSimultaneousConnect = false; + +static struct net_domain sDomain = { + "ipv4", + AF_INET, + {}, + &gDomainModule, + &gIPv4AddressModule +}; + + +bool +is_server(const sockaddr* addr) +{ + return ((sockaddr_in*)addr)->sin_port == htons(1024); +} + + +bool +is_syn(net_buffer* buffer) +{ + NetBufferHeaderReader bufferHeader(buffer); + if (bufferHeader.Status() < B_OK) + return bufferHeader.Status(); + + tcp_header &header = bufferHeader.Data(); + + return (header.flags & TCP_FLAG_SYNCHRONIZE) != 0; +} + + +// #pragma mark - misc kernel + + +void * +object_cache_alloc(object_cache *cache, uint32 flags) +{ + return malloc((size_t)cache); +} + + +void +object_cache_free(object_cache *cache, void *object) +{ + free(object); +} + + +object_cache * +create_object_cache(const char *name, size_t objectSize, + size_t alignment, void *cookie, object_cache_constructor constructor, + object_cache_destructor) +{ + return (object_cache*)objectSize; +} + + +void +delete_object_cache(object_cache *cache) +{ +} + + +// #pragma mark - stack + + +status_t +std_ops(int32, ...) +{ + return B_OK; +} + + +net_domain * +get_domain(int family) +{ + return &sDomain; +} + + +status_t +register_domain_protocols(int family, int type, int protocol, ...) +{ + return B_OK; +} + + +status_t +register_domain_datalink_protocols(int family, int type, ...) +{ + return B_OK; +} + + +static status_t +register_domain_receiving_protocol(int family, int type, const char *moduleName) +{ + return B_OK; +} + + +static net_stack_module_info gNetStackModule = { + { + NET_STACK_MODULE_NAME, + 0, + std_ops + }, + NULL, //register_domain, + NULL, //unregister_domain, + get_domain, + + register_domain_protocols, + register_domain_datalink_protocols, + register_domain_receiving_protocol, + + NULL, //get_domain_receiving_protocol, + NULL, //put_domain_receiving_protocol, + + NULL, //register_device_deframer, + NULL, //unregister_device_deframer, + NULL, //register_domain_device_handler, + NULL, //register_device_handler, + NULL, //unregister_device_handler, + NULL, //register_device_monitor, + NULL, //unregister_device_monitor, + NULL, //device_link_changed, + NULL, //device_removed, + NULL, //device_enqueue_buffer, + + notify_socket, + + checksum, + + init_fifo, + uninit_fifo, + fifo_enqueue_buffer, + fifo_dequeue_buffer, + clear_fifo, + fifo_socket_enqueue_buffer, + + init_timer, + set_timer, + cancel_timer, + is_timer_active, +}; + + +// #pragma mark - socket + + +status_t +socket_create(int family, int type, int protocol, net_socket **_socket) +{ + struct net_socket_private *socket = new (std::nothrow) net_socket_private; + if (socket == NULL) + return B_NO_MEMORY; + + memset(socket, 0, sizeof(net_socket)); + socket->family = family; + socket->type = type; + socket->protocol = protocol; + + status_t status = benaphore_init(&socket->lock, "socket"); + if (status < B_OK) + goto err1; + + // set defaults (may be overridden by the protocols) + socket->send.buffer_size = 65535; + socket->send.low_water_mark = 1; + socket->send.timeout = B_INFINITE_TIMEOUT; + socket->receive.buffer_size = 65535; + socket->receive.low_water_mark = 1; + socket->receive.timeout = B_INFINITE_TIMEOUT; + + list_init_etc(&socket->pending_children, offsetof(net_socket_private, link)); + list_init_etc(&socket->connected_children, offsetof(net_socket_private, link)); + + socket->first_protocol = gTCPModule->init_protocol(socket); + if (socket->first_protocol == NULL) { + fprintf(stderr, "tcp_tester: cannot create protocol\n"); + goto err2; + } + + socket->first_info = gTCPModule; + + socket->first_protocol->next = &sDomainProtocol; + socket->first_protocol->module = gTCPModule; + socket->first_protocol->socket = socket; + + *_socket = socket; + return B_OK; + +err2: + benaphore_destroy(&socket->lock); +err1: + delete socket; + return status; +} + + +void +socket_delete(net_socket *_socket) +{ + net_socket_private *socket = (net_socket_private *)_socket; + + if (socket->parent != NULL) + panic("socket still has a parent!"); + + socket->first_info->uninit_protocol(socket->first_protocol); + benaphore_destroy(&socket->lock); + delete socket; +} + + +int +socket_accept(net_socket *socket, struct sockaddr *address, socklen_t *_addressLength, + net_socket **_acceptedSocket) +{ + net_socket *accepted; + status_t status = socket->first_info->accept(socket->first_protocol, + &accepted); + if (status < B_OK) + return status; + + if (address && *_addressLength > 0) { + memcpy(address, &accepted->peer, min_c(*_addressLength, accepted->peer.ss_len)); + *_addressLength = accepted->peer.ss_len; + } + + *_acceptedSocket = accepted; + return B_OK; +} + + +int +socket_bind(net_socket *socket, const struct sockaddr *address, socklen_t addressLength) +{ + sockaddr empty; + if (address == NULL) { + // special - try to bind to an empty address, like INADDR_ANY + memset(&empty, 0, sizeof(sockaddr)); + empty.sa_len = sizeof(sockaddr); + empty.sa_family = socket->family; + + address = ∅ + addressLength = sizeof(sockaddr); + } + + if (socket->address.ss_len != 0) { + status_t status = socket->first_info->unbind(socket->first_protocol, + (sockaddr *)&socket->address); + if (status < B_OK) + return status; + } + + memcpy(&socket->address, address, sizeof(sockaddr)); + + status_t status = socket->first_info->bind(socket->first_protocol, + (sockaddr *)address); + if (status < B_OK) { + // clear address again, as binding failed + socket->address.ss_len = 0; + } + + return status; +} + + +int +socket_connect(net_socket *socket, const struct sockaddr *address, socklen_t addressLength) +{ + if (address == NULL || addressLength == 0) + return ENETUNREACH; + + if (socket->address.ss_len == 0) { + // try to bind first + status_t status = socket_bind(socket, NULL, 0); + if (status < B_OK) + return status; + } + + return socket->first_info->connect(socket->first_protocol, address); +} + + +int +socket_listen(net_socket *socket, int backlog) +{ + status_t status = socket->first_info->listen(socket->first_protocol, backlog); + if (status == B_OK) + socket->options |= SO_ACCEPTCONN; + + return status; +} + + +ssize_t +socket_send(net_socket *socket, const void *data, size_t length, int flags) +{ + if (socket->peer.ss_len == 0) + return EDESTADDRREQ; + + if (socket->address.ss_len == 0) { + // try to bind first + status_t status = socket_bind(socket, NULL, 0); + if (status < B_OK) + return status; + } + + // TODO: useful, maybe even computed header space! + net_buffer *buffer = gNetBufferModule.create(256); + if (buffer == NULL) + return ENOBUFS; + + // copy data into buffer + if (gNetBufferModule.append(buffer, data, length) < B_OK) { + gNetBufferModule.free(buffer); + return ENOBUFS; + } + + buffer->flags = flags; + //buffer->source = (sockaddr *)&socket->address; + //buffer->destination = (sockaddr *)&socket->peer; + memcpy(&buffer->source, &socket->address, socket->address.ss_len); + memcpy(&buffer->destination, &socket->peer, socket->peer.ss_len); + + status_t status = socket->first_info->send_data(socket->first_protocol, buffer); + if (status < B_OK) { + gNetBufferModule.free(buffer); + return status; + } + + return length; +} + + +ssize_t +socket_recv(net_socket *socket, void *data, size_t length, int flags) +{ + net_buffer *buffer; + ssize_t status = socket->first_info->read_data( + socket->first_protocol, length, flags, &buffer); + if (status < B_OK) + return status; + + // if 0 bytes we're received, no buffer will be created + if (buffer == NULL) + return 0; + + ssize_t bytesReceived = buffer->size; + gNetBufferModule.read(buffer, 0, data, bytesReceived); + gNetBufferModule.free(buffer); + + return bytesReceived; +} + + +status_t +socket_spawn_pending(net_socket *_parent, net_socket **_socket) +{ + net_socket_private *parent = (net_socket_private *)_parent; + + BenaphoreLocker locker(parent->lock); + + // We actually accept more pending connections to compensate for those + // that never complete, and also make sure at least a single connection + // can always be accepted + if (parent->child_count > 3 * parent->max_backlog / 2) + return ENOBUFS; + + net_socket_private *socket; + status_t status = socket_create(parent->family, parent->type, parent->protocol, + (net_socket **)&socket); + if (status < B_OK) + return status; + + // inherit parent's properties + socket->send = parent->send; + socket->receive = parent->receive; + socket->options = parent->options & ~SO_ACCEPTCONN; + socket->linger = parent->linger; + memcpy(&socket->address, &parent->address, parent->address.ss_len); + memcpy(&socket->peer, &parent->peer, parent->peer.ss_len); + + // add to the parent's list of pending connections + list_add_item(&parent->pending_children, socket); + socket->parent = parent; + parent->child_count++; + + *_socket = socket; + return B_OK; +} + + +status_t +socket_dequeue_connected(net_socket *_parent, net_socket **_socket) +{ + net_socket_private *parent = (net_socket_private *)_parent; + + benaphore_lock(&parent->lock); + + net_socket *socket = (net_socket *)list_remove_head_item(&parent->connected_children); + if (socket != NULL) { + socket->parent = NULL; + parent->child_count--; + *_socket = socket; + } + + benaphore_unlock(&parent->lock); + return socket != NULL ? B_OK : B_ENTRY_NOT_FOUND; +} + + +ssize_t +socket_count_connected(net_socket *_parent) +{ + net_socket_private *parent = (net_socket_private *)_parent; + + BenaphoreLocker _(parent->lock); + + ssize_t count = 0; + void *item = NULL; + while ((item = list_get_next_item(&parent->connected_children, + item)) != NULL) { + count++; + } + + return count; +} + + +status_t +socket_set_max_backlog(net_socket *_socket, uint32 backlog) +{ + net_socket_private *socket = (net_socket_private *)_socket; + + // we enforce an upper limit of connections waiting to be accepted + if (backlog > 256) + backlog = 256; + + benaphore_lock(&socket->lock); + + // first remove the pending connections, then the already connected ones as needed + net_socket *child; + while (socket->child_count > backlog + && (child = (net_socket *)list_remove_tail_item(&socket->pending_children)) != NULL) { + child->parent = NULL; + socket->child_count--; + } + while (socket->child_count > backlog + && (child = (net_socket *)list_remove_tail_item(&socket->connected_children)) != NULL) { + child->parent = NULL; + socket_delete(child); + socket->child_count--; + } + + socket->max_backlog = backlog; + benaphore_unlock(&socket->lock); + return B_OK; +} + + +/*! + The socket has been connected. It will be moved to the connected queue + of its parent socket. +*/ +status_t +socket_connected(net_socket *socket) +{ + net_socket_private *parent = (net_socket_private *)socket->parent; + if (parent == NULL) + return B_BAD_VALUE; + + benaphore_lock(&parent->lock); + + list_remove_item(&parent->pending_children, socket); + list_add_item(&parent->connected_children, socket); + + benaphore_unlock(&parent->lock); + return B_OK; +} + + +status_t +socket_notify(net_socket *_socket, uint8 event, int32 value) +{ + net_socket_private *socket = (net_socket_private *)_socket; + + benaphore_lock(&socket->lock); + + bool notify = true; + + switch (event) { + case B_SELECT_READ: + { + if ((ssize_t)socket->receive.low_water_mark > value && value >= B_OK) + notify = false; + break; + } + case B_SELECT_WRITE: + { + if ((ssize_t)socket->send.low_water_mark > value && value >= B_OK) + notify = false; + break; + } + case B_SELECT_ERROR: + socket->error = value; + break; + } + + if (notify) + ; + + benaphore_unlock(&socket->lock); + return B_OK; +} + + +net_socket_module_info gNetSocketModule = { + { + NET_SOCKET_MODULE_NAME, + 0, + std_ops + }, + NULL, //socket_open, + NULL, //socket_close, + NULL, //socket_free, + + NULL, //socket_readv, + NULL, //socket_writev, + NULL, //socket_control, + + NULL, //socket_read_avail, + NULL, //socket_send_avail, + + NULL, //socket_send_data, + NULL, //socket_receive_data, + + NULL, //get_option, + NULL, //set_option, + NULL, //socket_get_next_stat, + + // connections + socket_spawn_pending, + socket_delete, + socket_dequeue_connected, + socket_count_connected, + socket_set_max_backlog, + socket_connected, + + // notifications + NULL, //socket_request_notification, + NULL, //socket_cancel_notification, + socket_notify, + + // standard socket API + NULL, //socket_accept, + NULL, //socket_bind, + NULL, //socket_connect, + NULL, //socket_getpeername, + NULL, //socket_getsockname, + NULL, //socket_getsockopt, + NULL, //socket_listen, + NULL, //socket_recv, + NULL, //socket_send, + NULL, //socket_setsockopt, + NULL, //socket_shutdown, +}; + + +// #pragma mark - protocol + + +net_protocol* +init_protocol(net_socket** _socket) +{ + net_socket *socket; + status_t status = socket_create(AF_INET, SOCK_STREAM, IPPROTO_TCP, &socket); + if (status < B_OK) + return NULL; + + status = socket->first_info->open(socket->first_protocol); + if (status < B_OK) { + fprintf(stderr, "tcp_tester: cannot open client: %s\n", strerror(status)); + socket_delete(socket); + return NULL; + } + + *_socket = socket; + return socket->first_protocol; +} + + +void +close_protocol(net_protocol* protocol) +{ + gTCPModule->close(protocol); + gTCPModule->free(protocol); + gTCPModule->uninit_protocol(protocol); +} + + +// #pragma mark - datalink + + +status_t +datalink_send_data(struct net_route *route, net_buffer *buffer) +{ + struct context* context = (struct context*)route->gateway; + + context->lock.Lock(); + list_add_item(&context->list, buffer); + context->lock.Unlock(); + + release_sem(context->wait_sem); + return B_OK; +} + + +status_t +datalink_send_datagram(net_protocol *protocol, net_domain *domain, + net_buffer *buffer) +{ + panic("called"); + return B_ERROR; +} + + +struct net_route * +get_route(struct net_domain *_domain, const struct sockaddr *address) +{ + if (is_server(address)) { + // to the server + return &sServerContext.route; + } + + return &sClientContext.route; +} + + +net_datalink_module_info gNetDatalinkModule = { + { + NET_DATALINK_MODULE_NAME, + 0, + std_ops + }, + + NULL, //datalink_control, + datalink_send_data, + datalink_send_datagram, + + NULL, //is_local_address, + NULL, //datalink_get_interface, + NULL, //datalink_get_interface_with_address, + + NULL, //add_route, + NULL, //remove_route, + get_route, + NULL, //put_route, + NULL, //register_route_info, + NULL, //unregister_route_info, + NULL, //update_route_info +}; + + +// #pragma mark - domain + + +status_t +domain_open(net_protocol *protocol) +{ + return B_OK; +} + + +status_t +domain_close(net_protocol *protocol) +{ + return B_OK; +} + + +status_t +domain_free(net_protocol *protocol) +{ + return B_OK; +} + + +status_t +domain_connect(net_protocol *protocol, const struct sockaddr *address) +{ + return B_ERROR; +} + + +status_t +domain_accept(net_protocol *protocol, struct net_socket **_acceptedSocket) +{ + return EOPNOTSUPP; +} + + +status_t +domain_control(net_protocol *protocol, int level, int option, void *value, + size_t *_length) +{ + return B_ERROR; +} + + +status_t +domain_bind(net_protocol *protocol, const struct sockaddr *address) +{ + return B_OK; +} + + +status_t +domain_unbind(net_protocol *protocol, struct sockaddr *address) +{ + return B_OK; +} + + +status_t +domain_listen(net_protocol *protocol, int count) +{ + return EOPNOTSUPP; +} + + +status_t +domain_shutdown(net_protocol *protocol, int direction) +{ + return EOPNOTSUPP; +} + + +status_t +domain_send_data(net_protocol *protocol, net_buffer *buffer) +{ + // find route + struct net_route *route = get_route(&sDomain, (sockaddr *)&buffer->destination); + if (route == NULL) + return ENETUNREACH; + + return datalink_send_data(route, buffer); +} + + +status_t +domain_send_routed_data(net_protocol *protocol, struct net_route *route, + net_buffer *buffer) +{ + return datalink_send_data(route, buffer); +} + + +ssize_t +domain_send_avail(net_protocol *protocol) +{ + return B_ERROR; +} + + +status_t +domain_read_data(net_protocol *protocol, size_t numBytes, uint32 flags, + net_buffer **_buffer) +{ + return B_ERROR; +} + + +ssize_t +domain_read_avail(net_protocol *protocol) +{ + return B_ERROR; +} + + +struct net_domain * +domain_get_domain(net_protocol *protocol) +{ + return &sDomain; +} + + +size_t +domain_get_mtu(net_protocol *protocol, const struct sockaddr *address) +{ + return 1480; + // 1500 ethernet - IPv4 header +} + + +status_t +domain_receive_data(net_buffer *buffer) +{ + static bigtime_t lastTime = 0; + + uint32 packetNumber = atomic_add(&sPacketNumber, 1); + + bool drop = false; + if (sDropList.find(packetNumber) != sDropList.end() + || (sRandomDrop > 0.0 && (1.0 * rand() / RAND_MAX) > sRandomDrop)) + drop = true; + + if (!drop && (sRoundTripTime > 0 || sRandomRoundTrip || sIncreasingRoundTrip)) { + bigtime_t add = 0; + if (sRandomRoundTrip) + add = (bigtime_t)(1.0 * rand() / RAND_MAX * 500000) - 250000; + if (sIncreasingRoundTrip) + sRoundTripTime += (bigtime_t)(1.0 * rand() / RAND_MAX * 150000); + + snooze(sRoundTripTime / 2 + add); + } + + if (sTCPDump) { + NetBufferHeaderReader bufferHeader(buffer); + if (bufferHeader.Status() < B_OK) + return bufferHeader.Status(); + + tcp_header &header = bufferHeader.Data(); + + bigtime_t now = system_time(); + if (lastTime == 0) + lastTime = now; + + printf("\33[0m% 3ld %8.6f (%8.6f) ", packetNumber, (now - sStartTime) / 1000000.0, + (now - lastTime) / 1000000.0); + lastTime = now; + + if (is_server((sockaddr *)&buffer->source)) + printf("\33[31mserver > client: "); + else + printf("client > server: "); + + int32 length = buffer->size - header.HeaderLength(); + + if ((header.flags & TCP_FLAG_PUSH) != 0) + putchar('P'); + if ((header.flags & TCP_FLAG_SYNCHRONIZE) != 0) + putchar('S'); + if ((header.flags & TCP_FLAG_FINISH) != 0) + putchar('F'); + if ((header.flags & TCP_FLAG_RESET) != 0) + putchar('R'); + if ((header.flags + & (TCP_FLAG_SYNCHRONIZE | TCP_FLAG_FINISH | TCP_FLAG_PUSH | TCP_FLAG_RESET)) == 0) + putchar('.'); + + printf(" %lu:%lu (%lu)", header.Sequence(), header.Sequence() + length, length); + if ((header.flags & TCP_FLAG_ACKNOWLEDGE) != 0) + printf(" ack %lu", header.Acknowledge()); + + printf(" win %u", header.AdvertisedWindow()); + + if (header.HeaderLength() > sizeof(tcp_header)) { + int32 size = header.HeaderLength() - sizeof(tcp_header); + + tcp_option *option; + uint8 optionsBuffer[1024]; + if (gBufferModule->direct_access(buffer, sizeof(tcp_header), + size, (void **)&option) != B_OK) { + if (size > 1024) { + printf("options too large to take into account (%ld bytes)\n", size); + size = 1024; + } + + gBufferModule->read(buffer, sizeof(tcp_header), optionsBuffer, size); + option = (tcp_option *)optionsBuffer; + } + + while (size > 0) { + uint32 length = 1; + switch (option->kind) { + case TCP_OPTION_END: + case TCP_OPTION_NOP: + break; + case TCP_OPTION_MAX_SEGMENT_SIZE: [... truncated: 622 lines follow ...] From axeld at mail.berlios.de Sun Oct 21 22:44:20 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sun, 21 Oct 2007 22:44:20 +0200 Subject: [Haiku-commits] r22646 - haiku/trunk/headers/private/kernel/slab Message-ID: <200710212044.l9LKiKDr009736@sheep.berlios.de> Author: axeld Date: 2007-10-21 22:44:19 +0200 (Sun, 21 Oct 2007) New Revision: 22646 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22646&view=rev Removed: haiku/trunk/headers/private/kernel/slab/Base.h Modified: haiku/trunk/headers/private/kernel/slab/Slab.h Log: Moved Base.h into Slab.h, and removed Base.h. Deleted: haiku/trunk/headers/private/kernel/slab/Base.h Modified: haiku/trunk/headers/private/kernel/slab/Slab.h =================================================================== --- haiku/trunk/headers/private/kernel/slab/Slab.h 2007-10-21 20:25:54 UTC (rev 22645) +++ haiku/trunk/headers/private/kernel/slab/Slab.h 2007-10-21 20:44:19 UTC (rev 22646) @@ -8,7 +8,54 @@ #ifndef _SLAB_SLAB_H_ #define _SLAB_SLAB_H_ -#include + #include +#include +#include + + +enum { + /* create_object_cache_etc flags */ + CACHE_NO_DEPOT = 1 << 0, + CACHE_UNLOCKED_PAGES = 1 << 1, + + /* object_cache_alloc flags */ + CACHE_DONT_SLEEP = 1 << 8, + + /* internal */ + CACHE_DURING_BOOT = 1 << 31 +}; + +typedef struct object_cache object_cache; + +typedef status_t (*object_cache_constructor)(void *cookie, void *object); +typedef void (*object_cache_destructor)(void *cookie, void *object); +typedef void (*object_cache_reclaimer)(void *cookie, int32 level); + + +#ifdef __cplusplus +extern "C" { #endif + +object_cache *create_object_cache(const char *name, size_t object_size, + size_t alignment, void *cookie, object_cache_constructor constructor, + object_cache_destructor); +object_cache *create_object_cache_etc(const char *name, size_t object_size, + size_t alignment, size_t max_byte_usage, uint32 flags, void *cookie, + object_cache_constructor constructor, object_cache_destructor destructor, + object_cache_reclaimer reclaimer); + +void delete_object_cache(object_cache *cache); + +void *object_cache_alloc(object_cache *cache, uint32 flags); +void object_cache_free(object_cache *cache, void *object); + +status_t object_cache_reserve(object_cache *cache, size_t object_count, + uint32 flags); + +#ifdef __cplusplus +} +#endif + +#endif /* _SLAB_SLAB_H_ */ From axeld at mail.berlios.de Sun Oct 21 22:56:35 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sun, 21 Oct 2007 22:56:35 +0200 Subject: [Haiku-commits] r22647 - in haiku/trunk: headers/private/kernel/slab src/system/kernel/slab Message-ID: <200710212056.l9LKuZdV012450@sheep.berlios.de> Author: axeld Date: 2007-10-21 22:56:34 +0200 (Sun, 21 Oct 2007) New Revision: 22647 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22647&view=rev Modified: haiku/trunk/headers/private/kernel/slab/Slab.h haiku/trunk/src/system/kernel/slab/Slab.cpp Log: Slab.h no longer includes Depot.h. Modified: haiku/trunk/headers/private/kernel/slab/Slab.h =================================================================== --- haiku/trunk/headers/private/kernel/slab/Slab.h 2007-10-21 20:44:19 UTC (rev 22646) +++ haiku/trunk/headers/private/kernel/slab/Slab.h 2007-10-21 20:56:34 UTC (rev 22647) @@ -9,8 +9,6 @@ #define _SLAB_SLAB_H_ -#include - #include #include Modified: haiku/trunk/src/system/kernel/slab/Slab.cpp =================================================================== --- haiku/trunk/src/system/kernel/slab/Slab.cpp 2007-10-21 20:44:19 UTC (rev 22646) +++ haiku/trunk/src/system/kernel/slab/Slab.cpp 2007-10-21 20:56:34 UTC (rev 22647) @@ -6,7 +6,6 @@ * Hugo Santos, hugosantos at gmail.com */ -#include #include "slab_private.h" @@ -17,7 +16,9 @@ #include +#include #include +#include #include #include #include From axeld at mail.berlios.de Sun Oct 21 23:20:38 2007 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sun, 21 Oct 2007 23:20:38 +0200 Subject: [Haiku-commits] r22648 - haiku/trunk/src/add-ons/accelerants/common Message-ID: <200710212120.l9LLKclC016887@sheep.berlios.de> Author: axeld Date: 2007-10-21 23:20:38 +0200 (Sun, 21 Oct 2007) New Revision: 22648 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22648&view=rev Modified: haiku/trunk/src/add-ons/accelerants/common/create_display_modes.cpp Log: * Corrected mode creation; can't reuse the EDID values as is. * The sync flags still aren't handled correctly, though. Modified: haiku/trunk/src/add-ons/accelerants/common/create_display_modes.cpp =================================================================== --- haiku/trunk/src/add-ons/accelerants/common/create_display_modes.cpp 2007-10-21 20:56:34 UTC (rev 22647) +++ haiku/trunk/src/add-ons/accelerants/common/create_display_modes.cpp 2007-10-21 21:20:38 UTC (rev 22648) @@ -209,14 +209,16 @@ display_mode mode; mode.timing.pixel_clock = timing.pixel_clock * 10; mode.timing.h_display = timing.h_active; - mode.timing.h_sync_start = timing.h_blank; - mode.timing.h_sync_end = timing.h_sync_off; - mode.timing.h_total = timing.h_sync_width; + mode.timing.h_sync_start = timing.h_active + timing.h_sync_off; + mode.timing.h_sync_end = mode.timing.h_sync_start + timing.h_sync_width; + mode.timing.h_total = timing.h_active + timing.h_blank; mode.timing.v_display = timing.v_active; - mode.timing.v_sync_start = timing.v_blank; - mode.timing.v_sync_end = timing.v_sync_off; - mode.timing.v_total = timing.v_sync_width; + mode.timing.v_sync_start = timing.v_active + timing.v_sync_off; + mode.timing.v_sync_end = mode.timing.v_sync_start + timing.v_sync_width; + mode.timing.v_total = timing.v_active + timing.v_blank; mode.timing.flags = POSITIVE_SYNC; + if (timing.interlaced) + mode.timing.flags |= B_TIMING_INTERLACED; mode.space = B_RGB32; mode.virtual_width = timing.h_active; mode.virtual_height = timing.v_active; From urnenfel at tiscali.es Mon Oct 22 00:22:09 2007 From: urnenfel at tiscali.es (Oliver Ruiz Dorantes) Date: Mon, 22 Oct 2007 00:22:09 +0200 Subject: [Haiku-commits] r22642 - in haiku/trunk/src/kits: . bluetooth Message-ID: Hi! >Anyway, would you mind having a look at our coding style? Sure, please don't hesitate comment any single mistake in the style as being in more than 2,3 projects will lead to these problems out of intention until I get used. >- we do not indent because of a namespace >- brackets of functions/methods go to the next line sweet... although no info maybe in the guidelines about namespace identation? >- method names start with upper case Here will not be so easy: I started searching for Bluetooth APIs and the most easy and friendly one I found was the JSR82. If someone knows another one, there is still time for a change, let me know!:) So, as said in the commit I am implementing an existing API, we should attach to the names as the easy solution, or wrapping each class... overloading methods...? What do you think? bye -- Oliver, http://urnenfeld.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From mmu_man at mail.berlios.de Mon Oct 22 01:42:11 2007 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Mon, 22 Oct 2007 01:42:11 +0200 Subject: [Haiku-commits] r22649 - in haiku/trunk/headers/private/kernel/arch: . m68k Message-ID: <200710212342.l9LNgBl3018386@sheep.berlios.de> Author: mmu_man Date: 2007-10-22 01:42:09 +0200 (Mon, 22 Oct 2007) New Revision: 22649 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22649&view=rev Added: haiku/trunk/headers/private/kernel/arch/m68k/ haiku/trunk/headers/private/kernel/arch/m68k/arch_config.h haiku/trunk/headers/private/kernel/arch/m68k/arch_cpu.h haiku/trunk/headers/private/kernel/arch/m68k/arch_elf.h haiku/trunk/headers/private/kernel/arch/m68k/arch_int.h haiku/trunk/headers/private/kernel/arch/m68k/arch_kernel.h haiku/trunk/headers/private/kernel/arch/m68k/arch_kernel_args.h haiku/trunk/headers/private/kernel/arch/m68k/arch_mmu.h haiku/trunk/headers/private/kernel/arch/m68k/arch_platform.h haiku/trunk/headers/private/kernel/arch/m68k/arch_real_time_data.h haiku/trunk/headers/private/kernel/arch/m68k/arch_system_info.h haiku/trunk/headers/private/kernel/arch/m68k/arch_thread.h haiku/trunk/headers/private/kernel/arch/m68k/arch_thread_types.h haiku/trunk/headers/private/kernel/arch/m68k/arch_user_debugger.h haiku/trunk/headers/private/kernel/arch/m68k/arch_vm.h haiku/trunk/headers/private/kernel/arch/m68k/arch_vm_translation_map.h haiku/trunk/headers/private/kernel/arch/m68k/arch_vm_types.h haiku/trunk/headers/private/kernel/arch/m68k/cpu.h haiku/trunk/headers/private/kernel/arch/m68k/ktypes.h haiku/trunk/headers/private/kernel/arch/m68k/stage2_priv.h haiku/trunk/headers/private/kernel/arch/m68k/types.h Log: Headers (unfinished) for an m68k port (yes I do know it's useless, it's just for the l33t factor). Based on ppc/x86 headers from r22648. Added: haiku/trunk/headers/private/kernel/arch/m68k/arch_config.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/m68k/arch_config.h 2007-10-21 21:20:38 UTC (rev 22648) +++ haiku/trunk/headers/private/kernel/arch/m68k/arch_config.h 2007-10-21 23:42:09 UTC (rev 22649) @@ -0,0 +1,17 @@ +/* + * Copyright 2004, Axel D?rfler, axeld at pinc-software.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _KERNEL_ARCH_M68K_CONFIG_H +#define _KERNEL_ARCH_M68K_CONFIG_H + + +#define FUNCTION_CALL_PARAMETER_ALIGNMENT_TYPE unsigned int + +#define STACK_GROWS_DOWNWARDS + +//#define ATOMIC_FUNCS_ARE_SYSCALLS +#define ATOMIC64_FUNCS_ARE_SYSCALLS + + +#endif /* _KERNEL_ARCH_M68K_CONFIG_H */ Added: haiku/trunk/headers/private/kernel/arch/m68k/arch_cpu.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/m68k/arch_cpu.h 2007-10-21 21:20:38 UTC (rev 22648) +++ haiku/trunk/headers/private/kernel/arch/m68k/arch_cpu.h 2007-10-21 23:42:09 UTC (rev 22649) @@ -0,0 +1,258 @@ +/* +** Copyright 2003-2004, Axel D?rfler, axeld at pinc-software.de. All rights reserved. +** Distributed under the terms of the Haiku License. +*/ +#ifndef _KERNEL_ARCH_M68K_CPU_H +#define _KERNEL_ARCH_M68K_CPU_H + + +#include +#include + + +#define PAGE_SIZE 4096 + +struct iframe { + uint32 d7; + /* XXX: order depends on movem */ + uint32 a0; + /* 030 ex frame: */ + uint16 sr; + uint32 pc; + uint16 vector; /* [12:15] frame type */ + /* other stuff depending on frame type... do we really need that ? */ + union { + struct { + uint32 inst; + } format2 _PACKED; + struct { + uint32 inst; + uint16 intregs[4]; + } format9 _PACKED; + struct { + uint16 intregs[1]; + uint16 ssw; + uint16 instpipe_c; + uint16 instpipe_b; + uint32 faultaddr; + uint16 intregs2[2]; + uint32 dataout; + uint16 intregs3[2]; + } formata _PACKED; + struct { + uint16 intregs[1]; + uint16 ssw; + uint16 instpipe_c; + uint16 instpipe_b; + uint32 faultaddr; + uint16 intregs2[2]; + uint32 dataout; + uint16 intregs3[4]; + uint32 stbaddr; + uint16 intregs4[2]; + uint32 datain; + uint16 intregs5[3]; + uint16 intinfo; + uint16 intregs6[18]; + } formatb _PACKED; + }; +/* uint32 vector; + uint32 srr0; + uint32 srr1; + uint32 dar; + uint32 dsisr; + uint32 lr; + uint32 cr; + uint32 xer; + uint32 ctr; + uint32 fpscr; + uint32 r31; + uint32 r30; + uint32 r29; + uint32 r28; + uint32 r27; + uint32 r26; + uint32 r25; + uint32 r24; + uint32 r23; + uint32 r22; + uint32 r21; + uint32 r20; + uint32 r19; + uint32 r18; + uint32 r17; + uint32 r16; + uint32 r15; + uint32 r14; + uint32 r13; + uint32 r12; + uint32 r11; + uint32 r10; + uint32 r9; + uint32 r8; + uint32 r7; + uint32 r6; + uint32 r5; + uint32 r4; + uint32 r3; + uint32 r2; + uint32 r1; + uint32 r0; + double f31; + double f30; + double f29; + double f28; + double f27; + double f26; + double f25; + double f24; + double f23; + double f22; + double f21; + double f20; + double f19; + double f18; + double f17; + double f16; + double f15; + double f14; + double f13; + double f12; + double f11; + double f10; + double f9; + double f8; + double f7; + double f6; + double f5; + double f4; + double f3; + double f2; + double f1; + double f0;*/ +} _PACKED; + +enum machine_state { + MSR_EXCEPTIONS_ENABLED = 1L << 15, // EE + MSR_PRIVILEGE_LEVEL = 1L << 14, // PR + MSR_FP_AVAILABLE = 1L << 13, // FP + MSR_MACHINE_CHECK_ENABLED = 1L << 12, // ME + MSR_EXCEPTION_PREFIX = 1L << 6, // IP + MSR_INST_ADDRESS_TRANSLATION = 1L << 5, // IR + MSR_DATA_ADDRESS_TRANSLATION = 1L << 4, // DR +}; + +struct block_address_translation; + +typedef struct arch_cpu_info { + int null; +} arch_cpu_info; + + +#ifdef __cplusplus +extern "C" { +#endif + +extern uint32 get_sdr1(void); +extern void set_sdr1(uint32 value); +extern uint32 get_sr(void *virtualAddress); +extern void set_sr(void *virtualAddress, uint32 value); +extern uint32 get_msr(void); +extern uint32 set_msr(uint32 value); +extern uint32 get_pvr(void); + +extern void set_ibat0(struct block_address_translation *bat); +extern void set_ibat1(struct block_address_translation *bat); +extern void set_ibat2(struct block_address_translation *bat); +extern void set_ibat3(struct block_address_translation *bat); +extern void set_dbat0(struct block_address_translation *bat); +extern void set_dbat1(struct block_address_translation *bat); +extern void set_dbat2(struct block_address_translation *bat); +extern void set_dbat3(struct block_address_translation *bat); + +extern void get_ibat0(struct block_address_translation *bat); +extern void get_ibat1(struct block_address_translation *bat); +extern void get_ibat2(struct block_address_translation *bat); +extern void get_ibat3(struct block_address_translation *bat); +extern void get_dbat0(struct block_address_translation *bat); +extern void get_dbat1(struct block_address_translation *bat); +extern void get_dbat2(struct block_address_translation *bat); +extern void get_dbat3(struct block_address_translation *bat); + +extern void reset_ibats(void); +extern void reset_dbats(void); + +//extern void sethid0(unsigned int val); +//extern unsigned int getl2cr(void); +//extern void setl2cr(unsigned int val); +extern long long get_time_base(void); + +void __m68k_setup_system_time(vint32 *cvFactor); + // defined in libroot: os/arch/system_time.c +int64 __m68k_get_time_base(void); + // defined in libroot: os/arch/system_time_asm.S + +extern void m68k_context_switch(void **_oldStackPointer, void *newStackPointer); + +extern bool m68k_set_fault_handler(addr_t *handlerLocation, addr_t handler) + __attribute__((noinline)); + +#ifdef __cplusplus +} +#endif + +#define eieio() asm volatile("eieio") +#define isync() asm volatile("isync") +#define tlbsync() asm volatile("tlbsync") +#define ppc_sync() asm volatile("sync") +#define tlbia() asm volatile("tlbia") +#define tlbie(addr) asm volatile("tlbie %0" :: "r" (addr)) + + +// PowerPC processor version (the upper 16 bits of the PVR). +enum m68k_processor_version { + MPC601 = 0x0001, + MPC603 = 0x0003, + MPC604 = 0x0004, + MPC602 = 0x0005, + MPC603e = 0x0006, + MPC603ev = 0x0007, + MPC750 = 0x0008, + MPC604ev = 0x0009, + MPC7400 = 0x000c, + MPC620 = 0x0014, + IBM403 = 0x0020, + IBM401A1 = 0x0021, + IBM401B2 = 0x0022, + IBM401C2 = 0x0023, + IBM401D2 = 0x0024, + IBM401E2 = 0x0025, + IBM401F2 = 0x0026, + IBM401G2 = 0x0027, + IBMPOWER3 = 0x0041, + MPC860 = 0x0050, + MPC8240 = 0x0081, + IBM405GP = 0x4011, + IBM405L = 0x4161, + IBM750FX = 0x7000, + MPC7450 = 0x8000, + MPC7455 = 0x8001, + MPC7457 = 0x8002, + MPC7447A = 0x8003, + MPC7448 = 0x8004, + MPC7410 = 0x800c, + MPC8245 = 0x8081, +}; + + +/* + Use of (some) special purpose registers. + + SPRG0: per CPU physical address pointer to an ppc_cpu_exception_context + structure + SPRG1: scratch + SPRG2: current struct thread* + SPRG3: TLS base pointer (only for userland threads) +*/ + +#endif /* _KERNEL_ARCH_PPC_CPU_H */ Added: haiku/trunk/headers/private/kernel/arch/m68k/arch_elf.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/m68k/arch_elf.h 2007-10-21 21:20:38 UTC (rev 22648) +++ haiku/trunk/headers/private/kernel/arch/m68k/arch_elf.h 2007-10-21 23:42:09 UTC (rev 22649) @@ -0,0 +1,49 @@ +/* +** Copyright 2003, Axel D?rfler, axeld at pinc-software.de. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ +#ifndef _KERNEL_ARCH_M68K_ELF_H +#define _KERNEL_ARCH_M68K_ELF_H + +/* relocation types */ + +#define R_PPC_NONE 0 +#define R_PPC_ADDR32 1 +#define R_PPC_ADDR24 2 +#define R_PPC_ADDR16 3 +#define R_PPC_ADDR16_LO 4 +#define R_PPC_ADDR16_HI 5 +#define R_PPC_ADDR16_HA 6 +#define R_PPC_ADDR14 7 +#define R_PPC_ADDR14_BRTAKEN 8 +#define R_PPC_ADDR14_BRNTAKEN 9 +#define R_PPC_REL24 10 +#define R_PPC_REL14 11 +#define R_PPC_REL14_BRTAKEN 12 +#define R_PPC_REL14_BRNTAKEN 13 +#define R_PPC_GOT16 14 +#define R_PPC_GOT16_LO 15 +#define R_PPC_GOT16_HI 16 +#define R_PPC_GOT16_HA 17 +#define R_PPC_PLTREL24 18 +#define R_PPC_COPY 19 +#define R_PPC_GLOB_DAT 20 +#define R_PPC_JMP_SLOT 21 +#define R_PPC_RELATIVE 22 +#define R_PPC_LOCAL24PC 23 +#define R_PPC_UADDR32 24 +#define R_PPC_UADDR16 25 +#define R_PPC_REL32 26 +#define R_PPC_PLT32 27 +#define R_PPC_PLTREL32 28 +#define R_PPC_PLT16_LO 29 +#define R_PPC_PLT16_HI 30 +#define R_PPC_PLT16_HA 31 +#define R_PPC_SDAREL16 32 +#define R_PPC_SECTOFF 33 +#define R_PPC_SECTOFF_LO 34 +#define R_PPC_SECTOFF_HI 35 +#define R_PPC_SECTOFF_HA 36 +#define R_PPC_ADDR30 37 + +#endif /* _KERNEL_ARCH_M68K_ELF_H */ Added: haiku/trunk/headers/private/kernel/arch/m68k/arch_int.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/m68k/arch_int.h 2007-10-21 21:20:38 UTC (rev 22648) +++ haiku/trunk/headers/private/kernel/arch/m68k/arch_int.h 2007-10-21 23:42:09 UTC (rev 22649) @@ -0,0 +1,46 @@ +/* + * Copyright 2005-2006, Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Axel D?rfler + * Ingo Weinhold + */ +#ifndef _KERNEL_ARCH_M68K_INT_H +#define _KERNEL_ARCH_M68K_INT_H + +#include + +#define NUM_IO_VECTORS 256 + +/* The sprg0 register of each CPU points to the physical address of such + a structure. So it is at hand in the early exception handling code. +*/ +struct m68k_cpu_exception_context { + void *kernel_handle_exception; // exception handler routine in the + // kernel + void *exception_context; // the virtual address of this + // structure + void *kernel_stack; // kernel stack for the current thread + + uint32 scratch[8]; // scratch memory for free use in the + // early exception handling code +}; + +#ifdef __cplusplus +extern "C" { +#endif + + +struct m68k_cpu_exception_context *m68k_get_cpu_exception_context(int cpu); + +void m68k_set_current_cpu_exception_context( + struct m68k_cpu_exception_context *context); + // only called once per CPU + + +#ifdef __cplusplus +} +#endif + +#endif /* _KERNEL_ARCH_M68K_INT_H */ Added: haiku/trunk/headers/private/kernel/arch/m68k/arch_kernel.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/m68k/arch_kernel.h 2007-10-21 21:20:38 UTC (rev 22648) +++ haiku/trunk/headers/private/kernel/arch/m68k/arch_kernel.h 2007-10-21 23:42:09 UTC (rev 22649) @@ -0,0 +1,30 @@ +/* +** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. +** Distributed under the terms of the NewOS License. +*/ +#ifndef _KERNEL_ARCH_M68K_KERNEL_H +#define _KERNEL_ARCH_M68K_KERNEL_H + +#include + +// memory layout +#define KERNEL_BASE 0x80000000 +#define KERNEL_SIZE 0x80000000 +#define KERNEL_TOP (KERNEL_BASE + (KERNEL_SIZE - 1)) + +/* +** User space layout is a little special: +** The user space does not completely cover the space not covered by the kernel. +** This is accomplished by starting user space at 1Mb and running to 64kb short of kernel space. +** The lower 1Mb reserved spot makes it easy to find null pointer references and guarantees a +** region wont be placed there. The 64kb region assures a user space thread cannot pass +** a buffer into the kernel as part of a syscall that would cross into kernel space. +*/ +#define USER_BASE 0x100000 +#define USER_SIZE (0x80000000 - (0x10000 + 0x100000)) +#define USER_TOP (USER_BASE + USER_SIZE) + +#define USER_STACK_REGION 0x70000000 +#define USER_STACK_REGION_SIZE (USER_BASE + (USER_SIZE - USER_STACK_REGION)) + +#endif /* _KERNEL_ARCH_M68K_KERNEL_H */ Added: haiku/trunk/headers/private/kernel/arch/m68k/arch_kernel_args.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/m68k/arch_kernel_args.h 2007-10-21 21:20:38 UTC (rev 22648) +++ haiku/trunk/headers/private/kernel/arch/m68k/arch_kernel_args.h 2007-10-21 23:42:09 UTC (rev 22649) @@ -0,0 +1,34 @@ +/* +** Copyright 2003, Axel D?rfler, axeld at pinc-software.de. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ +#ifndef KERNEL_ARCH_M68K_KERNEL_ARGS_H +#define KERNEL_ARCH_M68K_KERNEL_ARGS_H + +#ifndef KERNEL_BOOT_KERNEL_ARGS_H +# error This file is included from only +#endif + +#define _PACKED __attribute__((packed)) + +//#define MAX_VIRTUAL_RANGES_TO_KEEP 32 + +// kernel args +typedef struct { + // architecture specific + uint64 cpu_frequency; + uint64 bus_frequency; + uint64 time_base_frequency; + + addr_range page_table; // virtual address and size of the page table + addr_range exception_handlers; + addr_range framebuffer; // maps where the framebuffer is located, in physical memory + int screen_x, screen_y, screen_depth; + + // The virtual ranges we want to keep in the kernel. E.g. those belonging + // to the Open Firmware. +// uint32 num_virtual_ranges_to_keep; +// addr_range virtual_ranges_to_keep[MAX_VIRTUAL_RANGES_TO_KEEP]; +} arch_kernel_args; + +#endif /* KERNEL_ARCH_M68K_KERNEL_ARGS_H */ Added: haiku/trunk/headers/private/kernel/arch/m68k/arch_mmu.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/m68k/arch_mmu.h 2007-10-21 21:20:38 UTC (rev 22648) +++ haiku/trunk/headers/private/kernel/arch/m68k/arch_mmu.h 2007-10-21 23:42:09 UTC (rev 22649) @@ -0,0 +1,149 @@ +/* +** Copyright 2003, Axel D?rfler, axeld at pinc-software.de. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ +#ifndef _KERNEL_ARCH_M68K_MMU_H +#define _KERNEL_ARCH_M68K_MMU_H + + +#include +#include + +#include + + +/*** BAT - block address translation ***/ + +enum bat_length { + BAT_LENGTH_128kB = 0x0000, + BAT_LENGTH_256kB = 0x0001, + BAT_LENGTH_512kB = 0x0003, + BAT_LENGTH_1MB = 0x0007, + BAT_LENGTH_2MB = 0x000f, + BAT_LENGTH_4MB = 0x001f, + BAT_LENGTH_8MB = 0x003f, + BAT_LENGTH_16MB = 0x007f, + BAT_LENGTH_32MB = 0x00ff, + BAT_LENGTH_64MB = 0x01ff, + BAT_LENGTH_128MB = 0x03ff, + BAT_LENGTH_256MB = 0x07ff, +}; + +enum bat_protection { + BAT_READ_ONLY = 1, + BAT_READ_WRITE = 2, +}; + +struct block_address_translation { + // upper 32 bit + uint32 page_index : 15; // BEPI, block effective page index + uint32 _reserved0 : 4; + uint32 length : 11; + uint32 kernel_valid : 1; // Vs, Supervisor-state valid + uint32 user_valid : 1; // Vp, User-state valid + // lower 32 bit + uint32 physical_block_number : 15; // BPRN + uint32 write_through : 1; // WIMG + uint32 caching_inhibited : 1; + uint32 memory_coherent : 1; + uint32 guarded : 1; + uint32 _reserved1 : 1; + uint32 protection : 2; + + block_address_translation() + { + Clear(); + } + + void SetVirtualAddress(void *address) + { + page_index = uint32(address) >> 17; + } + + void SetPhysicalAddress(void *address) + { + physical_block_number = uint32(address) >> 17; + } + + void Clear() + { + memset((void *)this, 0, sizeof(block_address_translation)); + } +}; + +struct segment_descriptor { + uint32 type : 1; // 0 for page translation descriptors + uint32 kernel_protection_key : 1; // Ks, Supervisor-state protection key + uint32 user_protection_key : 1; // Kp, User-state protection key + uint32 no_execute_protection : 1; + uint32 _reserved : 4; + uint32 virtual_segment_id : 24; + + segment_descriptor() + { + Clear(); + } + + segment_descriptor(uint32 value) + { + *((uint32 *)this) = value; + } + + void Clear() + { + memset((void *)this, 0, sizeof(segment_descriptor)); + } +}; + + +/*** PTE - page table entry ***/ + +enum pte_protection { + PTE_READ_ONLY = 3, + PTE_READ_WRITE = 2, +}; + +struct page_table_entry { + // upper 32 bit + uint32 valid : 1; + uint32 virtual_segment_id : 24; + uint32 secondary_hash : 1; + uint32 abbr_page_index : 6; + // lower 32 bit + uint32 physical_page_number : 20; + uint32 _reserved0 : 3; + uint32 referenced : 1; + uint32 changed : 1; + uint32 write_through : 1; // WIMG + uint32 caching_inhibited : 1; + uint32 memory_coherent : 1; + uint32 guarded : 1; + uint32 _reserved1 : 1; + uint32 page_protection : 2; + + static uint32 PrimaryHash(uint32 virtualSegmentID, uint32 virtualAddress); + static uint32 SecondaryHash(uint32 virtualSegmentID, uint32 virtualAddress); + static uint32 SecondaryHash(uint32 primaryHash); +}; + +struct page_table_entry_group { + struct page_table_entry entry[8]; +}; + +extern void m68k_get_page_table(page_table_entry_group **_pageTable, size_t *_size); +extern void m68k_set_page_table(page_table_entry_group *pageTable, size_t size); + +static inline segment_descriptor +m68k_get_segment_register(void *virtualAddress) +{ + return (segment_descriptor)get_sr(virtualAddress); +} + + +static inline void +m68k_set_segment_register(void *virtualAddress, segment_descriptor segment) +{ + set_sr(virtualAddress, *(uint32 *)&segment); +} + +#endif /* _KERNEL_ARCH_M68K_MMU_H */ Added: haiku/trunk/headers/private/kernel/arch/m68k/arch_platform.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/m68k/arch_platform.h 2007-10-21 21:20:38 UTC (rev 22648) +++ haiku/trunk/headers/private/kernel/arch/m68k/arch_platform.h 2007-10-21 23:42:09 UTC (rev 22649) @@ -0,0 +1,52 @@ +/* + * Copyright 2006, Ingo Weinhold . + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef _KERNEL_M68K_ARCH_PLATFORM_H +#define _KERNEL_M68K_ARCH_PLATFORM_H + +#include + +struct real_time_data; + +enum m68k_platform_type { + M68K_PLATFORM_AMIGA = 0, + M68K_PLATFORM_APPLE, + M68K_PLATFORM_ATARI /* Falcon */ +}; + +namespace BPrivate { + +class M68KPlatform { +public: + M68KPlatform(m68k_platform_type platformType); + virtual ~M68KPlatform(); + + static M68KPlatform *Default(); + + inline m68k_platform_type PlatformType() const { return fPlatformType; } + + virtual status_t Init(struct kernel_args *kernelArgs) = 0; + virtual status_t InitSerialDebug(struct kernel_args *kernelArgs) = 0; + virtual status_t InitPostVM(struct kernel_args *kernelArgs) = 0; + virtual status_t InitRTC(struct kernel_args *kernelArgs, + struct real_time_data *data) = 0; + + virtual char SerialDebugGetChar() = 0; + virtual void SerialDebugPutChar(char c) = 0; + + virtual void SetHardwareRTC(uint32 seconds) = 0; + virtual uint32 GetHardwareRTC() = 0; + + virtual void ShutDown(bool reboot) = 0; + +private: + m68k_platform_type fPlatformType; +}; + +} // namespace BPrivate + +using BPrivate::M68KPlatform; + + +#endif // _KERNEL_M68K_ARCH_PLATFORM_H Added: haiku/trunk/headers/private/kernel/arch/m68k/arch_real_time_data.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/m68k/arch_real_time_data.h 2007-10-21 21:20:38 UTC (rev 22648) +++ haiku/trunk/headers/private/kernel/arch/m68k/arch_real_time_data.h 2007-10-21 23:42:09 UTC (rev 22649) @@ -0,0 +1,36 @@ +/* + * Copyright 2006, Ingo Weinhold . + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef _KERNEL_ARCH_REAL_TIME_DATA_H +#define _KERNEL_ARCH_REAL_TIME_DATA_H + +#include +#include + + +struct ppc_real_time_data { + vint64 system_time_offset; +}; + +struct arch_real_time_data { + struct ppc_real_time_data data[2]; + vint32 system_time_conversion_factor; + vint32 version; + // Since there're no cheap atomic_{set,get,add}64() on PPC 32 (i.e. one + // that doesn't involve a syscall), we can't have just a single + // system_time_offset and set/get it atomically. + // That's why have our data twice. One set is current (indexed by + // version % 2). When setting the offset, we do that with disabled + // interrupts and protected by a spinlock. We write the new values + // into the other array element and increment the version. + // A reader first reads the version, then the date of interest, and + // finally rechecks the version. If it hasn't changed in the meantime, + // the read value is fine, otherwise it runs the whole procedure again. + // + // system_time_conversion_factor is currently consider constant, + // although that is not necessarily true. We simply don't support + // changing conversion factors at the moment. +}; + +#endif /* _KERNEL_ARCH_REAL_TIME_DATA_H */ Added: haiku/trunk/headers/private/kernel/arch/m68k/arch_system_info.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/m68k/arch_system_info.h 2007-10-21 21:20:38 UTC (rev 22648) +++ haiku/trunk/headers/private/kernel/arch/m68k/arch_system_info.h 2007-10-21 23:42:09 UTC (rev 22649) @@ -0,0 +1,12 @@ +/* + * Copyright 2005, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _KERNEL_ARCH_M68K_SYSTEM_INFO_H +#define _KERNEL_ARCH_M68K_SYSTEM_INFO_H + + +/* nothing to be seen here yet */ + + +#endif /* _KRENEL_ARCH_M68K_SYSTEM_INFO_H */ Added: haiku/trunk/headers/private/kernel/arch/m68k/arch_thread.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/m68k/arch_thread.h 2007-10-21 21:20:38 UTC (rev 22648) +++ haiku/trunk/headers/private/kernel/arch/m68k/arch_thread.h 2007-10-21 23:42:09 UTC (rev 22649) @@ -0,0 +1,44 @@ +/* + * Copyright 2003-2006, Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Axel D?rfler + * Ingo Weinhold + */ +#ifndef _KERNEL_ARCH_M68K_THREAD_H +#define _KERNEL_ARCH_M68K_THREAD_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +void m68k_push_iframe(struct iframe_stack *stack, struct iframe *frame); +void m68k_pop_iframe(struct iframe_stack *stack); +struct iframe *m68k_get_user_iframe(void); + + +extern inline struct thread * +arch_thread_get_current_thread(void) +{ + struct thread *t; + asm volatile("mfsprg2 %0" : "=r"(t)); + return t; +} + + +extern inline void +arch_thread_set_current_thread(struct thread *t) +{ + asm volatile("mtsprg2 %0" : : "r"(t)); +} + + +#ifdef __cplusplus +} +#endif + + +#endif /* _KERNEL_ARCH_M68K_THREAD_H */ Added: haiku/trunk/headers/private/kernel/arch/m68k/arch_thread_types.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/m68k/arch_thread_types.h 2007-10-21 21:20:38 UTC (rev 22648) +++ haiku/trunk/headers/private/kernel/arch/m68k/arch_thread_types.h 2007-10-21 23:42:09 UTC (rev 22649) @@ -0,0 +1,38 @@ +/* +** Copyright 2001, Travis Geiselbrecht. All rights reserved. +** Distributed under the terms of the NewOS License. +*/ +#ifndef KERNEL_ARCH_M68K_THREAD_TYPES_H +#define KERNEL_ARCH_M68K_THREAD_TYPES_H + +#define IFRAME_TRACE_DEPTH 4 + +struct iframe_stack { + struct iframe *frames[IFRAME_TRACE_DEPTH]; + int32 index; +}; + +// architecture specific thread info +struct arch_thread { + void *sp; // stack pointer + void *interrupt_stack; + + // used to track interrupts on this thread + struct iframe_stack iframes; +}; + +struct arch_team { + // gcc treats empty structures as zero-length in C, but as if they contain + // a char in C++. So we have to put a dummy in to be able to use the struct + // from both in a consistent way. + char dummy; +}; + +struct arch_fork_arg { + // gcc treats empty structures as zero-length in C, but as if they contain + // a char in C++. So we have to put a dummy in to be able to use the struct + // from both in a consistent way. + char dummy; +}; + +#endif /* KERNEL_ARCH_M68K_THREAD_TYPES_H */ Added: haiku/trunk/headers/private/kernel/arch/m68k/arch_user_debugger.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/m68k/arch_user_debugger.h 2007-10-21 21:20:38 UTC (rev 22648) +++ haiku/trunk/headers/private/kernel/arch/m68k/arch_user_debugger.h 2007-10-21 23:42:09 UTC (rev 22649) @@ -0,0 +1,17 @@ +/* + * Copyright 2005, Axel D?rfler, axeld at pinc-software.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _KERNEL_ARCH_M68K_USER_DEBUGGER_H +#define _KERNEL_ARCH_M68K_USER_DEBUGGER_H + + +struct arch_team_debug_info { + uint32 dummy; +}; + +struct arch_thread_debug_info { + uint32 dummy; +}; + +#endif // _KERNEL_ARCH_M68K_USER_DEBUGGER_H Added: haiku/trunk/headers/private/kernel/arch/m68k/arch_vm.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/m68k/arch_vm.h 2007-10-21 21:20:38 UTC (rev 22648) +++ haiku/trunk/headers/private/kernel/arch/m68k/arch_vm.h 2007-10-21 23:42:09 UTC (rev 22649) @@ -0,0 +1,15 @@ +/* + * Copyright 2004, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef ARCH_M68K_VM_H +#define ARCH_M68K_VM_H + +/* This many pages will be read/written on I/O if possible */ + +#define NUM_IO_PAGES 4 + /* 16 kB */ + +#define PAGE_SHIFT 12 + +#endif /* ARCH_M68K_VM_H */ Added: haiku/trunk/headers/private/kernel/arch/m68k/arch_vm_translation_map.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/m68k/arch_vm_translation_map.h 2007-10-21 21:20:38 UTC (rev 22648) +++ haiku/trunk/headers/private/kernel/arch/m68k/arch_vm_translation_map.h 2007-10-21 23:42:09 UTC (rev 22649) @@ -0,0 +1,26 @@ +/* +** Copyright 2003, Axel D?rfler, axeld at pinc-software.de. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ +#ifndef _KERNEL_ARCH_M68K_VM_TRANSLATION_MAP_H +#define _KERNEL_ARCH_M68K_VM_TRANSLATION_MAP_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +void m68k_translation_map_change_asid(vm_translation_map *map); + +status_t m68k_map_address_range(addr_t virtualAddress, addr_t physicalAddress, + size_t size); +void m68k_unmap_address_range(addr_t virtualAddress, size_t size); +status_t m68k_remap_address_range(addr_t *virtualAddress, size_t size, + bool unmap); + +#ifdef __cplusplus +} +#endif + +#endif /* _KERNEL_ARCH_M68K_VM_TRANSLATION_MAP_H */ Added: haiku/trunk/headers/private/kernel/arch/m68k/arch_vm_types.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/m68k/arch_vm_types.h 2007-10-21 21:20:38 UTC (rev 22648) +++ haiku/trunk/headers/private/kernel/arch/m68k/arch_vm_types.h 2007-10-21 23:42:09 UTC (rev 22649) @@ -0,0 +1,8 @@ +/* + * Copyright 2005, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _KERNEL_ARCH_M68K_VM_TYPES_H +#define _KERNEL_ARCH_M68K_VM_TYPES_H + +#endif /* _KERNEL_ARCH_M68K_VM_TYPES_H */ Added: haiku/trunk/headers/private/kernel/arch/m68k/cpu.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/m68k/cpu.h 2007-10-21 21:20:38 UTC (rev 22648) +++ haiku/trunk/headers/private/kernel/arch/m68k/cpu.h 2007-10-21 23:42:09 UTC (rev 22649) @@ -0,0 +1,11 @@ +/* +** Copyright 2001, Travis Geiselbrecht. All rights reserved. +** Distributed under the terms of the NewOS License. +*/ +#ifndef _M68K_CPU_H +#define _M68K_CPU_H + +#define PAGE_SIZE 4096 + +#endif + Added: haiku/trunk/headers/private/kernel/arch/m68k/ktypes.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/m68k/ktypes.h 2007-10-21 21:20:38 UTC (rev 22648) +++ haiku/trunk/headers/private/kernel/arch/m68k/ktypes.h 2007-10-21 23:42:09 UTC (rev 22649) @@ -0,0 +1,11 @@ +/* +** Copyright 2001, Travis Geiselbrecht. All rights reserved. +** Distributed under the terms of the NewOS License. +*/ +#ifndef _M68K_KTYPES_H +#define _M68K_KTYPES_H + +typedef unsigned long addr; + +#endif + Added: haiku/trunk/headers/private/kernel/arch/m68k/stage2_priv.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/m68k/stage2_priv.h 2007-10-21 21:20:38 UTC (rev 22648) +++ haiku/trunk/headers/private/kernel/arch/m68k/stage2_priv.h 2007-10-21 23:42:09 UTC (rev 22649) @@ -0,0 +1,43 @@ +/* +** Copyright 2001, Travis Geiselbrecht. All rights reserved. +** Distributed under the terms of the NewOS License. +*/ +#ifndef _STAGE2_PRIV_H +#define _STAGE2_PRIV_H + +#define LOAD_ADDR 0x100000 +#define BOOTDIR_ADDR 0x101000 + +int s2_text_init(); +void s2_change_framebuffer_addr(unsigned int address); +void putchar(char c); +void puts(char *str); +int printf(const char *fmt, ...); + +int of_init(void *of_entry); +int of_open(const char *node_name); +int of_finddevice(const char *dev); +int of_instance_to_package(int in_handle); +int of_getprop(int handle, const char *prop, void *buf, int buf_len); +int of_setprop(int handle, const char *prop, const void *buf, int buf_len); +int of_read(int handle, void *buf, int buf_len); +int of_write(int handle, void *buf, int buf_len); +int of_seek(int handle, long long pos); + +int s2_mmu_init(); +void mmu_map_page(unsigned int vsid, unsigned long pa, unsigned long va);; +void syncicache(void *address, int len); + +void s2_faults_init(kernel_args *ka); + +void getibats(int bats[8]); +void setibats(int bats[8]); [... truncated: 34 lines follow ...] From mmu_man at mail.berlios.de Mon Oct 22 01:50:00 2007 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Mon, 22 Oct 2007 01:50:00 +0200 Subject: [Haiku-commits] r22650 - haiku/trunk/src/system/kernel/arch/m68k Message-ID: <200710212350.l9LNo0Ew019396@sheep.berlios.de> Author: mmu_man Date: 2007-10-22 01:49:57 +0200 (Mon, 22 Oct 2007) New Revision: 22650 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=22650&view=rev Added: haiku/trunk/src/system/kernel/arch/m68k/Jamfile haiku/trunk/src/system/kernel/arch/m68k/arch_asm.S haiku/trunk/src/system/kernel/arch/m68k/arch_atomic.c haiku/trunk/src/system/kernel/arch/m68k/arch_cpu.cpp haiku/trunk/src/system/kernel/arch/m68k/arch_cpu_asm.S haiku/trunk/src/system/kernel/arch/m68k/arch_debug.cpp haiku/trunk/src/system/kernel/arch/m68k/arch_debug_console.cpp haiku/trunk/src/system/kernel/arch/m68k/arch_elf.cpp haiku/trunk/src/system/kernel/arch/m68k/arch_exceptions.S haiku/trunk/src/system/kernel/arch/m68k/arch_int.cpp haiku/trunk/src/system/kernel/arch/m68k/arch_mmu.cpp haiku/trunk/src/system/kernel/arch/m68k/arch_platform.cpp haiku/trunk/src/system/kernel/arch/m68k/arch_real_time_clock.cpp haiku/trunk/src/system/kernel/arch/m68k/arch_smp.c haiku/trunk/src/system/kernel/arch/m68k/arch_system_info.c haiku/trunk/src/system/kernel/arch/m68k/arch_thread.c haiku/trunk/src/system/kernel/arch/m68k/arch_timer.c haiku/trunk/src/system/kernel/arch/m68k/arch_user_debugger.cpp haiku/trunk/src/system/kernel/arch/m68k/arch_vm.cpp haiku/trunk/src/system/kernel/arch/m68k/arch_vm_translation_map.cpp Log: Unfinished kernel support for m68k. Based on ppc/x86 from r22648. Added: haiku/trunk/src/system/kernel/arch/m68k/Jamfile =================================================================== --- haiku/trunk/src/system/kernel/arch/m68k/Jamfile 2007-10-21 23:42:09 UTC (rev 22649) +++ haiku/trunk/src/system/kernel/arch/m68k/Jamfile 2007-10-21 23:49:57 UTC (rev 22650) @@ -0,0 +1,35 @@ +SubDir HAIKU_TOP src system kernel arch m68k ; + +SubDirHdrs $(SUBDIR) $(DOTDOT) generic ; +#UseHeaders $(TARGET_PRIVATE_KERNEL_HEADERS) ; +# for some reason, this doesn't work +UsePrivateHeaders kernel [ FDirName kernel arch $(TARGET_ARCH) ] + [ FDirName kernel boot platform $(HAIKU_BOOT_PLATFORM) ] ; + +SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) generic ] ; + +KernelStaticLibrary libm68k : + arch_atomic.c + arch_cpu.cpp + arch_cpu_asm.S + arch_debug_console.cpp + arch_debug.cpp + arch_elf.cpp + arch_exceptions.S + arch_int.cpp + arch_mmu.cpp + arch_platform.cpp + arch_real_time_clock.cpp + arch_smp.c + arch_system_info.c + arch_thread.c + arch_timer.c + arch_user_debugger.cpp + arch_vm.cpp + arch_vm_translation_map.cpp + arch_asm.S + + generic_vm_physical_page_mapper.cpp + : + $(TARGET_KERNEL_PIC_CCFLAGS) -Wno-unused +; Added: haiku/trunk/src/system/kernel/arch/m68k/arch_asm.S =================================================================== --- haiku/trunk/src/system/kernel/arch/m68k/arch_asm.S 2007-10-21 23:42:09 UTC (rev 22649) +++ haiku/trunk/src/system/kernel/arch/m68k/arch_asm.S 2007-10-21 23:49:57 UTC (rev 22650) @@ -0,0 +1,333 @@ +/* + * Copyright 2006, Ingo Weinhold . + * All rights reserved. Distributed under the terms of the MIT License. + * + * Copyright 2003, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the NewOS License. + */ + +#define FUNCTION(x) .global x; .type x, at function; x + +#define MSR_EXCEPTIONS_ENABLED 15 + +.text + +// ToDo: fixme +FUNCTION(reboot): + reset + + +/* void arch_int_enable_interrupts(void) */ +FUNCTION(arch_int_enable_interrupts): + mfmsr %r3 // load msr + + li %r4, 1 + insrwi %r3, %r4, 1, 31 - MSR_EXCEPTIONS_ENABLED + // sets bit 15, EE + + mtmsr %r3 // put it back into the msr + blr + + +/* int arch_int_disable_interrupts(void) + * r3 + */ +FUNCTION(arch_int_disable_interrupts): + mfmsr %r4 // load msr + + mr %r3, %r4 // save old state + rlwinm %r4, %r4, 0, 32 - MSR_EXCEPTIONS_ENABLED, 30 - MSR_EXCEPTIONS_ENABLED + // clears bit 15, EE + + mtmsr %r4 // put it back into the msr + blr + + +/* void arch_int_restore_interrupts(int oldState) + * r3 + */ +FUNCTION(arch_int_restore_interrupts): + mfmsr %r4 + + rlwimi %r4, %r3, 0, 31 - MSR_EXCEPTIONS_ENABLED, 31 - MSR_EXCEPTIONS_ENABLED + // clear or set bit 15, EE to the same state as in r3, oldState + + mtmsr %r4 + blr + +/* bool arch_int_are_interrupts_enabled(void) */ +FUNCTION(arch_int_are_interrupts_enabled): + mfmsr %r3 // load msr + extrwi %r3, %r3, 1, 31 - MSR_EXCEPTIONS_ENABLED + // mask out the EE bit + blr + + +// ToDo: fixme +FUNCTION(dbg_save_registers): + blr + +/* long long get_time_base(void) */ +FUNCTION(get_time_base): +1: + mftbu %r3 // get the upper time base register + mftb %r4 // get the lower time base register + mftbu %r5 // get the upper again + cmpw %r5, %r3 // see if it changed while we were reading the lower + bne- 1b // if so, repeat + blr + +/* void getibats(int bats[8]); */ +FUNCTION(getibats): + mfibatu %r0,0 + stw %r0,0(%r3) + mfibatl %r0,0 + stwu %r0,4(%r3) + mfibatu %r0,1 + stwu %r0,4(%r3) + mfibatl %r0,1 + stwu %r0,4(%r3) + mfibatu %r0,2 + stwu %r0,4(%r3) + mfibatl %r0,2 + stwu %r0,4(%r3) + mfibatu %r0,3 + stwu %r0,4(%r3) + mfibatl %r0,3 + stwu %r0,4(%r3) + blr + +// void setibats(int bats[8]); +FUNCTION(setibats): + lwz %r0,0(%r3) + mtibatu 0,%r0 + isync + lwzu %r0,4(%r3) + mtibatl 0,%r0 + isync + lwzu %r0,4(%r3) + mtibatu 1,%r0 + isync + lwzu %r0,4(%r3) + mtibatl 1,%r0 + isync + lwzu %r0,4(%r3) + mtibatu 2,%r0 + isync + lwzu %r0,4(%r3) + mtibatl 2,%r0 + isync + lwzu %r0,4(%r3) + mtibatu 3,%r0 + isync + lwzu %r0,4(%r3) + mtibatl 3,%r0 + isync + + blr + +// void getdbats(int bats[8]); +FUNCTION(getdbats): + mfdbatu %r0,0 + stw %r0,0(%r3) + mfdbatl %r0,0 + stwu %r0,4(%r3) + mfdbatu %r0,1 + stwu %r0,4(%r3) + mfdbatl %r0,1 + stwu %r0,4(%r3) + mfdbatu %r0,2 + stwu %r0,4(%r3) + mfdbatl %r0,2 + stwu %r0,4(%r3) + mfdbatu %r0,3 + stwu %r0,4(%r3) + mfdbatl %r0,3 + stwu %r0,4(%r3) + blr + +// void setdbats(int bats[8]); +FUNCTION(setdbats): + lwz %r0,0(%r3) + mtdbatu 0,%r0 + lwzu %r0,4(%r3) + mtdbatl 0,%r0 + lwzu %r0,4(%r3) + mtdbatu 1,%r0 + lwzu %r0,4(%r3) + mtdbatl 1,%r0 + lwzu %r0,4(%r3) + mtdbatu 2,%r0 + lwzu %r0,4(%r3) + mtdbatl 2,%r0 + lwzu %r0,4(%r3) + mtdbatu 3,%r0 + lwzu %r0,4(%r3) + mtdbatl 3,%r0 + sync + + blr + +// unsigned int gethid0(); +FUNCTION(gethid0): + mfspr %r3, 1008 + blr + +// void sethid0(unsigned int val); +FUNCTION(sethid0): + mtspr 1008, %r3 + blr + +// unsigned int getl2cr(); +FUNCTION(getl2cr): + mfspr %r3, 1017 + blr + +// void setl2cr(unsigned int val); +FUNCTION(setl2cr): + mtspr 1017, %r3 + blr + + +// void ppc_context_switch(addr_t *old_sp, addr_t new_sp); +FUNCTION(ppc_context_switch): + + // regs to push on the stack: f13-f31, r13-r31, cr, r2, lr + + // push the old regs we need to save on the stack + // f31-13 + stfdu %f31, -8(%r1) + stfdu %f30, -8(%r1) + stfdu %f29, -8(%r1) + stfdu %f28, -8(%r1) + stfdu %f27, -8(%r1) + stfdu %f26, -8(%r1) + stfdu %f25, -8(%r1) + stfdu %f24, -8(%r1) + stfdu %f23, -8(%r1) + stfdu %f22, -8(%r1) + stfdu %f21, -8(%r1) + stfdu %f20, -8(%r1) + stfdu %f19, -8(%r1) + stfdu %f18, -8(%r1) + stfdu %f17, -8(%r1) + stfdu %f16, -8(%r1) + stfdu %f15, -8(%r1) + stfdu %f14, -8(%r1) + stfdu %f13, -8(%r1) + + // r31-13, r2 + stwu %r31, -4(%r1) + stwu %r30, -4(%r1) + stwu %r29, -4(%r1) + stwu %r28, -4(%r1) + stwu %r27, -4(%r1) + stwu %r26, -4(%r1) + stwu %r25, -4(%r1) + stwu %r24, -4(%r1) + stwu %r23, -4(%r1) + stwu %r22, -4(%r1) + stwu %r21, -4(%r1) + stwu %r20, -4(%r1) + stwu %r19, -4(%r1) + stwu %r18, -4(%r1) + stwu %r17, -4(%r1) + stwu %r16, -4(%r1) + stwu %r15, -4(%r1) + stwu %r14, -4(%r1) + stwu %r13, -4(%r1) + stwu %r2, -4(%r1) + + // CR and LR + mfcr %r0 + stwu %r0, -4(%r1) + mflr %r0 + stwu %r0, -4(%r1) + + // save the old stack pointer + stwu %r1, 0(%r3) + + // restore the new stack pointer + mr %r1, %r4 + + // restore the new regs + // LR and CR + lwz %r0, 0(%r1) + mtlr %r0 + lwzu %r0, 4(%r1) + mtcr %r0 + + // r2, r13-31 + lwzu %r2, 4(%r1) + lwzu %r13, 4(%r1) + lwzu %r14, 4(%r1) + lwzu %r15, 4(%r1) + lwzu %r16, 4(%r1) + lwzu %r17, 4(%r1) + lwzu %r18, 4(%r1) + lwzu %r19, 4(%r1) + lwzu %r20, 4(%r1) + lwzu %r21, 4(%r1) + lwzu %r22, 4(%r1) + lwzu %r23, 4(%r1) + lwzu %r24, 4(%r1) + lwzu %r25, 4(%r1) + lwzu %r26, 4(%r1) + lwzu %r27, 4(%r1) + lwzu %r28, 4(%r1) + lwzu %r29, 4(%r1) + lwzu %r30, 4(%r1) + lwzu %r31, 4(%r1) + + // f13-31 + lfdu %f13, 4(%r1) + lfdu %f14, 8(%r1) + lfdu %f15, 8(%r1) + lfdu %f16, 8(%r1) + lfdu %f17, 8(%r1) + lfdu %f18, 8(%r1) + lfdu %f19, 8(%r1) + lfdu %f20, 8(%r1) + lfdu %f21, 8(%r1) + lfdu %f22, 8(%r1) + lfdu %f23, 8(%r1) + lfdu %f24, 8(%r1) + lfdu %f25, 8(%r1) + lfdu %f26, 8(%r1) + lfdu %f27, 8(%r1) + lfdu %f28, 8(%r1) + lfdu %f29, 8(%r1) + lfdu %f30, 8(%r1) + lfdu %f31, 8(%r1) + + addi %r1, %r1, 8 + + blr + + +// void ppc_switch_stack_and_call(addr_t newKstack, +// void (*func)(void *), void *arg) +FUNCTION(ppc_switch_stack_and_call): + mr %r1, %r3 // set the new stack pointer + mtctr %r4 // move the target function into CTR + mr %r3, %r5 // move the arg to this func to the new arg + bctr + + +// ppc_kernel_thread_root(): parameters in r13-r15, the functions to call +// (in that order). The function is used when spawing threads. It usually calls +// an initialization function, the actual thread function, and a function that +// destroys the thread. +FUNCTION(ppc_kernel_thread_root): + mtlr %r13 + blrl + mtlr %r14 + blrl + mtlr %r15 + blrl + + // We should never get here. If we do, it's time to enter the kernel + // debugger (without a message at the moment). + li %r3, 0 + b kernel_debugger + Added: haiku/trunk/src/system/kernel/arch/m68k/arch_atomic.c =================================================================== --- haiku/trunk/src/system/kernel/arch/m68k/arch_atomic.c 2007-10-21 23:42:09 UTC (rev 22649) +++ haiku/trunk/src/system/kernel/arch/m68k/arch_atomic.c 2007-10-21 23:49:57 UTC (rev 22650) @@ -0,0 +1,237 @@ +/* + * Copyright 2003, Marcus Overhagen. All rights reserved. + * Distributed under the terms of the OpenBeOS License. + */ + +#include + +#include +#include + +/* + * Emulation of 64 bit atomic functions. + * Slow, using spinlocks... + */ + +static spinlock atomic_lock = 0; + +int64 +atomic_set64(vint64 *value, int64 newValue) +{ + cpu_status status; + int64 oldValue; + status = disable_interrupts(); + acquire_spinlock(&atomic_lock); + oldValue = *value; + *value = newValue; + release_spinlock(&atomic_lock); + restore_interrupts(status); + return oldValue; +} + +int64 +atomic_test_and_set64(vint64 *value, int64 newValue, int64 testAgainst) +{ + cpu_status status; + int64 oldValue; + status = disable_interrupts(); + acquire_spinlock(&atomic_lock); + oldValue = *value; + if (oldValue == testAgainst) + *value = newValue; + release_spinlock(&atomic_lock); + restore_interrupts(status); + return oldValue; +} + +int64 +atomic_add64(vint64 *value, int64 addValue) +{ + cpu_status status; + int64 oldValue; + status = disable_interrupts(); + acquire_spinlock(&atomic_lock); + oldValue = *value; + *value += addValue; + release_spinlock(&atomic_lock); + restore_interrupts(status); + return oldValue; +} + +int64 +atomic_and64(vint64 *value, int64 andValue) +{ + cpu_status status; + int64 oldValue; + status = disable_interrupts(); + acquire_spinlock(&atomic_lock); + oldValue = *value; + *value &= andValue; + release_spinlock(&atomic_lock); + restore_interrupts(status); + return oldValue; +} + +int64 +atomic_or64(vint64 *value, int64 orValue) +{ + cpu_status status; + int64 oldValue; + status = disable_interrupts(); + acquire_spinlock(&atomic_lock); + oldValue = *value; + *value |= orValue; + release_spinlock(&atomic_lock); + restore_interrupts(status); + return oldValue; +} + +int64 +atomic_get64(vint64 *value) +{ + cpu_status status; + int64 oldValue; + status = disable_interrupts(); + acquire_spinlock(&atomic_lock); + oldValue = *value; + release_spinlock(&atomic_lock); + restore_interrupts(status); + return oldValue; +} + +int64 +_user_atomic_set64(vint64 *value, int64 newValue) +{ + cpu_status status; + int64 oldValue; + if (!IS_USER_ADDRESS(value) + || lock_memory((void *)value, 8, B_READ_DEVICE) != B_OK) + goto access_violation; + + status = disable_interrupts(); + acquire_spinlock(&atomic_lock); + oldValue = *value; + *value = newValue; + release_spinlock(&atomic_lock); + restore_interrupts(status); + unlock_memory((void *)value, 8, B_READ_DEVICE); + return oldValue; + +access_violation: + // XXX kill application + return -1; +} + +int64 +_user_atomic_test_and_set64(vint64 *value, int64 newValue, int64 testAgainst) +{ + cpu_status status; + int64 oldValue; + if (!IS_USER_ADDRESS(value) + || lock_memory((void *)value, 8, B_READ_DEVICE) != B_OK) + goto access_violation; + + status = disable_interrupts(); + acquire_spinlock(&atomic_lock); + oldValue = *value; + if (oldValue == testAgainst) + *value = newValue; + release_spinlock(&atomic_lock); + restore_interrupts(status); + unlock_memory((void *)value, 8, B_READ_DEVICE); + return oldValue; + +access_violation: + // XXX kill application + return -1; +} + +int64 +_user_atomic_add64(vint64 *value, int64 addValue) +{ + cpu_status status; + int64 oldValue; + if (!IS_USER_ADDRESS(value) + || lock_memory((void *)value, 8, B_READ_DEVICE) != B_OK) + goto access_violation; + + status = disable_interrupts(); + acquire_spinlock(&atomic_lock); + oldValue = *value; + *value += addValue; + release_spinlock(&atomic_lock); + restore_interrupts(status); + unlock_memory((void *)value, 8, B_READ_DEVICE); + return oldValue; + +access_violation: + // XXX kill application + return -1; +} + +int64 +_user_atomic_and64(vint64 *value, int64 andValue) +{ + cpu_status status; + int64 oldValue; + if (!IS_USER_ADDRESS(value) + || lock_memory((void *)value, 8, B_READ_DEVICE) != B_OK) + goto access_violation; + + status = disable_interrupts(); + acquire_spinlock(&atomic_lock); + oldValue = *value; + *value &= andValue; + release_spinlock(&atomic_lock); + restore_interrupts(status); + unlock_memory((void *)value, 8, B_READ_DEVICE); + return oldValue; + +access_violation: + // XXX kill application + return -1; +} + +int64 +_user_atomic_or64(vint64 *value, int64 orValue) +{ + cpu_status status; + int64 oldValue; + if (!IS_USER_ADDRESS(value) + || lock_memory((void *)value, 8, B_READ_DEVICE) != B_OK) + goto access_violation; + + status = disable_interrupts(); + acquire_spinlock(&atomic_lock); + oldValue = *value; + *value |= orValue; + release_spinlock(&atomic_lock); + restore_interrupts(status); + unlock_memory((void *)value, 8, B_READ_DEVICE); + return oldValue; +access_violation: + // XXX kill application + return -1; +} + +int64 +_user_atomic_get64(vint64 *value) +{ + cpu_status status; + int64 oldValue; + if (!IS_USER_ADDRESS(value) + || lock_memory((void *)value, 8, B_READ_DEVICE) != B_OK) + goto access_violation; + + status = disable_interrupts(); + acquire_spinlock(&atomic_lock); + oldValue = *value; + release_spinlock(&atomic_lock); + restore_interrupts(status); + unlock_memory((void *)value, 8, B_READ_DEVICE); + return oldValue; + +access_violation: + // XXX kill application + return -1; +} Added: haiku/trunk/src/system/kernel/arch/m68k/arch_cpu.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/m68k/arch_cpu.cpp 2007-10-21 23:42:09 UTC (rev 22649) +++ haiku/trunk/src/system/kernel/arch/m68k/arch_cpu.cpp 2007-10-21 23:49:57 UTC (rev 22650) @@ -0,0 +1,264 @@ +/* + * Copyright 2003-2005, Axel D?rfler, axeld at pinc-software.de. + * Distributed under the terms of the MIT License. + * + * Copyright 2001, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the NewOS License. + */ + + +#include + +#include +#include +#include +#include + +static bool sHasTlbia; + +status_t +arch_cpu_preboot_init_percpu(kernel_args *args, int curr_cpu) +{ + // enable FPU + set_msr(get_msr() | MSR_FP_AVAILABLE); + + // The current thread must be NULL for all CPUs till we have threads. + // Some boot code relies on this. + arch_thread_set_current_thread(NULL); + + return B_OK; +} + + +status_t +arch_cpu_init(kernel_args *args) +{ + // TODO: Let the boot loader put that info into the kernel args + // (property "tlbia" in the CPU node). + sHasTlbia = false; + + return B_OK; +} + + +status_t +arch_cpu_init_post_vm(kernel_args *args) +{ + return B_OK; +} + +status_t +arch_cpu_init_post_modules(kernel_args *args) +{ + return B_OK; +} + +#define CACHELINE 32 + +void +arch_cpu_sync_icache(void *address, size_t len) +{ + int l, off; + char *p; + + off = (unsigned int)address & (CACHELINE - 1); + len += off; + + l = len; + p = (char *)address - off; + do { + asm volatile ("dcbst 0,%0" :: "r"(p)); + p += CACHELINE; + } while ((l -= CACHELINE) > 0); + asm volatile ("sync"); + + p = (char *)address - off; + do { + asm volatile ("icbi 0,%0" :: "r"(p)); + p += CACHELINE; + }