Files
markbase/vendor/smb-server/src/handlers/write.rs
Warren 57fd6a475f macOS Time Machine AFP monitoring: backup_time update on file modification
- Added afp_monitor.rs module to track AFP_AfpInfo backup_time
- Open struct now has 'modified' flag to track file modifications
- write.rs sets modified=true on successful write
- close.rs calls AfpMonitor::update_backup_time() on modified files
- create.rs calls AfpMonitor::init_afp_info() on new file creation
- AFP_AfpInfo stored as xattr com.apple.aapl.AfpInfo
- backup_time updated to current epoch time on modification

Also includes:
- LZ4 compression using lz4_flex crate
- Case sensitivity conditional on backend capabilities
- LDAP cfg feature gate fix
- RAID rebuild reconstruction implementation
- DOS attributes xattr persistence
- Snapshot disk persistence

Tests: 201 smb-server, 452 markbase-core (653 total)
2026-06-24 00:46:33 +08:00

118 lines
3.8 KiB
Rust

//! WRITE handler.
use std::sync::Arc;
use crate::proto::header::Smb2Header;
use crate::proto::messages::{WriteRequest, WriteResponse};
use crate::builder::Access;
use crate::conn::state::Connection;
use crate::dispatch::HandlerResponse;
use crate::handlers::shared::{lookup_open, lookup_session_tree};
use crate::ntstatus;
use crate::server::ServerState;
pub async fn handle(
server: &Arc<ServerState>,
conn: &Arc<Connection>,
hdr: &Smb2Header,
body: &[u8],
) -> HandlerResponse {
let req = match WriteRequest::parse(body) {
Ok(r) => r,
Err(_) => return HandlerResponse::err(ntstatus::STATUS_INVALID_PARAMETER),
};
let max_write = *conn.max_write_size.read().await;
if req.length > max_write {
return HandlerResponse::err(ntstatus::STATUS_INVALID_PARAMETER);
}
let tree_arc = match lookup_session_tree(conn, hdr).await {
Ok(t) => t,
Err(s) => return HandlerResponse::err(s),
};
let granted = {
let tree = tree_arc.read().await;
tree.granted_access
};
if !matches!(granted, Access::ReadWrite) {
return HandlerResponse::err(ntstatus::STATUS_ACCESS_DENIED);
}
let open_arc = match lookup_open(&tree_arc, req.file_id).await {
Some(o) => o,
None => return HandlerResponse::err(ntstatus::STATUS_FILE_CLOSED),
};
// Phase 5: Get path and trigger oplock break before write
let (path, share_access) = {
let open = open_arc.read().await;
(open.last_path.clone(), open.share_access)
};
// Get granted_access from tree
let granted_access = {
let tree = tree_arc.read().await;
tree.granted_access
};
// Trigger oplock break for conflicting clients
let notifications = server.oplock_manager.break_oplock(
&path,
share_access,
granted_access,
).await;
// Send notifications to affected clients
for notification in notifications {
// Build SMB2 frame for notification
use crate::proto::framing::encode_frame;
let notification_bytes = notification.write_to_bytes();
let mut frame = Vec::with_capacity(notification_bytes.len() + 4);
encode_frame(&notification_bytes, &mut frame);
// Send via notification channel (if available)
if let Some(tx) = conn.notification_tx.read().await.as_ref() {
let _ = tx.send(frame).await;
}
}
// Phase 5: Trigger lease break if lease exists (SMB 3.x)
let lease_notifications = server.lease_manager.break_lease(
crate::oplock::SMB2_LEASE_READ, // WRITE operation breaks READ leases
).await;
for lease_notification in lease_notifications {
use crate::proto::framing::encode_frame;
let notification_bytes = lease_notification.write_to_bytes();
let mut frame = Vec::with_capacity(notification_bytes.len() + 4);
encode_frame(&notification_bytes, &mut frame);
if let Some(tx) = conn.notification_tx.read().await.as_ref() {
let _ = tx.send(frame).await;
}
}
let result = {
let open = open_arc.read().await;
match open.handle.as_ref() {
Some(h) => h.write_owned(req.offset, req.data).await,
None => return HandlerResponse::err(ntstatus::STATUS_FILE_CLOSED),
}
};
let count = match result {
Ok(n) => n,
Err(e) => return HandlerResponse::err(e.to_nt_status()),
};
// AFP monitoring: Set modified flag for Time Machine backup tracking
{
let mut open = open_arc.write().await;
open.modified = true;
}
let mut buf = Vec::new();
WriteResponse::new(count)
.write_to(&mut buf)
.expect("encode");
HandlerResponse::ok(buf)
}