Changes by: antona
Update of /cvsroot/linux-ntfs/linux-ntfs/libntfs
In directory usw-pr-cvs1:/tmp/cvs-serv12548/libntfs
Added Files:
ntfsd.c
Log Message:
Initial ntfsd implementation using alarm signal to emulate a usermode thread.
(This might not work when the library is installed as shared... Not sure, will
found out soon enough...)
Stil missing the acutal walking of volumes and their dirty mft entries, as
well as flushing them...
--- NEW FILE ---
/*
* $Id: ntfsd.c,v 1.1 2001/04/07 00:45:49 antona Exp $
*
* ntfsd.c - Writer daemon. Part of the Linux-NTFS project.
*
* Copyright (c) 2001 Anton Altaparmakov.
*
* This program/include file is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program/include file 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program (in the main directory of the Linux-NTFS
* distribution in the file COPYING); if not, write to the Free Software
* Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <unistd.h>
#include <stdlib.h>
#include <linux/bitops.h>
#include <sys/time.h>
#include <signal.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include "ntfsd.h"
#include "support.h"
static void ntfsd_thread(int i)
{
if (!NtfsdStarted(ntfsd_flags) ||
test_and_set_bit(NTFSD_running, &ntfsd_flags))
return;
// TODO: Sync all volumes.
ClearNtfsdRunning(ntfsd_flags);
return;
}
static struct sigaction ntfsd_old_sigalrm_action;
static const char *ntfsd_internal_error = "Internal error.";
static const char *ntfsd_sigalrm_not_supported = "The system does not support "
"the SIGALRM signal.";
int ntfsd_start()
{
const char *ntfsd_start_error = "Linux-NTFS: failed to start ntfsd.";
struct sigaction act;
int tries;
if (test_and_set_bit(NTFSD_busy, &ntfsd_flags)) {
errno = EBUSY;
return FALSE;
}
if (test_and_set_bit(NTFSD_started, &ntfsd_flags)) {
unl_ret_true:
ClearNtfsdBusy(ntfsd_flags);
return TRUE;
}
memset(&ntfsd_old_sigalrm_action, 0, sizeof(struct sigaction));
tries = 0;
retry_get_action:
if (sigaction(SIGALRM, NULL, &act)) {
int e = errno;
switch (e) {
case EFAULT:
fprintf(stderr, "%s %s\n", ntfsd_start_error,
ntfsd_internal_error);
break;
case EINVAL:
fprintf(stderr, "%s %s\n", ntfsd_start_error,
ntfsd_sigalrm_not_supported);
break;
case EINTR:
if (tries++ < 2)
goto retry_get_action;
/* else fall through to default. */
default:
perror(ntfsd_start_error);
}
errno = e;
return FALSE;
}
if (act.sa_handler == &ntfsd_thread)
goto unl_ret_true;
memset(&act, 0, sizeof(struct sigaction));
tries = 0;
retry_set_action:
act.sa_handler = &ntfsd_thread;
if (sigaction(SIGALRM, &act, &ntfsd_old_sigalrm_action)) {
int e = errno;
switch (e) {
case EFAULT:
fprintf(stderr, "%s %s\n", ntfsd_start_error,
ntfsd_internal_error);
break;
case EINTR:
if (tries++ < 2)
goto retry_set_action;
/* else fall through to default. */
default:
perror(ntfsd_start_error);
}
errno = e;
return FALSE;
}
goto unl_ret_true;
}
int ntfsd_stop()
{
const char *ntfsd_stop_error = "Linux-NTFS: failed to stop ntfsd.";
struct sigaction act;
int tries;
if (test_and_set_bit(NTFSD_busy, &ntfsd_flags)) {
errno = EBUSY;
return FALSE;
}
if (!test_and_clear_bit(NTFSD_started, &ntfsd_flags)) {
unl_ret_true:
ClearNtfsdBusy(ntfsd_flags);
return TRUE;
}
tries = 0;
retry_set_action:
if (sigaction(SIGALRM, &ntfsd_old_sigalrm_action, NULL)) {
int e = errno;
switch (e) {
case EFAULT:
fprintf(stderr, "%s %s\n", ntfsd_stop_error,
ntfsd_internal_error);
break;
case EINTR:
if (tries++ < 2)
goto retry_set_action;
/* else fall through to default. */
default:
perror(ntfsd_stop_error);
}
errno = e;
return FALSE;
}
goto unl_ret_true;
}
|