Subversion Repositories Spectranet

[/] [trunk/] [tnfs/] [tnfs-perl/] [tnfsd.pl] - Diff between revs 265 and 288

Show entire file | Details | Blame | View Log

Rev 265 Rev 288
Line 39... Line 39...
                0x22    => \&writeBlock,
                0x22    => \&writeBlock,
                0x23    => \&closeFile,
                0x23    => \&closeFile,
                0x24    => \&statFile,
                0x24    => \&statFile,
                0x25    => \&seekFile,
                0x25    => \&seekFile,
                0x26    => \&unlinkFile,
                0x26    => \&unlinkFile,
                0x27    => \&chmodFile );
                0x27    => \&chmodFile,
 
                0x28    => \&renameFile );
 
 
# File modes
# File modes
my %MODE=(      0x01    => O_RDONLY,
my %MODE=(      0x01    => O_RDONLY,
                0x02    => O_WRONLY,
                0x02    => O_WRONLY,
                0x03    => O_RDWR );
                0x03    => O_RDWR );
Line 421... Line 422...
# seekFile - Seeks to a location in a file. (Command 0x25)
# seekFile - Seeks to a location in a file. (Command 0x25)
sub seekFile
sub seekFile
{
{
        my ($session, $cmd, $status, $msg)=@_;
        my ($session, $cmd, $status, $msg)=@_;
 
 
        my ($clientHandle, $seektype, $seekloc)=unpack("CCl", $msg);
        my ($clientHandle, $seektype, $seekloc)=unpack("CCV", $msg);
 
        if($seekloc & 8000000)
 
        {
 
                $seekloc = -$seekloc;
 
        }
        #print("seekFile: handle=$clientHandle type=$seektype loc=$seekloc\n");
        #print("seekFile: handle=$clientHandle type=$seektype loc=$seekloc\n");
        my $fhnd=$FILEHANDLE{$session}->[$clientHandle];
        my $fhnd=$FILEHANDLE{$session}->[$clientHandle];
        if(defined $fhnd)
        if(defined $fhnd)
        {
        {
                # this assumes posix definitions of SEEK_CUR, SYS_END etc.
                # this assumes posix definitions of SEEK_CUR, SYS_END etc.
Line 510... Line 515...
        {
        {
                sendMsg($session, 0x27, int($!));
                sendMsg($session, 0x27, int($!));
        }
        }
}
}
 
 
 
# renameFile - moves a file within the filesystem (0x28)
 
sub renameFile
 
{
 
        my ($session, $cmd, $status, $msg)=@_;
 
 
 
        # separate out "from" and "to" paths.
 
        my ($from, $to)=split(/\x00/, $msg);
 
        $from = $MOUNTPOINT{$session} . $from;
 
        $to = $MOUNTPOINT{$session} . $to;
 
        print("rename: $from => $to\n");
 
        if(rename($from, $to))
 
        {
 
                sendMsg($session, 0x28, 0x00);
 
        }
 
        else
 
        {
 
                sendMsg($session, 0x28, int($!));
 
        }
 
}
 
 
sub sendMsg
sub sendMsg
{
{
        my ($session, $cmd, $status, $msg)=@_;
        my ($session, $cmd, $status, $msg)=@_;
        my $seq=$SEQNO{$session};
        my $seq=$SEQNO{$session};
#       print("message: Session $session cmd $cmd status $status seq $seq\n");
#       print("message: Session $session cmd $cmd status $status seq $seq\n");