Print this page
5083 avoid undefined order of operations in assignments


2793 fsinit()
2794 {
2795         int i;
2796 
2797 
2798         /*
2799          * initialize the node
2800          */
2801         node.i_atime = mkfstime;
2802         node.i_mtime = mkfstime;
2803         node.i_ctime = mkfstime;
2804 #ifdef LOSTDIR
2805         /*
2806          * create the lost+found directory
2807          */
2808         (void) makedir(lost_found_dir, 2);
2809         for (i = DIRBLKSIZ; i < sblock.fs_bsize; i += DIRBLKSIZ) {
2810                 bcopy(&lost_found_dir[2], &buf[i], DIRSIZ(&lost_found_dir[2]));
2811         }
2812         node.i_number = LOSTFOUNDINO;
2813         node.i_smode = node.i_mode = IFDIR | 0700;
2814         node.i_nlink = 2;
2815         node.i_size = sblock.fs_bsize;
2816         node.i_db[0] = alloc((int)node.i_size, node.i_mode);
2817         node.i_blocks = btodb(fragroundup(&sblock, (int)node.i_size));
2818         IRANDOMIZE(&node.i_ic);
2819         wtfs(fsbtodb(&sblock, (uint64_t)node.i_db[0]), (int)node.i_size, buf);
2820         iput(&node);
2821 #endif
2822         /*
2823          * create the root directory
2824          */
2825         node.i_number = UFSROOTINO;
2826         node.i_mode = node.i_smode = IFDIR | UMASK;
2827         node.i_nlink = PREDEFDIR;
2828         node.i_size = makedir(root_dir, PREDEFDIR);
2829         node.i_db[0] = alloc(sblock.fs_fsize, node.i_mode);
2830         /* i_size < 2GB because we are initializing the file system */
2831         node.i_blocks = btodb(fragroundup(&sblock, (int)node.i_size));
2832         IRANDOMIZE(&node.i_ic);
2833         wtfs(fsbtodb(&sblock, (uint64_t)node.i_db[0]), sblock.fs_fsize, buf);
2834         iput(&node);
2835 }
2836 
2837 /*
2838  * construct a set of directory entries in "buf".
2839  * return size of directory.
2840  */
2841 static int
2842 makedir(struct direct *protodir, int entries)
2843 {
2844         char *cp;
2845         int i;
2846         ushort_t spcleft;




2793 fsinit()
2794 {
2795         int i;
2796 
2797 
2798         /*
2799          * initialize the node
2800          */
2801         node.i_atime = mkfstime;
2802         node.i_mtime = mkfstime;
2803         node.i_ctime = mkfstime;
2804 #ifdef LOSTDIR
2805         /*
2806          * create the lost+found directory
2807          */
2808         (void) makedir(lost_found_dir, 2);
2809         for (i = DIRBLKSIZ; i < sblock.fs_bsize; i += DIRBLKSIZ) {
2810                 bcopy(&lost_found_dir[2], &buf[i], DIRSIZ(&lost_found_dir[2]));
2811         }
2812         node.i_number = LOSTFOUNDINO;
2813         node.i_smode = IFDIR | 0700;
2814         node.i_nlink = 2;
2815         node.i_size = sblock.fs_bsize;
2816         node.i_db[0] = alloc((int)node.i_size, node.i_mode);
2817         node.i_blocks = btodb(fragroundup(&sblock, (int)node.i_size));
2818         IRANDOMIZE(&node.i_ic);
2819         wtfs(fsbtodb(&sblock, (uint64_t)node.i_db[0]), (int)node.i_size, buf);
2820         iput(&node);
2821 #endif
2822         /*
2823          * create the root directory
2824          */
2825         node.i_number = UFSROOTINO;
2826         node.i_mode = IFDIR | UMASK;
2827         node.i_nlink = PREDEFDIR;
2828         node.i_size = makedir(root_dir, PREDEFDIR);
2829         node.i_db[0] = alloc(sblock.fs_fsize, node.i_mode);
2830         /* i_size < 2GB because we are initializing the file system */
2831         node.i_blocks = btodb(fragroundup(&sblock, (int)node.i_size));
2832         IRANDOMIZE(&node.i_ic);
2833         wtfs(fsbtodb(&sblock, (uint64_t)node.i_db[0]), sblock.fs_fsize, buf);
2834         iput(&node);
2835 }
2836 
2837 /*
2838  * construct a set of directory entries in "buf".
2839  * return size of directory.
2840  */
2841 static int
2842 makedir(struct direct *protodir, int entries)
2843 {
2844         char *cp;
2845         int i;
2846         ushort_t spcleft;