quota: precheck first write for newly created files
All checks were successful
Source release / source-package (push) Successful in 1m0s

This commit is contained in:
Mario Fetka
2026-06-11 09:11:17 +00:00
parent 04507bea5f
commit eb55c16620
2 changed files with 13 additions and 1 deletions

View File

@@ -46,6 +46,7 @@ typedef struct {
#define FH_DO_NOT_REUSE 0x04
#define FH_IS_READONLY 0x20 /* filesystem is readonly */
#define FH_OPENED_RO 0x40 /* is opened RO */
#define FH_CREATED_NEW 0x80 /* newly created file: force first-write quota check */
extern void sig_bus_mmap(int rsig);

View File

@@ -493,6 +493,15 @@ int file_creat_open(int volume, uint8 *unixname, struct stat *stbuff,
if (fh->fd==-1)
completition=-0x9c;
else {
/*
* ncpfs may create a new file and then make the first data write
* through a path where the local file already appears to have the
* target EOF. Keep a one-shot marker so the first write still
* runs the user-volume quota precheck. This matters for the
* metadata/NWQUOTA backend, where the kernel will not catch an
* already-sized newly-created file the way Linux quota does.
*/
fh->fh_flags |= FH_CREATED_NEW;
if (seteuid(0)) {}
stat(fh->fname, stbuff);
(void)reseteuid();
@@ -959,7 +968,7 @@ int nw_write_file(int fhandle, uint8 *data, int size, uint32 offset)
if (fstat(fh->fd, &qst) == 0) {
old_size = qst.st_size;
if (new_size > old_size)
if (new_size > old_size || (fh->fh_flags & FH_CREATED_NEW))
qresult = nw_check_vol_user_space((uint8)fh->volume,
act_uid, fh->fname,
old_size, new_size);
@@ -968,6 +977,8 @@ int nw_write_file(int fhandle, uint8 *data, int size, uint32 offset)
size = qresult;
} else {
size = write(fh->fd, data, size);
if (size > -1)
fh->fh_flags &= ~FH_CREATED_NEW;
fh->offd+=(long)size;
if (!fh->modified)
fh->modified++;