CN116975002B - Method for protecting open file under domestic Linux operating system - Google Patents
Method for protecting open file under domestic Linux operating system Download PDFInfo
- Publication number
- CN116975002B CN116975002B CN202311225793.2A CN202311225793A CN116975002B CN 116975002 B CN116975002 B CN 116975002B CN 202311225793 A CN202311225793 A CN 202311225793A CN 116975002 B CN116975002 B CN 116975002B
- Authority
- CN
- China
- Prior art keywords
- file
- function
- handle
- protection
- directory
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/10—File systems; File servers
- G06F16/16—File or folder operations, e.g. details of user interfaces specifically adapted to file systems
- G06F16/162—Delete operations
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/10—File systems; File servers
- G06F16/16—File or folder operations, e.g. details of user interfaces specifically adapted to file systems
- G06F16/168—Details of user interfaces specifically adapted to file systems, e.g. browsing and visualisation, 2d or 3d GUIs
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/10—File systems; File servers
- G06F16/17—Details of further file system functions
- G06F16/174—Redundancy elimination performed by the file system
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Data Mining & Analysis (AREA)
- Databases & Information Systems (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Human Computer Interaction (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
- Storage Device Security (AREA)
Abstract
The invention provides a method for protecting and opening files under domestic Linux operating system, when a file manager is used for operating files or catalogues, the files are processed and deleted by the file manager, put into functions such as recycle bin and cutting, and before the file handle is acquired and the file operation is executed, a newly added function protection_file (); judging the operation file, firstly judging whether the operation target is a file or a directory, if the operation target is the file, directly acquiring a read-write lock of a file handle, if the read-write lock exists, popping up a prompt box, and canceling the current file operation. If the file is the directory, the files under all the directories and all the files under the sub-directories need to be recursively traversed in sequence, the read-write locks of the file handles are obtained, if the read-write locks exist, a prompt box is popped up, and the current file operation is canceled.
Description
Technical Field
The invention relates to a protection method for an opened file, in particular to a method for protecting the opened file under a domestic Linux operating system.
Background
In the existing domestic operation systems, such as domestic Linux operation systems like kylin and general letter, when a user uses office or PDF software to write a document/chart, a situation is often encountered that a file being written, when a file manager is used carelessly, deletes the file or a directory where the file is located, or moves the file or the directory where the file is located to other places and cannot be found, in order to prevent the situation, the invention provides a method for protecting an office type/PDF type file which is already opened under the domestic operation system.
There are also some methods for protecting open files in the market at present, for example, some manufacturers of office backup open office files at regular time, and some manufacturers of server hardware implement this function by adding a driving module, modifying the interface of the file system, etc.,
because the file manager of the existing domestic linux operating system does not have the function of protecting the opened office/PDF files, the existing technology for protecting the opened files has the following defects:
1. the techniques provided by most office manufacturers to protect open files have the following disadvantages: only when they use their own office software, it is not universal, not all office software has this function, and other types of files such as pdf cannot be protected.
2. Most server hardware is directed to a protection method of an opened file, an additional kernel module is generally required, a hard disk and a kernel file system are required to realize special interfaces, the server hardware is generally directed to, and a desktop operating system is generally not provided with the function.
Disclosure of Invention
In view of the above problems, the present invention provides a method for protecting and opening a file under a domestic Linux operating system, in which a function module for protecting a file is added to a function such as a recycle bin after processing and cutting, deleting, and when a user opens the file, the file manager triggers the function module when the file or a directory to which the file belongs performs a deleting or cutting action. And judging whether the file is in an open state by using a file locking mechanism under Linux, thereby realizing the function of protecting the opened file.
In order to achieve the above purpose, the invention discloses a method for protecting an opened file under a domestic Linux operating system, which comprises the following steps:
step S1, adding a new function protection_file () into a function of a file manager about file deletion or file placement in a recycle bin and a function of a file cutting function module, wherein the new function protection_file () is embedded in a file management area in a hook function mode, in the protection_file () function, firstly, calling a standard library function stat to acquire operated file information, and then judging whether an input file handle is a directory or not through an S_ISDIR () function, if yes, performing step S2, and if not, performing step S3;
step S2, opening a handle of the directory through an opendir () function, sequentially reading all contents under the directory through a readdir () function until NULL, and recursively calling a function protection_file () with the read file handle, and then carrying out step S4;
step S3, judging whether the file handle is a block device file through a function S_ISBLK () function, judging whether the file handle is a character device file through a function S_ISCHR (), and if the file handle is any one of the two types of files, not processing the file handle;
step S4, calling a function S_ISREG () in a protection_file () function to judge whether the operated file is a conventional file, if so, obtaining a sub-member statbuf.st_uid of a statbuf variable through a standard library function stat, obtaining a user id of the file through the statbuf.st_uid, obtaining a login user id of a current system through a getuid () function, and then judging whether the two are consistent, if so, performing step S5;
and S5, calling a standard library function fcntl () in the protect_file () function, acquiring the file write lock by setting a flag bit of F_WRLCK, if the file write lock exists, popping up a prompt box without permission through the standard library function provided by the GTK, canceling the current operation, and otherwise, continuing to execute the operation.
The method for protecting the opened file under the domestic Linux operating system has the beneficial effects that: after the scheme of the invention is deployed, when a user deletes a file or a catalog through system file management, cuts and deletes the file or the catalog to a recycle bin and the like, if the file or the file contained in the catalog is in an open editing state, the system can pop up a warning prompt box to inform the current user and terminate the operation, thereby protecting the open file from misoperation, deletion and the like.
Drawings
The invention will be described in further detail with reference to the drawings and the detailed description.
FIG. 1 is a flow chart of an open file protection design of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention are clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. In the following description, numerous specific details are set forth in order to provide a thorough understanding of the present invention, but the present invention may be practiced in other ways other than those described herein, and persons skilled in the art will readily appreciate that the present invention is not limited to the specific embodiments disclosed below.
The embodiment of the invention discloses a method for protecting an opened file under a domestic Linux operating system, which comprises the following steps:
step S1, adding a new function protection_file () into a function of a file manager about file deletion or file placement in a recycle bin and a function of a file cutting function module, wherein the new function protection_file () is embedded in a file management area in a hook function mode, in the protection_file () function, firstly, calling a standard library function stat to acquire operated file information, and then judging whether an input file handle is a directory or not through an S_ISDIR () function, if yes, performing step S2, and if not, performing step S3;
step S2, opening a handle of the directory through an opendir () function, sequentially reading all contents under the directory through a readdir () function until NULL, and recursively calling a function protection_file () with the read file handle, and then carrying out step S4;
step S3, judging whether the file handle is a block device file through a function S_ISBLK () function, judging whether the file handle is a character device file through a function S_ISCHR (), and if the file handle is any one of the two types of files, not processing the file handle;
step S4, calling a function S_ISREG () in a protection_file () function to judge whether the operated file is a conventional file, if so, obtaining a sub-member statbuf.st_uid of a statbuf variable through a standard library function stat, obtaining a user id of the file through the statbuf.st_uid, obtaining a login user id of a current system through a getuid () function, and then judging whether the two are consistent, if so, performing step S5;
and S5, calling a standard library function fcntl () in the protect_file () function, acquiring the file write lock by setting a flag bit of F_WRLCK, if the file write lock exists, popping up a prompt box without permission through the standard library function provided by the GTK, canceling the current operation, and otherwise, continuing to execute the operation.
The invention is based on the current mainstream file manager under domestic operating system such as caja; nautilus; peoney, etc., where code implementing the file manipulation section joins the corresponding function module that protects the open file, protects the actions of deleting through the file manager, putting in recycle bin, cutting, etc. that require moving the existing file path, because the file is contained in a directory, it also needs to be taken into account when doing the above-described operations on its parent directory up to its topmost directory.
The Linux file system has a mechanism of file lock, namely when a file is opened (an open () method called by a system call is called), the file system creates a lock for the file through a standard library function lock (), associates with an open entry (struct file) of the file, and locks the file. Therefore, the file lock mechanism under Linux is utilized in the file protection function module added with the file to judge whether the file is in an open state, thereby realizing the function of protecting the opened file.
As shown in fig. 1, in order to open a file protection design flow chart, for example, in the winning kylin V5 desktop operating system, the corresponding file manager is caja, and a new function, protect_file (), which is a main function of file protection, is added to a function related to file deletion or file entry recycle bin and a function of a cut file function module in the code of caja, and is embedded into the file manager in a hook function manner.
The definition of the new function protect_file () is:
Filetype protect_file(gchar />path)
typedef struct
{
char filename;
gboolean if_own;
}Filetype;
in the new function protection_file (), a standard library function stat (file path, & statbuf) is called to acquire the operated file information, and then an S_ISDIR () function is utilized to judge whether the input file handle is a directory;
if the file handle is the directory, opening a handle of the directory through an opendir () function, sequentially reading all contents under the directory through a readdir () function until the contents are NULL, and then recursively calling a function protection_file ();
if not, judging whether the file is a block device file or not by using a function S_ISBLK (); the S_ISCHR () function judges whether the file is a character device file or not, and the two types of files do not need to be processed because the files are not regular files;
finally, judging whether the operated file is a conventional file or not by utilizing a protection_file () function call function S_ISREG (), if the operated file is a conventional file, calling a sub-member (statbuf.st_uid) of a statbuf variable acquired by a standard library function stat through the protection_file (), acquiring a user id of the file through the statbuf.st_uid, acquiring a login user id of a current system through a getuid () function, and comparing the two;
if the file is inconsistent, the file is not indicated to belong to a user currently operating the file, and because the write lock is acquired when the fnctl () function is executed later to acquire the read-write lock, the file is distinguished from the write lock acquired when the file is opened, and a prompt box without permission is popped up;
when the user id of the file is consistent with the user id of the current operation, a standard library function fcntl () is called in a protection_file () function, the file write lock is obtained by setting a flag bit of F_WRLCK, if the write lock exists, a prompt box that the file is opened is popped up, the current operation is canceled, and otherwise, the current operation is continuously executed.
Based on the technical scheme of the invention, when a user deletes, cuts and deletes a file or a catalog through system file management, and deletes the file or the catalog to a recycle bin, if the file or the catalog contains the file in an open editing state, the system pops up a warning prompt box to inform the current user and terminates the operation, thereby protecting the opened file from misoperation, deletion and other actions.
It will be apparent that the described embodiments are only some, but not all, embodiments of the invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
Claims (1)
1. The method for protecting the opened file under the domestic Linux operating system is characterized by comprising the following steps:
step S1, adding a new function protection_file () into a function of a file manager about file deletion or file placement in a recycle bin and a function of a file cutting function module, wherein the new function protection_file () is embedded in a file management area in a hook function mode, in the protection_file () function, firstly, calling a standard library function stat to acquire operated file information, and then judging whether an input file handle is a directory or not through an S_ISDIR () function, if yes, performing step S2, and if not, performing step S3;
step S2, opening a handle of the directory through an opendir () function, sequentially reading all contents under the directory through a readdir () function until NULL, and recursively calling a function protection_file () with the read file handle, and then carrying out step S4;
step S3, judging whether the file handle is a block device file through a function S_ISBLK () function, judging whether the file handle is a character device file through a function S_ISCHR (), and if the file handle is any one of the two types of files, not processing the file handle;
step S4, judging whether the operated file is a conventional file through a function S_ISREG () in a protection_file () function, if so, obtaining a sub-member statbuf.st_uid of a statbuf variable through a standard library function stat, obtaining a user id to which the file belongs through the statbuf.st_uid, obtaining a login user id of a current system through a getuid () function, then judging whether the two are consistent, and if so, performing step S5;
and S5, calling a standard library function fcntl () in the protect_file () function, acquiring the file write lock by setting a flag bit of F_WRLCK, if the file write lock exists, popping up a prompt box without permission through the standard library function provided by the GTK, canceling the current operation, and otherwise, continuing to execute the operation.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202311225793.2A CN116975002B (en) | 2023-09-22 | 2023-09-22 | Method for protecting open file under domestic Linux operating system |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202311225793.2A CN116975002B (en) | 2023-09-22 | 2023-09-22 | Method for protecting open file under domestic Linux operating system |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN116975002A CN116975002A (en) | 2023-10-31 |
| CN116975002B true CN116975002B (en) | 2023-12-26 |
Family
ID=88473330
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202311225793.2A Active CN116975002B (en) | 2023-09-22 | 2023-09-22 | Method for protecting open file under domestic Linux operating system |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN116975002B (en) |
Citations (10)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| KR20050081593A (en) * | 2004-02-16 | 2005-08-19 | 현 길 김 | Methodology of the computerized file security using the computer virus concept |
| JP2007316780A (en) * | 2006-05-24 | 2007-12-06 | Nec Corp | Computer system, computer and file operation limiting method to be used therefor, and its program |
| CN101719210A (en) * | 2009-12-25 | 2010-06-02 | 武汉大学 | File use control method based on linux platform digital copyright management |
| CN101901313A (en) * | 2010-06-10 | 2010-12-01 | 中科方德软件有限公司 | Linux file protection system and method |
| CN105893847A (en) * | 2016-04-22 | 2016-08-24 | 北京金山安全软件有限公司 | Method and device for protecting safety protection application program file and electronic equipment |
| KR20180004065A (en) * | 2017-12-27 | 2018-01-10 | 라인 가부시키가이샤 | Method and system for protecting file |
| CN109614165A (en) * | 2018-12-04 | 2019-04-12 | 山东财经大学 | A method and device for parallel operation of multiple versions of COM components |
| CN111680323A (en) * | 2020-05-26 | 2020-09-18 | 广州多益网络股份有限公司 | Code borrowing protection method and system |
| CN111797408A (en) * | 2020-09-09 | 2020-10-20 | 北京志翔科技股份有限公司 | Linux system-based trusted computing method and device |
| CN115329351A (en) * | 2022-07-22 | 2022-11-11 | 安徽工程大学 | File protection system and method for Windows system |
Family Cites Families (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CA2292041A1 (en) * | 1998-12-22 | 2000-06-22 | Scott Alan Thomson | Software program protection mechanism |
| US6941470B1 (en) * | 2000-04-07 | 2005-09-06 | Everdream Corporation | Protected execution environments within a computer system |
| US8959639B2 (en) * | 2007-06-18 | 2015-02-17 | Symantec Corporation | Method of detecting and blocking malicious activity |
| US10255443B2 (en) * | 2016-02-11 | 2019-04-09 | Line Corporation | Method, apparatus, system and non-transitory computer readable medium for code protection |
| US10990678B2 (en) * | 2017-07-26 | 2021-04-27 | Comodo Security Solutions, Inc. | Method to protect application running in a hostile environment |
-
2023
- 2023-09-22 CN CN202311225793.2A patent/CN116975002B/en active Active
Patent Citations (10)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| KR20050081593A (en) * | 2004-02-16 | 2005-08-19 | 현 길 김 | Methodology of the computerized file security using the computer virus concept |
| JP2007316780A (en) * | 2006-05-24 | 2007-12-06 | Nec Corp | Computer system, computer and file operation limiting method to be used therefor, and its program |
| CN101719210A (en) * | 2009-12-25 | 2010-06-02 | 武汉大学 | File use control method based on linux platform digital copyright management |
| CN101901313A (en) * | 2010-06-10 | 2010-12-01 | 中科方德软件有限公司 | Linux file protection system and method |
| CN105893847A (en) * | 2016-04-22 | 2016-08-24 | 北京金山安全软件有限公司 | Method and device for protecting safety protection application program file and electronic equipment |
| KR20180004065A (en) * | 2017-12-27 | 2018-01-10 | 라인 가부시키가이샤 | Method and system for protecting file |
| CN109614165A (en) * | 2018-12-04 | 2019-04-12 | 山东财经大学 | A method and device for parallel operation of multiple versions of COM components |
| CN111680323A (en) * | 2020-05-26 | 2020-09-18 | 广州多益网络股份有限公司 | Code borrowing protection method and system |
| CN111797408A (en) * | 2020-09-09 | 2020-10-20 | 北京志翔科技股份有限公司 | Linux system-based trusted computing method and device |
| CN115329351A (en) * | 2022-07-22 | 2022-11-11 | 安徽工程大学 | File protection system and method for Windows system |
Also Published As
| Publication number | Publication date |
|---|---|
| CN116975002A (en) | 2023-10-31 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US7778961B2 (en) | Delayed deletion of extended attributes | |
| US8069442B2 (en) | Computer system and method for secure installation and operation of software | |
| US7526621B2 (en) | Method for implementing retention policies to archive records | |
| US7155465B2 (en) | Method and apparatus for automatically archiving a file system | |
| US7640404B2 (en) | File system write filtering for selectively permitting or preventing data from being written to write-protected storage | |
| US8200721B2 (en) | System and method for providing write-once-read-many (WORM) storage | |
| US20110276540A1 (en) | Method, system, and program for archiving files | |
| US20080010326A1 (en) | Method and system for securely deleting files from a computer storage device | |
| US7926106B1 (en) | Utilizing early exclusive volume access and direct volume manipulation to remove protected files | |
| US7421560B2 (en) | Method and system of computing quota usage | |
| US6714951B2 (en) | Continuous journaling of objects within a hierarchical directory tree | |
| KR100898968B1 (en) | How to Automatically Delete Temporary Files Used by Applications | |
| CA2412001A1 (en) | System and method for manipulating multiple clip items of data | |
| US20060277183A1 (en) | System and method for neutralizing locked pestware files | |
| WO2009096936A2 (en) | Erasing and restoring factory settings in computer systems | |
| KR20100025116A (en) | Fully automatic deletion using the system to prevent the leakage of documents | |
| CN116975002B (en) | Method for protecting open file under domestic Linux operating system | |
| CN109033868A (en) | A kind of management method and device of movable storage device file | |
| KR101055287B1 (en) | How to manage temporary files used by applications | |
| US10037328B2 (en) | Non-privileged access to data independent of filesystem implementation | |
| US20060277182A1 (en) | System and method for analyzing locked files | |
| CN112506424A (en) | Kernel-based method for preventing hard disk partition from being deleted under window operating system | |
| Craiger | Recovering digital evidence from Linux systems | |
| Cisco | Agent Version Management | |
| US8732132B2 (en) | Life moment tagging and storage |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |