Skip to content

Commit

Permalink
Merge pull request #222 from gboudreau/dev/hardlinks
Browse files Browse the repository at this point in the history
Hard links support
  • Loading branch information
gboudreau authored Mar 31, 2020
2 parents 390aacd + f013fca commit a683c2e
Show file tree
Hide file tree
Showing 32 changed files with 598 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build_vfs_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if [ "$ARCH" = "i686" ]; then
ARCH="i386"
fi

for version in 4.11.0 4.10.0 4.9.0 4.8.0 4.7.0 4.6.0 4.5.0 4.4.0; do
for version in 4.12.0 4.11.0 4.10.0 4.9.0 4.8.0 4.7.0 4.6.0 4.5.0 4.4.0; do
source "${GREYHOLE_INSTALL_DIR}/build_vfs.sh" ${version}

M=`echo ${version} | awk -F'.' '{print $1}'` # major
Expand Down
1 change: 1 addition & 0 deletions includes/SambaSpool.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public static function parse_samba_spool() {
$fullpath = array_shift($line);
break;
case 'rename':
case 'link':
$fullpath = array_shift($line);
$fullpath_target = array_shift($line);
break;
Expand Down
1 change: 1 addition & 0 deletions includes/Tasks/AbstractTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
require_once('includes/Tasks/RmdirTask.php');
require_once('includes/Tasks/UnlinkTask.php');
require_once('includes/Tasks/WriteTask.php');
require_once('includes/Tasks/LinkTask.php');

abstract class AbstractTask {
public $id;
Expand Down
55 changes: 55 additions & 0 deletions includes/Tasks/LinkTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/*
Copyright 2020 Guillaume Boudreau
This file is part of Greyhole.
Greyhole 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 3 of the License, or
(at your option) any later version.
Greyhole 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 Greyhole. If not, see <http://www.gnu.org/licenses/>.
*/

class LinkTask extends WriteTask {

public function execute() {
$share = $this->share;
$full_path = $this->full_path;
$target_full_path = $this->additional_info;

$landing_zone = get_share_landing_zone($share);
if (!$landing_zone) {
return TRUE;
}

if ($this->should_ignore_file()) {
return TRUE;
}

Log::info("File (hard)linked: $landing_zone/$target_full_path -> $landing_zone/$full_path");
$this->full_path = $target_full_path;

parent::execute();

return TRUE;
}

public function should_ignore_file($share = NULL, $full_path = NULL) {
// We ignore this task, if the target is ignored, whatever the source ($this->full_path) is
if (empty($full_path)) {
$full_path = $this->additional_info;
}
return parent::should_ignore_file($share, $full_path);
}

}

?>
Binary file modified samba-module/bin/4.10/greyhole-i386.so
Binary file not shown.
Binary file modified samba-module/bin/4.10/greyhole-x86_64.so
Binary file not shown.
Binary file modified samba-module/bin/4.11/greyhole-i386.so
Binary file not shown.
Binary file modified samba-module/bin/4.11/greyhole-x86_64.so
Binary file not shown.
Binary file added samba-module/bin/4.12/greyhole-i386.so
Binary file not shown.
Binary file added samba-module/bin/4.12/greyhole-x86_64.so
Binary file not shown.
Binary file modified samba-module/bin/4.4/greyhole-i386.so
Binary file not shown.
Binary file modified samba-module/bin/4.4/greyhole-x86_64.so
Binary file not shown.
Binary file modified samba-module/bin/4.5/greyhole-i386.so
Binary file not shown.
Binary file modified samba-module/bin/4.5/greyhole-x86_64.so
Binary file not shown.
Binary file modified samba-module/bin/4.6/greyhole-i386.so
Binary file not shown.
Binary file modified samba-module/bin/4.6/greyhole-x86_64.so
Binary file not shown.
Binary file modified samba-module/bin/4.7/greyhole-i386.so
Binary file not shown.
Binary file modified samba-module/bin/4.7/greyhole-x86_64.so
Binary file not shown.
Binary file modified samba-module/bin/4.8/greyhole-i386.so
Binary file not shown.
Binary file modified samba-module/bin/4.8/greyhole-x86_64.so
Binary file not shown.
Binary file modified samba-module/bin/4.9/greyhole-i386.so
Binary file not shown.
Binary file modified samba-module/bin/4.9/greyhole-x86_64.so
Binary file not shown.
18 changes: 18 additions & 0 deletions samba-module/vfs_greyhole-samba-4.10.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ static struct tevent_req *greyhole_pwrite_send(struct vfs_handle_struct *handle,
static ssize_t greyhole_pwrite_recv(struct tevent_req *req, struct vfs_aio_state *vfs_aio_state);
static int greyhole_close(vfs_handle_struct *handle, files_struct *fsp);
static int greyhole_rename(vfs_handle_struct *handle, const struct smb_filename *oldname, const struct smb_filename *newname);
static int greyhole_link(vfs_handle_struct *handle, const struct smb_filename *oldname, const struct smb_filename *newname);
static int greyhole_unlink(vfs_handle_struct *handle, const struct smb_filename *path);

/* Save formatted string to Greyhole spool */
Expand Down Expand Up @@ -85,6 +86,7 @@ static struct vfs_fn_pointers vfs_greyhole_fns = {
.pwrite_recv_fn = greyhole_pwrite_recv,
.close_fn = greyhole_close,
.rename_fn = greyhole_rename,
.link_fn = greyhole_link,
.unlink_fn = greyhole_unlink
};

Expand Down Expand Up @@ -310,6 +312,22 @@ static int greyhole_rename(vfs_handle_struct *handle, const struct smb_filename
return result;
}

static int greyhole_link(vfs_handle_struct *handle, const struct smb_filename *oldname, const struct smb_filename *newname)
{
int result;

result = SMB_VFS_NEXT_LINK(handle, oldname, newname);

if (result >= 0) {
gh_spoolf("link\n%s\n%s\n%s\n\n",
lp_servicename(talloc_tos(), handle->conn->params->service),
oldname->base_name,
newname->base_name);
}

return result;
}

static int greyhole_unlink(vfs_handle_struct *handle, const struct smb_filename *path)
{
int result;
Expand Down
18 changes: 18 additions & 0 deletions samba-module/vfs_greyhole-samba-4.11.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ static struct tevent_req *greyhole_pwrite_send(struct vfs_handle_struct *handle,
static ssize_t greyhole_pwrite_recv(struct tevent_req *req, struct vfs_aio_state *vfs_aio_state);
static int greyhole_close(vfs_handle_struct *handle, files_struct *fsp);
static int greyhole_rename(vfs_handle_struct *handle, const struct smb_filename *oldname, const struct smb_filename *newname);
static int greyhole_link(vfs_handle_struct *handle, const struct smb_filename *oldname, const struct smb_filename *newname);
static int greyhole_unlink(vfs_handle_struct *handle, const struct smb_filename *path);

/* Save formatted string to Greyhole spool */
Expand Down Expand Up @@ -85,6 +86,7 @@ static struct vfs_fn_pointers vfs_greyhole_fns = {
.pwrite_recv_fn = greyhole_pwrite_recv,
.close_fn = greyhole_close,
.rename_fn = greyhole_rename,
.link_fn = greyhole_link,
.unlink_fn = greyhole_unlink
};

Expand Down Expand Up @@ -310,6 +312,22 @@ static int greyhole_rename(vfs_handle_struct *handle, const struct smb_filename
return result;
}

static int greyhole_link(vfs_handle_struct *handle, const struct smb_filename *oldname, const struct smb_filename *newname)
{
int result;

result = SMB_VFS_NEXT_LINK(handle, oldname, newname);

if (result >= 0) {
gh_spoolf("link\n%s\n%s\n%s\n\n",
lp_servicename(talloc_tos(), handle->conn->params->service),
oldname->base_name,
newname->base_name);
}

return result;
}

static int greyhole_unlink(vfs_handle_struct *handle, const struct smb_filename *path)
{
int result;
Expand Down
Loading

0 comments on commit a683c2e

Please sign in to comment.