Unix File Attributes

1 篇文章 0 订阅

The Unix File Attributes packet consists of the following:

File-Index Type Filename@File-Attributes@Link @Extended-Attributes@ where

@
represents a byte containing a binary zero.
FileIndex
is the sequential file index starting from one assigned by the File daemon.
Type
is one of the following:

#define FT_LNKSAVED   1    /* hard link to file already saved */
#define FT_REGE       2    /* Regular file but empty */
#define FT_REG        3    /* Regular file */
#define FT_LNK        4    /* Soft Link */
#define FT_DIR        5    /* Directory */
#define FT_SPEC       6    /* Special file -- chr, blk, fifo, sock */
#define FT_NOACCESS   7    /* Not able to access */
#define FT_NOFOLLOW   8    /* Could not follow link */
#define FT_NOSTAT     9    /* Could not stat file */
#define FT_NOCHG     10    /* Incremental option, file not changed */
#define FT_DIRNOCHG  11    /* Incremental option, directory not changed */
#define FT_ISARCH    12    /* Trying to save archive file */
#define FT_NORECURSE 13    /* No recursion into directory */
#define FT_NOFSCHG   14    /* Different file system, prohibited */
#define FT_NOOPEN    15    /* Could not open directory */
#define FT_RAW       16    /* Raw block device */
#define FT_FIFO      17    /* Raw fifo device */

Filename
is the fully qualified filename.
File-Attributes
consists of the 13 fields of the stat() buffer in ASCII base64 format separated by spaces. These fields and their meanings are shown below. This stat() packet is in Unix format, and MUST be provided (constructed) for ALL systems.
Link
when the FT code is FT_LNK or FT_LNKSAVED, the item in question is a Unix link, and this field contains the fully qualified link name. When the FT code is not FT_LNK or FT_LNKSAVED, this field is null.
Extended-Attributes
The exact format of this field is operating system dependent. It contains additional or extended attributes of a system dependent nature. Currently, this field is used only on WIN32 systems where it contains a ASCII base64 representation of the WIN32_FILE_ATTRIBUTE_DATA structure as defined by Windows. The fields in the base64 representation of this structure are like the File-Attributes separated by spaces.

The File-attributes consist of the following:

Field No.Stat NameUnixWin98/NTMacOS
1st_devDevice number of filesystemDrive numbervRefNum
2st_inoInode numberAlways 0fileID/dirID
3st_modeFile modeFile mode777 dirs/apps; 666 docs; 444 locked docs
4st_nlinkNumber of links to the fileNumber of link (only on NTFS)Always 1
5st_uidOwner IDAlways 0Always 0
6st_gidGroup IDAlways 0Always 0
7st_rdevDevice ID for special filesDrive No.Always 0
8st_sizeFile size in bytesFile size in bytesData fork file size in bytes
9st_blksizePreferred block sizeAlways 0Preferred block size
10st_blocksNumber of blocks allocatedAlways 0Number of blocks allocated
11st_atimeLast access time since epochLast access time since epochLast access time -66 years
12st_mtimeLast modify time since epochLast modify time since epochLast access time -66 years
13st_ctimeInode change time since epochFile create time since epochFile create time -66 years

java代码获取

    /**
     * 判断执行环境是否是linux
     * http://www.mkyong.com/java/how-to-detect-os-in-java-systemgetpropertyosname/
     * @return
     */
    public static boolean isLinux(){
        String OS = System.getProperty("os.name").toLowerCase();
        return (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0 );
    }
    /**
     * 判断当前的执行环境是否是windows系统
     * http://www.mkyong.com/java/how-to-detect-os-in-java-systemgetpropertyosname/
     * @return
     */
    public static boolean isWindows(){
        String OS = System.getProperty("os.name").toLowerCase();
        return (OS.indexOf("win") >= 0);
    }
    /**
     * 判断参数的第二个元素的文件类型,对windows os无效
     * @param args
     */
    public static void detectUnixHardLink(String[] args){
        if(isWindows()){
            System.out.println("该操作只支持对linux文件类型的判断");
            return;
        }
        String filePath=null;

        try{
            filePath=args[1];
        }catch(ArrayIndexOutOfBoundsException e){
            log.error("文件类型判断少文件地址");
        }
        Path p=new File(filePath).toPath();
        try {
            int type=(Integer)java.nio.file.Files.getAttribute(p, "unix:nlink");
            System.out.println("unix nlink:"+type);
        } catch (IOException | ClassCastException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

原文地址:
http://www.bacula.org/5.1.x-manuals/en/developers/developers/Unix_File_Attributes.html
其它参考:
http://www.cse.scu.edu/~tschwarz/COEN252_09/Lectures/UnixFileSystem.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值