如果文件/目录大小增加以上,有没有办法在Linux中重新呼叫

Is there a way to get call back in linux if file/directory size increases above configured level

本文关键字:Linux 新呼叫 呼叫 有没有 文件 增加 如果      更新时间:2023-10-16

正在使用Linux系统调用,在C/C 中寻找类似此类的内容,

char * filename="/tmp/testDirectory";
fd = open(filename, O_CREAT | O_RDWR);
setmaxfilesize(fd,"4mb");         //<== looking for some API to do this.
registerforCallback(mycallback);  //<== looking for some API to do this 
void mycallback(void * arg)
{
 /* Delete old files inside directory to have space for new files*/
}

是的,但不直接在我所知的文件大小上。

看一下:https://lwn.net/articles/604686/

这将为您提供一个很好的起点,如何与文件通知进行交互。文件更改后,可以通知您的处理程序。在处理程序中,您可以检查大小并完成工作。

摘录:有dnotify基本上与SYSCALL fcntl(fd, F_NOTIFY, mask);一起使用dnotify接缝要过时(我的Linux发行版不再支持DNOTIFY)

inotify带有自己的API。参见man inotify。可以使用int inotify_add_watch(int fd, const char *pathname, uint32_t mask);来观察文件更改,其中可以在其中掩码为IN_MODIFY,以查看文件上的所有修改。如果从此处调用您的处理程序,请请求文件大小并执行您的操作。